From 5a85f2f166078a7ff52e62c0ada29dd7f9622949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2=20=D0=AE=D1=80=D0=B8?= =?UTF-8?q?=D0=B9?= Date: Tue, 28 Nov 2023 00:15:06 +0300 Subject: [PATCH] 2.0.0 - Material Design 3 Fix doc string. --- kivymd/uix/label/label.py | 49 ++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 27 deletions(-) diff --git a/kivymd/uix/label/label.py b/kivymd/uix/label/label.py index 052d3e33e..01fbfbf83 100755 --- a/kivymd/uix/label/label.py +++ b/kivymd/uix/label/label.py @@ -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 = [ @@ -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( @@ -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 ),