[wxPython-dev] Problem with MenuItem.Destroy()

Paul McNett p at ulmcnett.com
Fri Jan 19 12:39:40 PST 2007


Robin Dunn wrote:
> Paul McNett wrote:
>> Robin Dunn wrote:
>>> Sorry, I thought I had dealt with this bug already but the fix isn't 
>>> in the code currently so maybe it accidentally got reverted or 
>>> something.
>>
>> Okay, I just found another problem, reproducible with the Menu.py 
>> example:
>>
>> --- Menu.py.orig        2006-12-08 11:49:41.000000000 -0800
>> +++ Menu.py     2006-12-22 09:04:45.000000000 -0800
>> @@ -81,6 +81,9 @@
>>          item = wx.MenuItem(menu5, 500, "&Smile!\tCtrl+S", "This one 
>> has an icon")
>>          item.SetBitmap(images.getSmilesBitmap())
>>          menu5.AppendItem(item)
>> +        menu5.RemoveItem(item)
>> +        menu4.AppendItem(item)
>> +        #item.Destroy()
>>
>>          # Shortcuts
>>          menu5.Append(501, "Interesting thing\tCtrl+A", "Note the 
>> shortcut!")
>>
>>
>> ====
>> We already know that the commented item.Destroy() segfaults in 
>> wx2.8.0.1 but not in wx 2.6. What we know now is that while the 
>> RemoveItem() works fine in both, the AppendItem() does not (segfault 
>> in 2.8).
>>
>> The good news is that I believe all the remaining issues in Dabo come 
>> down to this problem. We tend to move menu items around...
> 
> Try it like this:
> 
>         menu5.AppendItem(item)
>         item = menu5.RemoveItem(item)
>         menu4.AppendItem(item)
> 
> I'm not sure if that will work around the problem in 2.8.0.1 but it does 
> in the current CVS.

Okay, sorry to keep coming back after weeks in between :) but while your 
above sample works fine for raw wx.MenuItem instances, it doesn't work 
for Dabo which mixes-in a dabo.ui.dPemMixin and a wx.MenuItem to create 
a dMenuItem. This code in my working copy of dMenu.remove():

print "Before RemoveItem:", item.__class__.__bases__
item = self.RemoveItem(item)
print "After RemoveItem:", item.__class__.__bases__

shows that the return value from RemoveItem() has lost the Dabo part of 
__bases__:

Before RemoveItem: (<class 'dabo.ui.uiwx.dPemMixin.dPemMixin'>, <class 
'wx._core.MenuItem'>)
After RemoveItem: (<class 'wx._core.Object'>,)

wx2.6 shows the same issue. The only difference for Dabo was that we 
weren't using:

item = self.RemoveItem(item)

but discarding the return value:

self.RemoveItem(item)

Now how shall I proceed? I can make wx2.6 work by discarding the return 
value like we used to do, but I don't see a way to make wx2.8 work at 
this point, unless manually resetting __bases__ after the fact would be 
recommended. Thanks in advance for any guidance you can provide, Robin.

Paul



-- 
pkm ~ http://paulmcnett.com





More information about the wxpython-dev mailing list