I am trying to associate nodes in my TreeCtrl with strings. For example, a node “Lion” would have the string “King of the beasts” associated with it. This functionality is not native to TreeCtrl.
This would permit me to have a TreeCtrl and a TextCtrl, and all of the nodes on the TreeCtrl can have their descriptors edited in the TextCtrl. So if, in the TreeCtrl, you clicked on “Lion”, then the string “King of the beasts” would show up in the TextCtrl. If you edited the string in the TextCtrl, then the descriptor would change.
I tried to implement this using a list and a dictionary, which are synchronized using a method called SyncStacks(), thus emulating an ordered associative array. This does not appear to be the most efficient way of accomplishing the task of mimicking an ordered associative array.
I need an ordered associative array because then each node’s text would be the key, and its descriptor would be the value. The order the nodes have in the TreeCtrl would be the order in the ordered associative array. Then, calling GetOrderedText(), I would get all of the descriptors in the same order that the nodes have in the TreeCtrl.
My current way of implementing this descriptor functionality is not working. Although the methods SyncStacks() and GetOrderedText() work when tested separately, in my application they do not operate properly (presumably due to my erroneous programming).
(Would it be better if I just created my own class, derived from wx.TreeCtrl? Or would the problem remain equally as difficult?) I tried studying the outlining application Leo’s code to understand how it accomplishes the task, but I found no help.
Here are my problems:
-
On the creation of a node, the list does not append its text for some reason.
-
Editing a label causes problems - the list does not change.
-
Problems of a similar technical nature - the list does not add the entries, so removing them later on doesn’t work.
-
My implementation is so unwieldy!
There must be a better way of accomplishing this task. I just can’t seem to find it in my brain or in other people’s code. Mimicking an ordered associative array seemed the best way to me, but it is not working. Is there any other way in which I can associate nodes in my TreeCtrl with strings?
Thank you for the assistance!
NotalonWindow.py (15.6 KB)