469,288 Members | 2,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,288 developers. It's quick & easy.

Recursively expand all branches ox wxTreeCtrl

Hi there.
I have a problem when working with a wxTreeCtrl. I would like to
expand all branches of a sepcific position in a tree with a single
command. Since there does not appear to be such a command, I tried to
write my own recursive function. Here is the code snippet:
def OnPopup1(self,event):
item = self.Tree.GetSelection()
self.parent.msgbox(self,self.Tree.GetItemText(item ),"Kein
Titel",wxOK)
#self.Tree.Expand(item)
self.ExpandCompleteBranch(self.Tree,item,0)

def ExpandCompleteBranch(self,tree,treeitem,cookie):
self.parent.msgbox(self,"Durchlauf "+str(cookie),"Kein
Titel",wxOK)
if tree.ItemHasChildren(treeitem):
lastchild = tree.GetLastChild(treeitem)
tree.Expand(treeitem)
(child,cookie) = tree.GetFirstChild(treeitem,cookie)
self.ExpandCompleteBranch(tree,child,cookie+1)
while child != lastchild:
cookie = cookie +1
(child,cookie) = tree.GetNextChild(treeitem,cookie)
self.ExpandCompleteBranch(tree,child,cookie+1)
Donīt worry aout the self.parent.msgbox-function. This just calls the
wxMessageDialog, gets the GetModal and closes the dialog. The
msgbox-function works fine but the recursive complete branch expanding
does not. When ativating the function, I first get the value "0" in
the MEssageDialog, then the selected node is expanded, then I get a
very high number (> 4 million), then the first child of the originally
selected node is expanded, I get a very high value again in the
cookie-MessageDialog, and then I get only MessageDialogs with the
value "1", and nothing happens to the tree.
Can anybody help. I think that the error lies in the assignment of the
values for the cookies, but I donīt know how these things work.
Can anybody help?
Jul 18 '05 #1
1 2048
Try the following modifications...

def OnPopup1(self,event):
item = self.Tree.GetSelection()
self.parent.msgbox(self,self.Tree.GetItemText(item ),"Kein
Titel",wxOK)
#self.Tree.Expand(item)
* self.ExpandCompleteBranch(self.Tree,item,wxNewId() )

def ExpandCompleteBranch(self,tree,treeitem,cookie):
self.parent.msgbox(self,"Durchlauf "+str(cookie),"Kein Titel",wxOK)
if tree.ItemHasChildren(treeitem):
lastchild = tree.GetLastChild(treeitem)
tree.Expand(treeitem)
(child,cookie) = tree.GetFirstChild(treeitem,cookie)
self.ExpandCompleteBranch(tree,child,cookie+1)
while child != lastchild:
* #cookie = cookie + 1
(child,cookie) = tree.GetNextChild(treeitem,cookie)
* self.ExpandCompleteBranch(tree,child,wxNewId())

I use wxNewId() for cookie ids so that all calls will have unique cookie
ids. I'm not sure this is technically necessary, but it can't hurt.

Also, by altering the cookie id during the while loop, you are
destroying the cookie that is necessary to access the remainder of the
branch.

Give the above (without the '*' at the beginning of the line) a try.

- Josiah
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Krzysztof Kaczkowski | last post: by
reply views Thread by Brendan | last post: by
reply views Thread by danielpm72 | last post: by
3 posts views Thread by Stewart Allen | last post: by
10 posts views Thread by Dan Nash | last post: by
1 post views Thread by mitsura | last post: by
6 posts views Thread by Jeff Newman | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.