Recursively expand all branches ox wxTreeCtrl

Piet pit.grinja at gmx.de
Sun Apr 4 03:53:44 EDT 2004


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?



More information about the Python-list mailing list