471,853 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,853 software developers and data experts.

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 2127
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
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.