[wxPython-users] TreeCtrl GetNextVisible

Robin Dunn robin at alldunn.com
Fri Sep 1 15:56:11 PDT 2006


Saketh Bhamidipati wrote:

>         >  I still want to iterate through the TreeCtrl, but without the
>         major
>         >  issue that all nodes must be visible for the iteration to work.
>         >
> 
>         Use GetFirstChild/GetNextChild.
> 

> 
>     I got it to work with this code:
>             while current.IsOk ():
>                 new = None
> 
>                 if current == self.tree.GetRootItem():
>                     new = self.tree.GetFirstChild(current)
> 
>                 else:
>                     new = self.tree.GetNextSibling (current)
> 

Try looping like this instead:

	parent = self.tree.GetRootItem()
	item, cookie = self.tree.GetFirstChild(parent)
	while item:
		# ...do stuff with item...
		item, cookie = self.tree.GetNextChild(parent, cookie)

if you ever want to support more than one level below the root then this 
is easily adapted to a recursive algorithm.


>     But I have a problem - if the user minimizes the root node, nothing
>     but the root node gets written. How can I fix this?

The code above shouldn't care about the visibility of the items, unless 
you are using the virtual capabilities of the tree and are removing 
items from the tree when parent nodes are collapsed...

> 
> Actually, I could solve this problem if I just made the root node 
> unminimizable. How can I do that?

Catch the EVT_TREE_ITEM_COLLAPSING event and if the item is the root 
node then veto the event.

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!





More information about the wxpython-users mailing list