Replies: 2 comments
-
So, I found a way to achieve what I want. i = 0
while True:
try:
node = self.projects.get_node_by_id(i)
if node.data and 'db_uid' in node.data and node.data['db_uid'] == project_id:
# wont work, this is not the same node for some reason?
#self.projects.move_cursor(node)
# will work, but my tree root is not displayed, so -1
self.projects.move_cursor_to_line(i-1)
return True
except UnknownNodeID:
return False
i+= 1 But only after I actually tried having an dictionary of all leafes which did not work. In fact, even if I find the correct node with the method above, only the line select works. Which will fail if for some reason the IDs are not in order or anything got changed about the tree structure. Moving cursor selects a tree-node without activating it, so that one was a silly question, I somehow overlooked that. But still, when I have the node in a dict or find it via iterating through...isnt that the same node? Why wont move_cursor not work? But I am also not a big fan of iterating through the entire tree in the first place |
Beta Was this translation helpful? Give feedback.
-
So, after carefully studying the _tree code I came to the conclusion that my above code is error prone, but this one should work: # project_id = number we are looking for
# 'db_uid' data that got added as json into the data-property of the TreeNode
for i in range(0, a_tree.last_line):
try:
node = a_tree.get_node_at_line(i)
if node.data and 'db_uid' in node.data and node.data['db_uid'] == project_id:
a_tree.move_cursor_to_line(i-1)
return True
except UnknownNodeID: # unforeseen circumstances?
continue
return False This iterates through the entire tree line by line. This is necessary as the internal TreeId isnt certainly always the same as the line number. If ones deletes nodes for instance the numbers wont add up. But for i, treeline in enumerate(a_tree._tree_lines, 1):
node = treeline.node
if node.data and 'db_uid' in node.data and node.data['db_uid'] == project_id:
a_tree.move_cursor_to_line(i-1)
return True
return False # if none was found this of course accesses an internal var which is kinda iffy..but this is what I got I guess? I created a Pull Request based on my findings: #5362 |
Beta Was this translation helpful? Give feedback.
-
I searched a bit and tried to crawl through the documentation, but I just might lack the cranial capacity to comprehend the solution I am looking for.
The Situation:
I got a tree widget with entries that have additional data in them (which is just an ID to a database entry) when that entry gets clicked I update another widget based on the given data-id in the tree Node.
But, there is the need to update the tree Widget with new leafs and/or nodes. Currently i redraw the entire thing (it doesn't happen that often so I hope performance shouldn't be a concern). I would like to save up the currently selected tree node and select it again. But for that I would have needed to save up the node objects upon creation.
What I wanted to do was just going through all Leaves and look for the content of the data-field in each of them. But there is no way to do that? And then..how to I actually highlight a Leaf.
I have a very similar function for a datatable where I repopulate the entire thing when a new entry is added and save the currently selected row through it (but here the id is directly on the row object).
So in short:
Beta Was this translation helpful? Give feedback.
All reactions