Gmane
From: Robin Dunn <robin <at> alldunn.com>
Subject: Re: MenuItem problem on Windows wxPython 2.8
Newsgroups: gmane.comp.python.wxpython.devel
Date: 2007-01-12 19:11:13 GMT (1 year, 46 weeks, 4 days, 2 hours and 39 minutes ago)
Paul McNett wrote:
> Robin Dunn wrote:
>> Paul McNett wrote:
>>> We are getting this on Windows, but not on Linux, when instantiating 
>>> a wx.MenuItem.
>>>
>>
>>>   File 
>>> "C:\Python24\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 
>>> 11047, in __init__
>>>     _core_.MenuItem_swiginit(self,_core_.new_MenuItem(*args, **kwargs))
>>> wx._core.PyAssertionError: C++ assertion "wxAssertFailure" failed at 
>>> ..\..\src\common\stockitem.cpp(166) in wxGetStockLa
>>> bel(): invalid stock item ID
>>>
>>> Worked fine in 2.6. The arguments being sent to the wx.MenuItem 
>>> constructor are:
>>> {'kind': 0, 'id': 5108, 'parentMenu': 
>>> <dabo.ui.uiwx.dBaseMenuBar.FileMenu; proxy of <Swig Object of type 
>>> 'wxMenu *' at 0x20f8eb0> >}
>>>
>>> Any ideas?
>>
>> wx.ID_DEFAULT is not listed in the code that translates from a stock 
>> ID to a label string.  I'm not sure if it is supposed to be, but for 
>> now you can just not support using that ID.
> 
> I don't know what is going on. I've experimented using id's of -1, 
> wx.NewId(), wx.ID_EXIT, or even not passing the id. In each case, I get 
> the same assertion referring to an invalid stockitemid. However, I 
> haven't been able to repro this using raw wx code, so something else is 
> going on (probably in Dabo) that I need to track down. 

If no label is given then it assumes that you are wanting to use a stock 
label and so it calls wxGetStockLabel to look it up, which is basically 
just a big switch statement that maps IDs to strings.  If the given ID 
is not in there then it does the assert.  These work for me:

  >>> import wx
  >>> menu = wx.Menu()
  >>> mi = wx.MenuItem(menu, wx.ID_EXIT)
  >>> mi = wx.MenuItem(menu, -1, "Hello")
  >>> mi = wx.MenuItem(menu, wx.ID_EXIT, "Goodbye")
  >>> mi = wx.MenuItem(menu, wx.NewId(), "Foo")

These will fail:

  >>> mi = wx.MenuItem(menu, wx.ID_DEFAULT)
  >>> mi = wx.MenuItem(menu, -1)
  >>> mi = wx.MenuItem(menu, wx.NewId())

 > Why would this
> assert in Windows and not Linux?
> 

IIRC, on Linux it is also checking with GTK for stock icons and labels 
rather than just the built-in set so maybe there is some different 
assumptions made...

-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!