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
datapoint2
The 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 0
def __getitem__( self, item ):
raise IndexError
def GetLabel( self ):
raise RuntimeError, 'not implemented'
class ListNode(TreeNode):
def __init__(self, nodes, title):
self._nl = nodes
self._tt = title
def __len__(self):
return len(self._nl)
def __getitem__( self, item ):
return self._nl[item]
def GetLabel( self ):
return self._tt
I 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