I would like to be able to contruct a tree using the wxTreeCtrl in Python,
select a node anywhere within the tree, and walk the tree starting with that
node, examining all its children and ending at its next sibling. Has anyone
already developed a piece of code which can do that?
Thanx in advance!
Eric
<!-- ****************************************************************
Eric Freese Email: eric@isogen.com
Director - Professional Services - Midwest Voice: 651 636 9180
ISOGEN International/DataChannel Fax: 651 636 9191
1611 West County Road B - Suite 204 WWW: www.isogen.com
St. Paul, MN 55113 www.datachannel.com
***************************************************************** -->
I would like to be able to contruct a tree using the wxTreeCtrl in Python,
select a node anywhere within the tree, and walk the tree starting with that
node, examining all its children and ending at its next sibling. Has anyone
already developed a piece of code which can do that?
Thanx in advance!
Eric
Not exactly what you ask, but close enough.
def UpdateBranch( self, item=None, recurse=None ):
if item is None:
item = self.tree.GetRootItem()
node = self.tree.GetPyData( item )
child,boza = self.tree.GetFirstChild( item, 0 )
for s in node:
if child.IsOk():
ni = child
child,boza = self.tree.GetNextChild( item,boza )
self.tree.SetItemText( ni, s.GetLabel() ) #self.tree.SetPyData( ni, s ) #data = self.tree.GetItemData( ni ) #data.SetData( s )
self.tree.SetItemData( ni, wxTreeItemData( s ) )
self.tree.SetItemHasChildren( ni, len(s) )
if len(s) and recurse:
self.UpdateBranch( ni, recurse )
else:
ni = self.tree.AppendItem( item, s.GetLabel() )
self.tree.SetPyData( ni, s )
self.tree.SetItemHasChildren( ni, len(s) )
if child.IsOk():
# prev list was longer
extra =
while child.IsOk():
extra.append( child )
child,boza = self.tree.GetNextChild( item,boza )
map( self.tree.Delete, extra )
I would like to be able to contruct a tree using the wxTreeCtrl in Python,
select a node anywhere within the tree, and walk the tree starting with that
node, examining all its children and ending at its next sibling. Has anyone
already developed a piece of code which can do that?
It should be fairly easy to do with the ItemHasChildren, GetFirstChild and GetNextChild methods.
···
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters? http://wxPython.org Relax with wxPython!