This commit is contained in:
yumoqing 2021-12-17 00:02:02 +08:00
parent 23fb775723
commit 979ac006b2
2 changed files with 85 additions and 36 deletions

View File

@ -11,9 +11,14 @@ from kivy.properties import NumericProperty, DictProperty, \
from kivyblocks.ready import WidgetReady from kivyblocks.ready import WidgetReady
from kivyblocks.bgcolorbehavior import BGColorBehavior from kivyblocks.bgcolorbehavior import BGColorBehavior
from kivyblocks.utils import CSize from kivyblocks.utils import CSize
from kivyblocks.baseWidget import Box from kivyblocks.baseWidget import Box, Text
from kivyblocks.widget_css import WidgetCSS from kivyblocks.widget_css import WidgetCSS
class TinyText(Text):
def on_texture_size(self, o, ts):
self.size = self.texture_size
print('TinyText:texture_size=', self.texture_size)
class ClickableBox(TouchRippleButtonBehavior, Box): class ClickableBox(TouchRippleButtonBehavior, Box):
def __init__(self, def __init__(self,
border_width=1, border_width=1,
@ -23,11 +28,10 @@ class ClickableBox(TouchRippleButtonBehavior, Box):
border_width, border_width,
border_width, border_width,
border_width], border_width],
radius=radius,
**kw) **kw)
self.border_width = border_width self.border_width = border_width
self.bind(minimum_height=self.setter('height')) # self.bind(minimum_height=self.setter('height'))
self.bind(minimum_width=self.setter('width')) # self.bind(minimum_width=self.setter('width'))
def on_press(self,o=None): def on_press(self,o=None):
pass pass
@ -35,32 +39,53 @@ class ClickableBox(TouchRippleButtonBehavior, Box):
class ClickableText(ClickableBox): class ClickableText(ClickableBox):
text = StringProperty(' ') text = StringProperty(' ')
def __init__(self, **kw): def __init__(self, **kw):
print('ClickableText begin inited')
self.txt_w = None
super(ClickableText, self).__init__(**kw) super(ClickableText, self).__init__(**kw)
self.txt_w = Text(text=self.text, i18n=True) self.txt_w = TinyText(text=self.text, i18n=True)
# self.txt_w.size_hint = (None, None) self.txt_w.bind(texture_size=self.reset_size)
# self.txt_w.bind(minimum_height=self.self.txt_w.setter('height'))
# self.txt_w.bind(minimum_width=self.self.txt_w.setter('width'))
self.add_widget(self.txt_w) self.add_widget(self.txt_w)
self.txt_w.size_hint = (None, None)
self.txt_w.size = self.txt_w.texture_size
#self.txt_w.bind(minimum_height=self.txt_w.setter('height'))
#self.txt_w.bind(minimum_width=self.txt_w.setter('width'))
print('ClickableText inited')
def reset_size(self, o, s):
self.size_hint = (None,None)
self.size = self.txt_w.texture_size
def on_text(self, o, txt): def on_text(self, o, txt):
self.txt_w.text = txt print('on_text fired')
if self.txt_w:
self.txt_w.text = self.text
class ClickableIconText(ClickableText): class ClickableIconText(ClickableText):
source = StringProperty(None) source = StringProperty(None)
img_kw = DictProperty({}) img_kw = DictProperty({})
def __init__(self, **kw): def __init__(self, **kw):
super(ClickableIconText, self).__init__(**kw)
self.img_w = None self.img_w = None
if source: super(ClickableIconText, self).__init__(**kw)
self.img_w = AsyncImage(source=self.source, **self.img_kw) print('ClickableIconText inited')
self.add_widget(self.img_w, index=0)
def reset_size(self, o, s):
self.size_hint = (None,None)
if self.orientation == 'horizontal':
self.height = max(self.txt_w.texture_size[1], self.img_w.height)
self.width = self.txt_w.texture_size[0] + self.img_w.width
else:
self.height = self.txt_w.texture_size[1] + self.img_w.height
self.width = max(self.txt_w.texture_size[0], self.img_w.width)
def on_source(self, o, source): def on_source(self, o, source):
if self.img_w: if self.img_w:
self.img_w.source = source self.img_w.source = source
return return
self.img_w = AsyncImage(source=self.source, **self.img_kw) self.img_w = AsyncImage(source=self.source, **self.img_kw)
self.add_widget(self.img_w, index=0) self.add_widget(self.img_w, index=-1)
class ToggleText(ClickableText): class ToggleText(ClickableText):
""" """
@ -91,7 +116,8 @@ class ToggleText(ClickableText):
return self.select_state return self.select_state
def on_select_state(self, o, f): def on_select_state(self, o, f):
self.clscss = self.css_on if f else self.css_off self.csscls = self.css_on if f else self.css_off
print(f'using {self.csscls}')
class ToggleIconText(ToggleText): class ToggleIconText(ToggleText):
""" """
@ -109,28 +135,38 @@ class ToggleIconText(ToggleText):
source = StringProperty(None) source = StringProperty(None)
img_kw = DictProperty({}) img_kw = DictProperty({})
def __init__(self, **kw): def __init__(self, **kw):
super(ToggleIconText, self).__init__(**kw)
self.img_w = None self.img_w = None
self.source = source_off super(ToggleIconText, self).__init__(**kw)
self.source = self.source_off
self.img_w = AsyncImage(source=self.source, **self.img_kw)
self.add_widget(self.img_w, index=-1)
def reset_size(self, o, s):
self.size_hint = (None,None)
if self.orientation == 'horizontal':
self.height = max(self.txt_w.texture_size[1], self.img_w.height)
self.width = self.txt_w.texture_size[0] + self.img_w.width
else:
self.height = self.txt_w.texture_size[1] + self.img_w.height
self.width = max(self.txt_w.texture_size[0], self.img_w.width)
print(f'ToggleIconText:w,h={self.width},{self.height}')
def on_select_state(self, o, f): def on_select_state(self, o, f):
super(ToggleIconText, self).on_select_state(o,f) super(ToggleIconText, self).on_select_state(o,f)
self.source = source_on if f else source_off self.source = self.source_on if f else self.source_off
def on_source(self, o, source): def on_source(self, o, source):
if not self.img_w: if self.img_w:
self.img_w = AsyncImage(self.source, **self.img_kw) self.img_w.source = self.source
self.add_widget(sef.img_w, index=0)
class ClickableImage(ClickableBox): class ClickableImage(ClickableBox):
source=StringProperty(None) source=StringProperty(None)
img_kw = DictProperty(None) img_kw = DictProperty(None)
def __init__(self, **kw): def __init__(self, **kw):
super(ClickableImage, self).__init__(**kw)
self.img_w = None self.img_w = None
if source: super(ClickableImage, self).__init__(**kw)
self.img_w = AsyncImage(source=self.source, **self.img_kw) self.img_w = AsyncImage(source=self.source, **self.img_kw)
self.add_widget(self.img_w) self.add_widget(self.img_w)
def on_source(self, o, source): def on_source(self, o, source):
if self.img_w: if self.img_w:
@ -145,7 +181,7 @@ class ToggleImage(ClickableImage):
select_state = BooleanProperty(False) select_state = BooleanProperty(False)
def __init__(self, **kw): def __init__(self, **kw):
super(ToggleImage, self).__init__(**kw) super(ToggleImage, self).__init__(**kw)
self.source = source_on self.source = self.source_on
def toggle(self): def toggle(self):
self.select_state = False if self.select_state else True self.select_state = False if self.select_state else True
@ -166,9 +202,11 @@ class ToggleImage(ClickableImage):
self.source = self.source_off self.source = self.source_off
r = Factory.register r = Factory.register
r('TinyText', TinyText)
r('ClickableBox', ClickableBox) r('ClickableBox', ClickableBox)
r('ClickableText',ClickableText) r('ClickableText',ClickableText)
r('ClickableIconText',ClickableIconText) r('ClickableIconText',ClickableIconText)
r('ToggleText',ToggleText) r('ToggleText',ToggleText)
r('ToggleIconText',ToggleIconText) r('ToggleIconText',ToggleIconText)
r('ClickableImage',ClickableImage) r('ClickableImage',ClickableImage)
r('ToggleImage',ToggleImage)

