473,505 Members | 15,212 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2199
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1708
by: Krzysztof Kaczkowski | last post by:
Hello Im having problem, wxTreeCtrl generate 3 x EVT_TREE_SEL_CHANGED on click item right button mouse. This problem only win32. Why? Simple example: from wxPython.wx import * class...
0
1176
by: Brendan | last post by:
Hello, I am looking for any pointers on creating a Tree control which can render html snippets as labels. On each leaf of the tree I want to show text, but with more formatting than is...
0
1593
by: danielpm72 | last post by:
Hi, I want to read a wxTreeCtrl from the root since I want to store all the information in it in a python dictionary. I know that the methods I have to use are ItemHasChildren, GetFirstChild and...
3
1562
by: Stewart Allen | last post by:
Hi there, I'm trying to create a query that will display all branches in a company even if that branch hasn't made a claim. The main manufacturing company makes the machines and distributes the...
2
10547
by: melo | last post by:
Hello, I've been struggling with a function(s) to recursively set all folders and files to NOT read-only. So, I thought I'd post this message. What I need to do is: given a starting path, I...
10
1994
by: Dan Nash | last post by:
Hi peeps.. Im using the TreeView control from IE COntrols to create a directory structure, and trying to do it recursively. The code works, but my question is simply how can I make the subdirs...
1
1400
by: mitsura | last post by:
Hi, it is possible to change the font (bold, underline, italic) in the text used in a wxTreeCtrl? I looked in the wxPython demo but I can't find anything. Any help much appreciated. Kris
3
1665
by: Alwin | last post by:
Hey All! I am currently designing a database model for (at first sight) a simple order entry program. The problem I'm currently facing is the exchange of data between the databases of each branch...
6
5128
by: Jeff Newman | last post by:
Hello, Could anyone explain to me why the following class's destructor shows up as having multiple branches? (At least as judged by gcov 4.1.2 when compiled with gcc 4.1.2 ): struct blah {...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7367
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4699
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.