How to use TreeView.select_node

163 views
Skip to first unread message

Sergey Vdovin

unread,
Nov 11, 2018, 9:34:43 AM11/11/18
to Kivy users support
Hello.
What is node in select_node(node)?
I want to change selected position from another module but don't undertand how to handle this method. Are there some ids, names of nodes or something else..

Probably, kivy docs include the answer but I can't find anything ((

Sergey Vdovin

unread,
Nov 11, 2018, 1:10:39 PM11/11/18
to Kivy users support
I had to find the internal file describing the feature in Kivy... builtin treeview.py opened me the whole truth, thanks heaven! It turn out quite tricky to control selection from an external module. Here's my solution. If you know easier one, write me, please...

Class that describes TreeView widget (partially):
class CustomLabel(TreeViewLabel):
 
 internal_id
= NumericProperty()
 
 
...
 
class CollectionManager_Widget(BoxLayout):
 
 
...
 counter
= 0
 
for work in db_controller.collection.find():
 label_text
= name_handler(work)
 treeview
.add_node(CustomLabel(text=label_text, internal_id=counter))
 counter
+= 1
 
...


Code that describe switching to the previous element in the TreeView widget:
def move_to_previous(self):
 pre
=App.get_running_app().database_viewer.ids.CollectionManager_Widget_id.treeview #This is my own path to TreeView widget
 selected_number
= pre.selected_node.internal_id #This is a property from the code above
 pre
.deselect_node()
 pre
.select_node(pre.root.nodes[selected_number-1])


воскресенье, 11 ноября 2018 г., 17:34:43 UTC+3 пользователь Sergey Vdovin написал:
Reply all
Reply to author
Forward
0 new messages