MenuItem and SetPyData

Hi,

How do you set custom data to a wx.MenuItem similar to TreeCtrl's
SetPydata command.
When you are building a complex hierarchical menu using a directory
structure, it would be great to associate custom data to a menuitem
that can be fetched in popup event.

Thanks

Prashant
Python 2.6.2
wxPython 2.8.10.1
XP 32

King wrote:

Hi,

How do you set custom data to a wx.MenuItem similar to TreeCtrl's
SetPydata command.
When you are building a complex hierarchical menu using a directory
structure, it would be great to associate custom data to a menuitem
that can be fetched in popup event.

Thanks

Prashant
Python 2.6.2
wxPython 2.8.10.1
XP 32
  

I'm not sure if wx supports this, but you could maintain a dictionary, like so:

item = menu.AppendItem (something)
data[item.GetId()] = custom_data

and in your event handler,

_id = event.GetId()
print data[_id]

···

--
Steven Sproat, BSc
http://www.basicrpg.com/

Thanks,

Yes, I am using dictionary method but "SetPyData" is more
pythonic. :slight_smile:

Prashant
Python 2.6.2
wxPython 2.8.10.1
XP 32

Hi,

···

On Jan 9, 11:29 am, King <animator...@gmail.com> wrote:

Thanks,

Yes, I am using dictionary method but "SetPyData" is more
pythonic. :slight_smile:

Prashant
Python 2.6.2
wxPython 2.8.10.1
XP 32

Well, you can subclass the menu and add that method to your menu (I
think). The method could then use the dict code that you and Steven
are talking about.

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

PyCon 2010 Atlanta Feb 19-21 http://us.pycon.org/

Menu items don't support attaching extra data values to the item. Although they may be able to be made to do so, it would be *lots* more complex than just maintaining your own ID --> data object map.

···

On 1/9/10 1:19 AM, King wrote:

Hi,

How do you set custom data to a wx.MenuItem similar to TreeCtrl's
SetPydata command.
When you are building a complex hierarchical menu using a directory
structure, it would be great to associate custom data to a menuitem
that can be fetched in popup event.

--
Robin Dunn
Software Craftsman