Is there something wrong with this code for traversing all the items in
a tree?
def traverseTree(self, tree, item=None, level=0):
# tree is a wxTreeCtrl
if item is None:
item = tree.GetRootItem()
print '%s%s' % (' '*level, tree.GetPyData(item))
item, cookie = tree.GetFirstChild(item, 0)
while item.isOk():
self.traverseTree(tree, item, level+1)
item, cookie = tree.GetNextChild(item, cookie)
def someMethod(self):
...
self.traverseTree(aTreeCtrl)
...
For a tree that visibly looks like this:
[-] A
>--[-] B
> `--[-] C
>--[+] D (contains 1 hidden child 'E')
`--[+] F (contains 1 hidden child 'G')
I only get A, B and C to print. I'm expecting D, E, F and G to print as
well.
You can see that I'm preserving and passing the cookie. I tried using
id(item) and randrange(100,999999) in place of 0 for the initial
cookie, just to make sure I started it off with something different.
That didn't help.
I'm stumped on this one.
Full traversal could be useful in general. Specifically, I just want to
call tree.Expand(item) on all items to get the entire tree to expand.
···
--
Chuck
http://ChuckEsterbrook.com