You probably already found it, but just in case you overlooked it, there is
also the main demo code (as opposed to the tree Controls/wxTreeCtrl
example). From the demo, click on the "Overview" tree item (the topmost
tree item) and then go to the Demo Code tab. That will show you the code
for the wxPythonDemo class in the demo application, which has a tree in it
that is somewhat more complex than the wxTreeCtrl example.
In a couple weeks, I'll have one that is fairly complex (there's a bunch of
unrelated stuff I need to do first). It will be a project tree much like MS
DevStudio or other IDE applications.
···
-----Original Message-----
From: Niki Spahiev <spahievi@vega.bg>
To: Jonathan Pennington <wxpython-users@lists.sourceforge.net>
Date: Wednesday, January 10, 2001 4:17 PM
Subject: Re: [wxPython] wxTreeCtrl sample requested
Hello Jonathan,
Wednesday, January 10, 2001, 6:28:04 AM, you wrote:
I'm looking for code to read that uses wxTreeCtrl that's more indepth
than the demo. Anybody have a fairly complicated application using
Trees that I can read the code for?Background: I'm building an application that is making dictionaries 4
levels deep, with the bottom most level being datasets. Ex:Level:
sub:
subsub:
dataset:
datapoint0
datapoint1
datapoint2The user will be adding and deleting at the level of subsub and below,
so I need to be able to update the tree on the fly, as well as
copy/move items from branch to branch. I keep all the data in a main
dictionary in memory.Anybody have anything similiar that I can read? Thanks.
I am using dynamic tree made from TreeNodes as follow:
class TreeNode:
"""array of subnodes plus header"""def __len__(self):
return 0def __getitem__( self, item ):
raise IndexErrordef GetLabel( self ):
raise RuntimeError, 'not implemented'class ListNode(TreeNode):
def __init__(self, nodes, title):
self._nl = nodes
self._tt = titledef __len__(self):
return len(self._nl)def __getitem__( self, item ):
return self._nl[item]def GetLabel( self ):
return self._ttI start tree with like this:
root = self.tree.AddRoot( dd.GetLabel() )
self.tree.SetPyData( root, dd )
self.tree.SetItemHasChildren( root, len(dd) )where dd is TreeNode e.g.:
dd = ListNode( [
ListNode( [
ListNode( [DataNode(), ...], 'dataset' ),
ListNode( [DataNode(), ...], 'dataset' ),
], 'subsub' )
], 'sub' )then i use this to update tree according to current state of
TreeNodes:def UpdateBranch( self, item, recurse=None ):
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 )
#for wx 2.2.1
#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 )wx 2.2.1 has bug in wxTreeItemData for which is commented code
HTH,
Niki Spahiev_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users