[wxPython-users] Associating nodes in a tree with strings

Josiah Carlson jcarlson at uci.edu
Thu Jun 22 12:38:08 PDT 2006


Robin Dunn <robin at alldunn.com> wrote:
> Josiah Carlson wrote:
> > Creating your own tree, if wxPython did not offer such functionality
> > already, would be fairly easy.  The trick is that while you may not
> > expect tree nodes to share names, other trees that could use such
> > functionality may expect to share names, so using node names as keys in
> > a dictionary probably isn't the best idea.  You could use tree node ids,
> > as I believe those are unique within the tree.
> 
> I don't think they are hashable however, which is a requirement of 
> dictionary keys.  I would probably do it simply by generating a unique 
> ID and making that be the dictionary key, and also set it as the tree 
> item data.

The tree node ids are integers, so should be hashable.  Whether or not
to keep the information in a dictionary or in the tree depends on
whether or not such uses are desireable or necessary (and whether the
user wants to traverse the tree to pull the information out).

 - Josiah





More information about the wxpython-users mailing list