This commit is contained in:
yumoqing 2021-05-18 12:42:43 +08:00
parent 4a9778c086
commit fc283e6063
2 changed files with 29 additions and 13 deletions

View File

@ -34,6 +34,9 @@ class PressableBox(TouchRippleButtonBehavior, Box):
self.actived = False self.actived = False
self.csscls = self.normal_css self.csscls = self.normal_css
def active(self, flag):
self.box_actived = flag
def on_box_actived(self, o, v): def on_box_actived(self, o, v):
if self.box_actived: if self.box_actived:
self.csscls = self.actived_css self.csscls = self.actived_css

View File

@ -128,6 +128,11 @@ class TreeNode(BoxLayout):
self.addContent() self.addContent()
self.setSize() self.setSize()
def sibling(self):
if self.parentNode is None:
return [ i for i in self.treeObj.nodes if i != self ]
return [ i for i in self.parentNode.nodes if i != self ]
def selected(self): def selected(self):
self.content.selected() self.content.selected()
@ -305,9 +310,10 @@ tree options
"params", "params",
"normal_css", "normal_css",
"selected_css", "selected_css",
"single_expand",
"select_leaf_only",
"bgcolor", "bgcolor",
"checkbox", "checkbox",
"single_expand"
"multplecheck", "multplecheck",
"idField", "idField",
"textFiled", "textFiled",
@ -320,6 +326,7 @@ class Tree(WidgetCSS, ScrollWidget):
url=None, url=None,
params={}, params={},
single_expand=False, single_expand=False,
select_leaf_only=True,
bgcolor=[0.2,0.2,0.2,1], bgcolor=[0.2,0.2,0.2,1],
normal_css="default", normal_css="default",
row_height=2, row_height=2,
@ -334,6 +341,7 @@ class Tree(WidgetCSS, ScrollWidget):
self.params = params self.params = params
self.data = data self.data = data
self.single_expand=single_expand self.single_expand=single_expand
self.select_leaf_only=select_leaf_only
self.row_height=row_height self.row_height=row_height
self.rowheight = CSize(self.row_height) self.rowheight = CSize(self.row_height)
self.bgcolor = bgcolor self.bgcolor = bgcolor
@ -360,7 +368,15 @@ class Tree(WidgetCSS, ScrollWidget):
self.unselect_row() self.unselect_row()
self.selected_node = node self.selected_node = node
node.selected() node.selected()
self.dispatch('on_press', node) if not self.select_leaf_only or not node.hasChildren_nodes:
self.dispatch('on_press', node)
if node.hasChildren_nodes:
node.toggleChildren(node)
node.trigger.on_press()
if node.children_open and self.single_expand:
for n in node.sibling():
if n.hasChildren_nodes and n.children_open:
n.collapse()
def unselect_row(self): def unselect_row(self):
if self.selected_node: if self.selected_node:
@ -458,11 +474,6 @@ class TextTreeNode(TreeNode):
return return
def onPress(self,o,v=None): def onPress(self,o,v=None):
if self.hasChildren_nodes:
Logger.info('select the non-leaf node')
self.toggleChildren(self)
self.trigger.on_press()
return
Logger.info('select the leaf node') Logger.info('select the leaf node')
self.treeObj.select_row(self) self.treeObj.select_row(self)
@ -479,10 +490,6 @@ class TextTree(Tree):
self.NodeKlass = nodeklass self.NodeKlass = nodeklass
super().__init__(**options) super().__init__(**options)
def select_row(self, node):
super().select_row(node)
self.dispatch('on_press',node.data)
class MenuTreeNode(TextTreeNode): class MenuTreeNode(TextTreeNode):
def on_size(self, *args): def on_size(self, *args):
Logger.info('%s:on_size(),bgcolor=%s, fgcolor=%s,css=%s', Logger.info('%s:on_size(),bgcolor=%s, fgcolor=%s,css=%s',
@ -494,6 +501,12 @@ class MenuTreeNode(TextTreeNode):
self.content.width = self.node_box.width - self.trigger.width self.content.width = self.node_box.width - self.trigger.width
self.text_widget.width = self.content.width - CSize(1) self.text_widget.width = self.content.width - CSize(1)
def selected(self):
self.content.active(True)
def unselected(self):
self.content.active(False)
def buildContent(self): def buildContent(self):
txt = self.data.get(self.treeObj.textField, txt = self.data.get(self.treeObj.textField,
self.data.get(self.treeObj.idField,'defaulttext')) self.data.get(self.treeObj.idField,'defaulttext'))
@ -552,8 +565,8 @@ class MenuTree(TextTree):
def select_row(self, node): def select_row(self, node):
super().select_row(node) super().select_row(node)
self.dispatch('on_press',node.data) if not node.hasChildren_nodes:
self.menucall(node) self.menucall(node)
def menucall(self, node): def menucall(self, node):
url = node.data.get('url') url = node.data.get('url')