Hi all.
I'm probably just stupid and couldn't find this in the archives, so I thought I'd throw it out there.
First things first, I'm trying to do this on the OSX port.
I've got a tree like this:
root
people
view
places
view
things
view
When I generate the tree, I store off the wxTreeItemId for each node into a dictionary, associating it to a method like this:
self.peopleview = self.comonents.tree.AppendItem( people, "view" )
self.nodeDict[self.peopleview] = self.doPeopleView
where doPeopleView is defined later.
I'd like to, upon a EVT_TREE_ITEM_ACTIVATION for any of the views, be able to fire off different methods. My idea
was that in the event handler, just execute the function associated with the wxTreeItemId in the nodeDict. I don't like the idea of traversing
the tree to determine which view is being executed.
However, when I'm running the code, it appears that the self.peopleview is an instance at one location, and the
wxTreeItemId returned from the self.components.tree.GetSelection() is a different instance.
Am I wrong in thinking it should be the same instance? Any help here?
Zack Moxley
Nerd
No, you're right. TreeItemIds are wrappers around C++ objects that are
created on the fly so the TreeItemId from AppendItem and from
GetSelection are actually different instances. One solution is to use
Set/GetPyData to store your callback in.
Cheers, Frank
···
2007/2/14, Zack Moxley <mox411@gmail.com>:
However, when I'm running the code, it appears that the
self.peopleview is an instance at one location, and the
wxTreeItemId returned from the self.components.tree.GetSelection() is
a different instance.
Am I wrong in thinking it should be the same instance? Any help here?
Actually, I think I found a sloppier way around that I’m going to use for now.
Basically, I’m still storing the Id in dictionary. Later, when the event fires,
I just traverse through the dictionaries and compare for equality.
It’s sloppy, bad form, and I hate coding that way, but well, it works for now.
The tree shouldn’t be growing to any size that will cause performance problems
(best case, first item matches, worst case, last item, all cases one traversal of list).
If I do end up having to re-do it, I’ll look into this.
Thanks.
Zack Moxley
Nerd
···
On Feb 14, 2007, at 5:18 PM, Frank Niessink wrote:
2007/2/14, Zack Moxley mox411@gmail.com:
However, when I’m running the code, it appears that the
self.peopleview is an instance at one location, and the
wxTreeItemId returned from the self.components.tree.GetSelection() is
a different instance.
Am I wrong in thinking it should be the same instance? Any help here?
No, you’re right. TreeItemIds are wrappers around C++ objects that are
created on the fly so the TreeItemId from AppendItem and from
GetSelection are actually different instances. One solution is to use
Set/GetPyData to store your callback in.
Cheers, Frank
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org