I'm looking for the accepted wxPythonic idiom for doing what I think must be a common task.
I have a wxTreeCtrl in which is represented a data model. Some expandable items represent objects. Each of those objects is the root of a sub-tree which reflects its internal structure. Two objects of the same class will be represented in separate sub-trees having identical structure.
An operation on an object will affect some sub-item of its representation in the wxTreeCtrl. I have the item and I know what class object it represents, so I know the traversal that will get me from the object root to the sub-item I want to manipulate. How do wxPythonistas normally do this?
By way of example, let's say that somewhere in my wxTreeCtrl is an item that represents a Whozits. A Whozits has lots of interesting bits and pieces, one of which is a Thingamabob, whose tree item must turn purple under certain circumstances. The Thingamabob for a Whosits is always the second child of the third child of the first child of the toplevel Whozits item:
+- uninteresting stuff
+- The Whozits I'm working with
>
+- A collection of Whozits parts
> >
> +- Some Part
> >
> +- Another Part
> >
> +- Yet Another Part
> >
> +- Almost What I want
> >
> +- The Thingamabob I want
>
+- Other Stuff in a Whozits
+- A different Whozits I don't care about right now
+- more uninteresting stuff
Right now, I'm doing the following to get from a Whozits to a Thingamabob:
cookie = 0
c2, cookie = tree.GetFirstChild(whozits, cookie)
c3, cookie = tree.GetFirstChild(c2, cookie)
c3, cookie = tree.GetNextChild(c2, cookie)
c4, cookie = tree.GetFirstChild(c3, cookie)
c4, cookie = tree.GetNextChild(c3, cookie)
print 'thingamabob is item', c4
It works, but it's ugly and it certainly doesn't scale well. I'm about to generalize this in a helper routine that takes a tree, a starting point, and a list representing the traversal path:
thingamabob = traverseTree(tree, from = whozits, route = [1, 3, 2])
If there's a standard way to do this, I'd be happy if someone would point me in the right direction.
Regards,
Greg Goodman