View File

@ -9,7 +9,7 @@ from kivy.uix.widget import Widget
from kivy.app import App from kivy.app import App
from kivy.clock import Clock from kivy.clock import Clock
from kivy.factory import Factory from kivy.factory import Factory
from kivy.properties import StringProperty from kivy.properties import StringProperty, ListProperty, NumericProperty
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
from appPublic.registerfunction import RegisterFunction from appPublic.registerfunction import RegisterFunction
@ -19,6 +19,7 @@ from .utils import *
from .ready import WidgetReady from .ready import WidgetReady
from .color_definitions import getColors from .color_definitions import getColors
from .baseWidget import Text, Box from .baseWidget import Text, Box
from .scrollpanel import ScrollPanel
from .toggleitems import ToggleItems from .toggleitems import ToggleItems
""" """
@ -130,7 +131,7 @@ Toolpage options
""" """
class ScrollToolbar(ToolbarPanel): class ScrollToolbar(ScrollPanel):
""" """
tool has the follow attributes tool has the follow attributes
{ {
@ -145,35 +146,37 @@ class ScrollToolbar(ToolbarPanel):
"img_width_c":image width in charecter size "img_width_c":image width in charecter size
"css_on", "css_on",
"css_off", "css_off",
"orient":"V" or "H"
"tools": "tools":
"tool_orient"
} }
""" """
css_on = StringProperty('default') css_on = StringProperty('default')
css_off = StringProperty('default') css_off = StringProperty('default')
tools = ListProperty([]) tools = ListProperty([])
tool_orient = StringProperty('horizontal')
img_height_c = NumericProperty(2) img_height_c = NumericProperty(2)
img_width_c = NumericProperty(2) img_width_c = NumericProperty(2)
def __init__(self, **kw): def __init__(self, **kw):
print('#############init begin##########')
super(ScrollToolbar, self).__init__(**kw) super(ScrollToolbar, self).__init__(**kw)
print('#############super init end##########')
self.register_event_type('on_press') self.register_event_type('on_press')
self.w_dic = {} self.w_dic = {}
def on_tools(self, o, tools):
for t in self.tools: for t in self.tools:
label = t.get('label') label = t.get('label')
source_on = t.get('source_on', t.get('img_src',None)) source_on = t.get('source_on', t.get('img_src',None))
source_off = t.get('source_off', t.get('img_src', None)) source_off = t.get('source_off', t.get('img_src', None))
ToggleIconText = Factory.ToggleIconText ToggleIconText = Factory.ToggleIconText
ToggleText = Factory.ToggleText ToggleText = Factory.ToggleText
ToggleIcon = Factory.ToggleIcon ToggleImage = Factory.ToggleImage
if label and source_on: if label and source_on:
w = ToggleIconText(css_on=self.css_on, w = ToggleIconText(css_on=self.css_on,
css_off=self.css_off, css_off=self.css_off,
text=label, text=label,
source_on=source_on, source_on=source_on,
source_off=source_off, source_off=source_off,
orientation=self.tool_orient,
img_kw={ img_kw={
"size_hint":(None, None), "size_hint":(None, None),
"height":CSize(self.img_height_c), "height":CSize(self.img_height_c),
@ -183,14 +186,16 @@ class ScrollToolbar(ToolbarPanel):
elif label: elif label:
w = ToggleText(css_on=self.css_on, w = ToggleText(css_on=self.css_on,
css_off=self.css_off, css_off=self.css_off,
orientation=self.tool_orient,
text=label) text=label)
elif source_on: elif source_on:
w = ToggleIcon( source_on=source_on, w = ToggleImage( source_on=source_on,
source_off=source_off, source_off=source_off,
orientation=self.tool_orient,
img_kw={ img_kw={
"size_hint":(None, None), "size_hint":(None, None),
"height":CSize(self.img_height_c), "height":CSize(self.img_height_c),
"width":"CSize(self.img_width_c) "width":CSize(self.img_width_c)
} }
) )
@ -260,6 +265,12 @@ class ToolPage(BoxLayout):
self.toolbar.height = self.height self.toolbar.height = self.height
self.content.height = self.height self.content.height = self.height
self.content.width = self.width - self.toolbar.width self.content.width = self.width - self.toolbar.width
print(f'tb-width={self.toolbar.width}')
print(f'tb-height={self.toolbar.height}')
print(f'c-height={self.content.height}')
print(f'c-width={self.content.width}')
print(f'height={self.height}')
print(f'width={self.width}')
def init(self): def init(self):
self.initFlag = True self.initFlag = True
@ -267,8 +278,8 @@ class ToolPage(BoxLayout):
self.content = BoxLayout() self.content = BoxLayout()
self.content.widget_id = 'content' self.content.widget_id = 'content'
opts = {} opts = {}
opts['img_height_c"] = self.img_size, opts['img_height_c'] = self.img_size
opts['img_width_c"] = self.img_size, opts['img_width_c'] = self.img_size
opts['css_on'] = self.actived_css opts['css_on'] = self.actived_css
opts['css_off'] = self.normal_css opts['css_off'] = self.normal_css
opts['orient'] = 'H' opts['orient'] = 'H'