Skip to content

Commit

Permalink
2.0.0 - Material Design 3
Browse files Browse the repository at this point in the history
Fix doc string.
  • Loading branch information
HeaTTheatR committed Nov 27, 2023
1 parent 3a3fbdd commit 5a85f2f
Showing 1 changed file with 22 additions and 27 deletions.
49 changes: 22 additions & 27 deletions kivymd/uix/label/label.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,32 +331,31 @@ def on_copy(self, instance_label: MDLabel):
from kivy.lang.builder import Builder
from kivy.metrics import dp
from kivymd.uix.snackbar import MDSnackbar, MDSnackbarText
from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.menu import MDDropdownMenu
from kivymd.toast import toast
KV = '''
MDBoxLayout:
orientation: "vertical"
spacing: "12dp"
padding: "24dp"
md_bg_color: self.theme_cls.backgroundColor
MDScrollView:
MDBoxLayout:
id: box
orientation: "vertical"
padding: "24dp"
spacing: "12dp"
adaptive_height: True
MDBoxLayout:
id: box
orientation: "vertical"
padding: "24dp"
spacing: "12dp"
adaptive_height: True
MDTextField:
max_height: "200dp"
mode: "fill"
mode: "filled"
multiline: True
MDWidget:
Widget:
'''
data = [
Expand All @@ -367,34 +366,37 @@ def on_copy(self, instance_label: MDLabel):
"Nisl rhoncus mattis rhoncus urna neque. Orci nulla pellentesque "
"dignissim enim. Ac auctor augue mauris augue neque gravida in fermentum. "
"Lacus suspendisse faucibus interdum posuere."
]
def toast(text):
MDSnackbar(
MDSnackbarText(
text=text,
),
y=dp(24),
pos_hint={"center_x": 0.5},
size_hint_x=0.3,
).open()
class CopyLabel(MDLabel):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.allow_selection = True
self.adaptive_height = True
self.theme_text_color = "Custom"
self.text_color = self.theme_cls.text_color
class Example(MDApp):
context_menu = None
def build(self):
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Orange"
return Builder.load_string(KV)
def on_start(self):
for text in data:
copy_label = CopyLabel(text=text)
copy_label.bind(
on_selection=self.open_context_menu,
on_cancel_selection=self.restore_text_color,
)
copy_label.bind(on_selection=self.open_context_menu)
self.root.ids.box.add_widget(copy_label)
def click_item_context_menu(
Expand All @@ -410,24 +412,17 @@ def click_item_context_menu(
if self.context_menu:
self.context_menu.dismiss()
def restore_text_color(self, instance_label: CopyLabel) -> None:
instance_label.text_color = self.theme_cls.text_color
def open_context_menu(self, instance_label: CopyLabel) -> None:
instance_label.text_color = "black"
menu_items = [
{
"text": "Copy text",
"viewclass": "OneLineListItem",
"height": dp(48),
"on_release": lambda: self.click_item_context_menu(
"copy", instance_label
),
},
{
"text": "Cut text",
"viewclass": "OneLineListItem",
"height": dp(48),
"on_release": lambda: self.click_item_context_menu(
"cut", instance_label
),
Expand Down

0 comments on commit 5a85f2f

Please sign in to comment.