From c7d993e5add576d94eb4a987ce51d1b1dd6f67db Mon Sep 17 00:00:00 2001 From: yumoqing Date: Wed, 2 Dec 2020 12:38:53 +0800 Subject: [PATCH] bugfix --- kivyblocks/bgcolorbehavior.py | 13 ++++++++++--- kivyblocks/dg.py | 14 ++++++++++---- kivyblocks/form.py | 4 +++- kivyblocks/newvideo.py | 6 ++++-- kivyblocks/tab.py | 11 ++++++----- kivyblocks/toggleitems.py | 5 ++++- kivyblocks/toolbar.py | 19 ++++++++----------- kivyblocks/tree.py | 17 +++++++++++++---- 8 files changed, 58 insertions(+), 31 deletions(-) diff --git a/kivyblocks/bgcolorbehavior.py b/kivyblocks/bgcolorbehavior.py index 9669f18..fa2bbdb 100644 --- a/kivyblocks/bgcolorbehavior.py +++ b/kivyblocks/bgcolorbehavior.py @@ -1,14 +1,16 @@ from kivy.logger import Logger -from kivy.graphics import Color, Rectangle +from kivy.graphics import Color, Rectangle, RoundedRectangle from kivy.properties import ListProperty from .color_definitions import getColors _logcnt = 0 class BGColorBehavior(object): - def __init__(self, color_level=-1,**kwargs): + def __init__(self, color_level=-1,radius=[],**kwargs): self.color_level = color_level + self.radius = radius self.bgcolor = [] self.fgcolor = [] + self.useOwnColor = False if color_level != -1: fg,bg= getColors(color_level) self.fgcolor = fg @@ -59,7 +61,12 @@ class BGColorBehavior(object): if self.canvas: with self.canvas.before: Color(*self.bgcolor) - self.rect = Rectangle(pos=self.pos, + if self.radius != []: + self.rect = RoundedRectangel(pos=self.pos, + size=self.size, + radius=self.radius) + else: + self.rect = Rectangle(pos=self.pos, size=self.size) else: print('on_bgcolor():self.canvas is None') diff --git a/kivyblocks/dg.py b/kivyblocks/dg.py index 1887216..5ac2282 100644 --- a/kivyblocks/dg.py +++ b/kivyblocks/dg.py @@ -22,6 +22,7 @@ from .paging import Paging, RelatedLoader from .ready import WidgetReady from .toolbar import Toolbar from .i18n import I18nText +from .bgcolorbehavior import BGColorBehavior class BLabel(ButtonBehavior, Text): def __init__(self, **kw): @@ -118,11 +119,12 @@ class Row(GridLayout): self.part.datagrid.select_rowid = self.row_id self.part.datagrid.dispatch('on_selected',self) -class Header(WidgetReady, ScrollWidget): - def __init__(self,part,**kw): +class Header(WidgetReady, BGColorBehavior, ScrollWidget): + def __init__(self,part,color_level=-1,**kw): self.part = part ScrollWidget.__init__(self,**kw) WidgetReady.__init__(self) + BGColorBehavior.__init__(self,color_level=color_level) self.init(1) self.bind(on_scroll_stop=self.part.datagrid.on_scrollstop) @@ -220,14 +222,18 @@ class DataGridPart(WidgetReady, BoxLayout): def addRow(self,id, data): return self.body.addRow(id, data) -class DataGrid(WidgetReady, BoxLayout): +class DataGrid(WidgetReady, BGColorBehavior, BoxLayout): row_selected = BooleanProperty(False) - def __init__(self,**options): + def __init__(self,color_level=-1,radius=[],**options): kw = DictObject() kw = setSizeOptions(options,kw) kw.orientation = 'vertical' + self.color_level = color_level + self.radius = radius WidgetReady.__init__(self) BoxLayout.__init__(self,**kw) + BGColorBehavior.__init__(self,color_level=color_level, + radius=radius) self.parenturl = options.get('parenturl',None) self.options = options self.noheader = options.get('noheader',False) diff --git a/kivyblocks/form.py b/kivyblocks/form.py index c0dc558..7693047 100644 --- a/kivyblocks/form.py +++ b/kivyblocks/form.py @@ -259,7 +259,9 @@ class Form(BGColorBehavior, BoxLayout): self.options = options BoxLayout.__init__(self, orientation='vertical') self.color_level = self.options.get('color_level', 0) - BGColorBehavior.__init__(self,color_level=self.color_level) + BGColorBehavior.__init__(self, + color_level=self.options.get('color_level',-1), + radius=self.options.get('radius',[])) self.readiedInput = 0 self.cols = self.options_cols = self.options.get('cols',1) if isHandHold() and Window.width < Window.height: diff --git a/kivyblocks/newvideo.py b/kivyblocks/newvideo.py index 498d3dd..7b60648 100644 --- a/kivyblocks/newvideo.py +++ b/kivyblocks/newvideo.py @@ -15,9 +15,11 @@ logger_func = {'quiet': Logger.critical, 'panic': Logger.critical, class NewVideo(BGColorBehavior, Video): - def __init__(self,**kw): + def __init__(self,color_level=-1,radius=[],**kw): Video.__init__(self, **kw) - BGColorBehavior.__init__(self) + BGColorBehavior.__init__(self, + color_level=color_level, + radius=radius) Window.allow_screensaver = False set_log_callback(self.ffplayerLog) diff --git a/kivyblocks/tab.py b/kivyblocks/tab.py index 9d3acc5..478bc0a 100644 --- a/kivyblocks/tab.py +++ b/kivyblocks/tab.py @@ -26,12 +26,13 @@ from kivy.factory import Factory from .bgcolorbehavior import BGColorBehavior class TabsPanel(BGColorBehavior, TabbedPanel): - def __init__(self,**options): + def __init__(self,color_level=-1, + radius=[], + **options): self.tabs_list = options.get('tabs') - self.color_level = options.get('color_level',0) - opts = {k:v for k,v in options.items() if k not in ['tabs','color_level']} - TabbedPanel.__init__(self,**opts) - BGColorBehavior.__init__(self) + TabbedPanel.__init__(self,**options) + BGColorBehavior.__init__(self,color_level=color_level, + radius=radius) Clock.schedule_once(self.add_tabs,0) def add_tab(self,text,desc): diff --git a/kivyblocks/toggleitems.py b/kivyblocks/toggleitems.py index 8a203c8..def41b2 100644 --- a/kivyblocks/toggleitems.py +++ b/kivyblocks/toggleitems.py @@ -60,11 +60,14 @@ class PressableBox(TouchRippleButtonBehavior, BoxLayout): class ToggleItems(BGColorBehavior, BoxLayout): def __init__(self, color_level=1, + radius=[], items_desc=[], border_width=1, **kw): BoxLayout.__init__(self, **kw) - BGColorBehavior.__init__(self,color_level=color_level) + BGColorBehavior.__init__(self, + color_level=color_level, + radius=radius) self.item_widgets = [] for desc in items_desc: c = PressableBox(border_width=border_width, diff --git a/kivyblocks/toolbar.py b/kivyblocks/toolbar.py index 07b437d..101a87d 100644 --- a/kivyblocks/toolbar.py +++ b/kivyblocks/toolbar.py @@ -41,7 +41,8 @@ class Tool(ButtonBehavior, BGColorBehavior, BoxLayout): ButtonBehavior.__init__(self) BoxLayout.__init__(self, size_hint_y=None) - BGColorBehavior.__init__(self,color_level=ancestor.color_level) + BGColorBehavior.__init__(self,color_level=ancestor.color_level, + radius=ancestor.radius) self.bl = BoxLayout(orientation='vertical', size_hint_y=None) self.add_widget(self.bl) @@ -134,12 +135,6 @@ class Toolbar(BGColorBehavior, GridLayout): tool.bind(on_press=self.tool_press) self.height = tool.height * 1.1 - def on_size(self,obj,size): - return - with self.canvas.before: - Color(0.3,0.3,0.3,1) - Rectangle(pos=self.pos,size=self.size) - def tool_press(self,o,v=None): for n,w in self.tool_widgets.items(): active = False @@ -166,16 +161,18 @@ Toolpage options """ class ToolPage(BGColorBehavior, BoxLayout): - def __init__(self,**opts): + def __init__(self,color_level=-1,radius=[],**opts): self.opts = DictObject(**opts) - self.parenturl = opts.get('parenturl',None) if self.opts.tool_at in [ 'top','bottom']: orient = 'vertical' else: orient = 'horizontal' - color_level=self.opts.color_level or 0 + self.color_level=self.opts.color_level or 0 + self.radius = self.opts.radius BoxLayout.__init__(self,orientation=orient) - BGColorBehavior.__init__(self,color_level=color_level) + BGColorBehavior.__init__(self, + color_level=color_level, + radius=radius) self.content = None self.toolbar = None self.init() diff --git a/kivyblocks/tree.py b/kivyblocks/tree.py index a19b9cd..29589fa 100644 --- a/kivyblocks/tree.py +++ b/kivyblocks/tree.py @@ -69,8 +69,10 @@ class NodeTrigger(ButtonBehavior, EmptyBox): Triangle(points=points) # print('pos=',self.pos,'size=',self.size) -class TreeNode(BoxLayout): +class TreeNode(BGColorBehavior,BoxLayout): def __init__(self,data,tree=None, + color_level=-1, + radius=[], parentNode=None, ): """ @@ -79,7 +81,11 @@ class TreeNode(BoxLayout): if children miss, it is a leaf node,if children is a empty array, is mean need load at it is first expanded. } """ + self.color_level = color_level if color_level != -1 else tree.color_level + 1 + self.radius = radius if radius!=[] else tree.audius BoxLayout.__init__(self,orientation='vertical',size_hint=(None,None)) + BGColorBehavior.__init__(self,color=self.color_level, + radius=self.radius) self.treeObj = tree self.parentNode = parentNode self.data = data @@ -282,10 +288,13 @@ tree options } """ class Tree(BGColorBehavior, ScrollWidget): - def __init__(self,**options): - self.color_level = options.get('color_level',0) + def __init__(self,color_level=-1,radius=[],**options): + self.color_level = color_level + self.radius = radius ScrollWidget.__init__(self) - BGColorBehavior.__init__(self,color_level=self.color_level) + BGColorBehavior.__init__(self, + color_level=self.color_level, + radius = self.radius) self.options = DictObject(**options) self.nodes = [] self.initflag = False