Problem with wxTreeCtrl and Python

I made a dictionairy which uses the wxTreeItemId as a key and a string
as the value. However, after storing I can't seem to retrieve the data
in the wx.EVT_TREE_ITEM_ACTIVATED using something like:

name = itemdict[ evt.GetItem() ]

So I tried storing the name in the TreeItemData using:

self.tree.SetPyData( item, name )

but when I try to retrieve the name in the wx.EVT_TREE_ITEM_ACTIVATED
using:

name = self.tree.GetPyData[ evt.GetItem() ]

it fails again.

Why isn't this working?

Hi,

Try :

name = self.tree.GetPyData( evt.GetItem() )

instead of

Bye.

···

On 25 juil, 14:49, BigPilot <bigpi...@linuxmail.org> wrote:

I made a dictionairy which uses the wxTreeItemId as a key and a string
as the value. However, after storing I can't seem to retrieve the data
in the wx.EVT_TREE_ITEM_ACTIVATED using something like:

name = itemdict[ evt.GetItem() ]

So I tried storing the name in the TreeItemData using:

self.tree.SetPyData( item, name )

but when I try to retrieve the name in the wx.EVT_TREE_ITEM_ACTIVATED
using:

name = self.tree.GetPyData[ evt.GetItem() ]

it fails again.

Why isn't this working?

Thanks for pointing that out. It works!

···

On Jul 25, 3:25 pm, Noethys <noet...@gmail.com> wrote:

Hi,

Try :

name = self.tree.GetPyData( evt.GetItem() )

instead of

Bye.

On 25 juil, 14:49, BigPilot <bigpi...@linuxmail.org> wrote:

> I made a dictionairy which uses the wxTreeItemId as a key and a string
> as the value. However, after storing I can't seem to retrieve the data
> in the wx.EVT_TREE_ITEM_ACTIVATED using something like:

> name = itemdict[ evt.GetItem() ]

> So I tried storing the name in the TreeItemData using:

> self.tree.SetPyData( item, name )

> but when I try to retrieve the name in the wx.EVT_TREE_ITEM_ACTIVATED
> using:

> name = self.tree.GetPyData[ evt.GetItem() ]

> it fails again.

> Why isn't this working?

To answer the original problem, the wx.TreeItemId instances are transient, and are just a temporary opaque handle that contains some platform specific details needed to access the tree item. This means that the wx.TreeItemId you got when you created the item will not be the the same instance you get from evt.GetItem(), although their hidden guts will likely be the same. So because of this they should not be used as dictionary keys.

···

On 7/25/10 3:41 PM, BigPilot wrote:

On 25 juil, 14:49, BigPilot<bigpi...@linuxmail.org> wrote:

I made a dictionairy which uses the wxTreeItemId as a key and a string
as the value. However, after storing I can't seem to retrieve the data
in the wx.EVT_TREE_ITEM_ACTIVATED using something like:

name = itemdict[ evt.GetItem() ]

--
Robin Dunn
Software Craftsman