[wxPython] wxTreeCtrl sample requested

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
                                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

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users

* Ken <kens@sightreader.com> [010110 20:06]:

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).

Actually, I was using the main demo tree as my example. Brendan's
helped with some of the manipulation stuff, I haven't had
time to check out Niki's example yet. Let me explain a bit more
clearly what kind of data I have and what specifically I need to do
with it.

It's GPS data from any variety of receivers. I have the trees
mentioned before, the last branch being either 'Waypoint+num',
'Track+num', etc. where num is the total number of data sets-1. If the
user downloads (for instance) 35 waypoints, there are then 35
sub-dictionaries in the main 'Waypoints' dictionary, which is in
MainDict:

MainDict = {'Waypoints': {
       'Waypoints0': {
               1:{'Field0': 'name',
                  'Field1': lat,
            'Field2': lon},
               2:{'Field0': 'name',
                  'Field1': lat,
            'Field2': lon}, ...
               }
      }
     }

I can now figure out how to do most things when I have the data, but
the problem comes in displaying the final datapoints. Each point in
Waypoints0, ie. each waypoint, is a dictionary. I need to list these
in a wxListCtrl window next to the tree, but I can't
statically define the columns because I have groups, tracks, routes,
etc. All of these have different end data fields. What's more, each
receiver sends a different sentance. In otherwords, my receiver may
send:

waypoints = [name,type,lat,lon,symbol]

and another may send:

waypoints = [name,comment, lat, lon, elev,
       symbol, city, proximity, favorite song, etc.]

I figure there must be a way to create the list columns- on tree
expansion- according to the number of items that must be displayed, or
according to the parent node, etc. Something like:

def OnItemExpanding(self, event)
    item = ??? (top node?) # Waypoints
    sub-item = ??? (parent node?) # Waypoints0
    data = MainDict[item][sub-item].keys()
    if item is 'Waypoints':
       ListBuilder(self, 'Waypoints', sub-item, data)

class ListBuilder:
   def __init__(self, parent, type, node, data)
   magicFunction(type, node, data)

   def magicFunction(type, node, data)
       access an already created tree, insert this data, and open the
       list on the ajoining page with the correct number of columns.

'type' can actually be figured out by node...

···

-----------

Of course, I can figure out a way to do this given time, but if
someone has a way already, I'd prefer not to reinvent the wheel. If I
get to the point where the number of columns is generated correctly, I
can have the user define the column names on the first run of the
program and save them to a userprefs file, then I can say:

if type is 'Waypoints':
   try:
  _columnlist=user_waypoint_columns
   except:
  _columnlist=standard_waypoint_columns

Thanks again.
-J
--
Jonathan Pennington | http://coastalgeology.org
Site Manager | Protection and stewardship
CoastalGeology.Org (CGO) | through public education.
john@coastalgeology.org | Join CGO, make a difference.

_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users