From 1ee4a4adaa06c7ef70d3aebb58fb02de9684befb Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 8 Mar 2020 22:49:46 +0800 Subject: [PATCH] bugfix --- kivyblocks/blocksapp.py | 2 +- kivyblocks/stylebehavior.py | 2 +- kivyblocks/tree.py | 34 +++++++++++++++++++++------------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/kivyblocks/blocksapp.py b/kivyblocks/blocksapp.py index ab181bc..a6a9269 100644 --- a/kivyblocks/blocksapp.py +++ b/kivyblocks/blocksapp.py @@ -69,7 +69,7 @@ class BlocksApp(App): def build(self): config = getConfig() self.config = config - self.theme_cls = ThemeManager() + # self.theme_cls = ThemeManager() self.serverinfo = ServerInfo() self.title = 'Test Title' self.blocks = Blocks() diff --git a/kivyblocks/stylebehavior.py b/kivyblocks/stylebehavior.py index b8c3798..e4c7aea 100644 --- a/kivyblocks/stylebehavior.py +++ b/kivyblocks/stylebehavior.py @@ -25,7 +25,7 @@ class StyleBehavior(object): c = self.bg_color if self.selected_flag: c = self.s_bg_color - logging.info('selected=%s,color=%s',str(self.selected_flag),str(c)) + # logging.info('selected=%s,color=%s',str(self.selected_flag),str(c)) with self.canvas.before: Color(*c) Rectangle(pos=self.pos,size=self.size) diff --git a/kivyblocks/tree.py b/kivyblocks/tree.py index 9b8fc54..1e4dd13 100644 --- a/kivyblocks/tree.py +++ b/kivyblocks/tree.py @@ -73,10 +73,10 @@ 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. } """ - super().__init__(orientation='vertical',size_hint=(None,None)) + BoxLayout.__init__(self,orientation='vertical',size_hint=(None,None)) self.treeObj = tree + self.parentNode = parentNode self.data = data - self.parentNonde = parentNode self.content = None self.children_open = False self.subNodes = [] @@ -103,8 +103,13 @@ class TreeNode(BoxLayout): self.height = self.node_box.height + self.node_box1.height else: self.height = self.node_box.height - self.width = self.trigger.width + \ - max(self.node_box.width,self.node_box1.width) + self.width = self.node_box.width + self._trigger_layout() + if self.parentNode: + self.parentNode._trigger_layout() + self.parentNode._trigger_layout() + else: + self.treeObj._inner._trigger_layout() def buildChildrenContainer(self): self.node_box1.add_widget(EmptyBox()) @@ -125,9 +130,9 @@ class TreeNode(BoxLayout): def addContent(self): self.buildContent() self.node_box.add_widget(self.content) - self.node_box.height = self.content.height + CSize(1) + self.node_box.height = self.content.height self.node_box.width = self.trigger.width + \ - self.content.width + CSize(1) + self.content.width logging.info('Tree : content=(%d,%d),box=(%d,%d)', \ self.content.width,self.content.height, self.node_box.width,self.node_box.height) @@ -178,7 +183,7 @@ class TreeNode(BoxLayout): self.node_box1.width = self.trigger.width + self.children_box.width def toggleChildren(self,o): - self.treeObj.unselected() + self.treeObj.unselect_row() self.children_open = True if not self.children_open else False if self.children_open: self.buildChildren() @@ -186,6 +191,10 @@ class TreeNode(BoxLayout): else: self.remove_widget(self.node_box1) self.setSize() + # when a widget remove from its parent, the get_parent_window() + # will return a None + # w1 = self.children_box.get_parent_window() + # logging.info('Tree :get_parent_window() return=%s',str(type(w1))) """ tree options @@ -201,11 +210,12 @@ tree options "data" # array of {children:{},...} } """ -class Tree(StyleBehavior,ScrollWidget): +# class Tree(StyleBehavior,ScrollWidget): +class Tree(ScrollWidget): def __init__(self,**options): ScrollWidget.__init__(self) level = options.get('level',0) - StyleBehavior.__init__(self,level=level) + # StyleBehavior.__init__(self,level=level) self.options = DictObject(**options) self.nodes = [] self.initflag = False @@ -269,17 +279,15 @@ class Tree(StyleBehavior,ScrollWidget): self.add_widget(w) logging.info('Tree : node=%s',type(w)) -class TextContent(StyleBehavior, PressableLabel): +class TextContent(PressableLabel): def __init__(self,level=0,**options): PressableLabel.__init__(self,**options) - StyleBehavior.__init__(self,level=level) class TextTreeNode(TreeNode): def buildContent(self): txt = self.data.get(self.treeObj.options.textField, self.data.get(self.treeObj.options.idField,'defaulttext')) - self.content = TextContent(level=self.treeObj.style_level, - text=txt, + self.content = TextContent( text=txt, size_hint=(None,None), font_size=CSize(1), text_size=CSize(len(txt)-1,1),