[wxPython-users] Associating nodes in a tree with strings
Robin Dunn
robin at alldunn.com
Thu Jun 22 13:05:05 PDT 2006
Josiah Carlson wrote:
> 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.
Internally they are either an int or a pointer, but from wxPython all
you've got is an opaque wx.TreeItemId proxy object.
> 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).
Agreed.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list