From 62984b85019b64a48c57c1f5714bd2c7c7942b81 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Mon, 22 Nov 2021 08:46:40 +0800 Subject: [PATCH] bugfix --- kivyblocks/clickable.py | 108 ++++++++++++++++++++++++++++++++++++++ kivyblocks/toggleitems.py | 3 -- 2 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 kivyblocks/clickable.py diff --git a/kivyblocks/clickable.py b/kivyblocks/clickable.py new file mode 100644 index 0000000..bfd606f --- /dev/null +++ b/kivyblocks/clickable.py @@ -0,0 +1,108 @@ +from functools import partial +from kivy.logger import Logger +from kivy.uix.behaviors import TouchRippleButtonBehavior +from kivy.graphics import Color, Rectangle +from kivy.uix.boxlayout import BoxLayout +from kivy.factory import Factory +from kivy.properties import ObjectProperty, StringProperty, BooleanProperty + +from kivyblocks.ready import WidgetReady +from kivyblocks.bgcolorbehavior import BGColorBehavior +from kivyblocks.utils import CSize +from kivyblocks.baseWidget import Box +from kivyblocks.widget_css import WidgetCSS + +class ClickableBox(TouchRippleButtonBehavior, Box): + def __init__(self, + border_width=1, + **kw): + super(ClickableBox, self).__init__( + padding=[border_width, + border_width, + border_width, + border_width], + radius=radius, + **kw) + self.border_width = border_width + + def on_press(self,o=None): + pass + +class ClickableText(ClickableBox): + text = StringProperty(' ') + def __init__(self, **kw): + super(ClickableText, self).__init__(**kw) + self.txt_w = Text(text=self.text, i18n=True) + self.add_widget(self.txt_w) + + def on_text(self, o, txt): + self.txt_w.text = txt + +class ToggleText(ClickableText): + """ + construct commad + ToggleText(**{ + "text":"test", + "on_css":"selected", + "off_css":"normal" + }) + + select_state = BooleanProperty(False) + on_css = StringProperty('default') + off_css = StringProperty('default') + def __init__(self, **kw): + super(ToggleText, self).__init__(**kw) + + def on_press(self, o=None): + if self.select_state = if self.select_state?False else True + + def on_select_state(self, o, f): + if f: + self.clscss = self.on_css + else: + self.clscss = self.off_css + +class ClickableImage(ClickableBox): + source=StringProperty('none') + +class ToggleImage( +class PressableBox(TouchRippleButtonBehavior, Box): + normal_css = StringProperty("default") + actived_css = StringProperty("default") + box_actived = BooleanProperty(False) + def __init__(self, + border_width=1, + user_data=None, + radius=[], + **kw): + super(PressableBox, self).__init__( + padding=[border_width, + border_width, + border_width, + border_width], + radius=radius, + **kw) + self.border_width = border_width + self.user_data = user_data + self.actived = False + self.csscls = self.normal_css + + def active(self, flag): + self.box_actived = flag + + def on_box_actived(self, o, v): + if self.box_actived: + self.csscls = self.actived_css + else: + self.csscls = self.normal_css + + def on_press(self,o=None): + self.box_actived = True + + + def setValue(self,d): + self.user_data = d + + def getValue(self): + return self.user_data + diff --git a/kivyblocks/toggleitems.py b/kivyblocks/toggleitems.py index 9069919..2e31e86 100644 --- a/kivyblocks/toggleitems.py +++ b/kivyblocks/toggleitems.py @@ -18,7 +18,6 @@ class PressableBox(TouchRippleButtonBehavior, Box): box_actived = BooleanProperty(False) def __init__(self, border_width=1, - color_level=-1, user_data=None, radius=[], **kw): @@ -56,7 +55,6 @@ class PressableBox(TouchRippleButtonBehavior, Box): """ ToggleItems format: { - color_level: radius: unit_size: items_desc: @@ -66,7 +64,6 @@ ToggleItems format: """ class ToggleItems(BoxLayout, WidgetCSS): def __init__(self, - color_level=1, radius=[], orientation='horizontal', unit_size=3,