473,799 Members | 3,106 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,e vent):
item = self.Tree.GetSe lection()
self.parent.msg box(self,self.T ree.GetItemText (item),"Kein
Titel",wxOK)
#self.Tree.Expa nd(item)
self.ExpandComp leteBranch(self .Tree,item,0)

def ExpandCompleteB ranch(self,tree ,treeitem,cooki e):
self.parent.msg box(self,"Durch lauf "+str(cookie)," Kein
Titel",wxOK)
if tree.ItemHasChi ldren(treeitem) :
lastchild = tree.GetLastChi ld(treeitem)
tree.Expand(tre eitem)
(child,cookie) = tree.GetFirstCh ild(treeitem,co okie)
self.ExpandComp leteBranch(tree ,child,cookie+1 )
while child != lastchild:
cookie = cookie +1
(child,cookie) = tree.GetNextChi ld(treeitem,coo kie)
self.ExpandComp leteBranch(tree ,child,cookie+1 )
Don´t worry aout the self.parent.msg box-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 2217
Try the following modifications.. .

def OnPopup1(self,e vent):
item = self.Tree.GetSe lection()
self.parent.msg box(self,self.T ree.GetItemText (item),"Kein
Titel",wxOK)
#self.Tree.Expa nd(item)
* self.ExpandComp leteBranch(self .Tree,item,wxNe wId())

def ExpandCompleteB ranch(self,tree ,treeitem,cooki e):
self.parent.msg box(self,"Durch lauf "+str(cookie)," Kein Titel",wxOK)
if tree.ItemHasChi ldren(treeitem) :
lastchild = tree.GetLastChi ld(treeitem)
tree.Expand(tre eitem)
(child,cookie) = tree.GetFirstCh ild(treeitem,co okie)
self.ExpandComp leteBranch(tree ,child,cookie+1 )
while child != lastchild:
* #cookie = cookie + 1
(child,cookie) = tree.GetNextChi ld(treeitem,coo kie)
* self.ExpandComp leteBranch(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
1722
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 MyApp(wxApp): def OnInit(self):
0
1200
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 allowed with the standard wxTreeCtrl. I have expermented with wxTreeListCtrl but it does not give the flexibility of html. Would it be possible to derive from wxTreeCtrl or wxTreeLayout? Or
0
1607
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 GetNextChild and I have been success in getting the first node in this manner: while child.IsOk(): print wx.TreeCtrl.GetItemText ( self, child ) if wx.TreeCtrl.ItemHasChildren ( self, child ):
3
1581
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 machines to the other branches and it is up to each branch to sell the machines to the customers. It is also the branches responsibility to make sure the machine is registered when sold and to deal with any warranty claims. The branch then sends...
2
10605
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 need to recursively go through all files and folders below the starting path and check if the file or folder is read-only and, if so, set it to not read-only. Any ideas?
10
2020
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 appear as leaves in the Tree, rather than as new branches? Here's the code..
1
1416
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
1678
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 of the company. The company consists of five branches where each the same program and, hence, same database is installed. The data between these branches have to be exchanged (i.e. customers, users). Now my question is, how should I design the...
6
5168
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 { blah(); virtual ~blah();
0
9687
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10484
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10027
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
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 we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.