From: Kevin A. <al...@se...> - 2004-04-07 17:30:46
|
Son of a... I'm pretty sure I know what is going on. On the Mac I found that the =20 '&' in the menu label was causing FindMenuItem to fail. Here's the =20 explanation I sent Robin, Stefan, etc. """ Well as usual my earlier assumption was wrong about where the bug was =20= which a sample cleared up. It isn't the reference to the menubar that =20= is the problem it is wxMenuBar::FindMenuItem method. As far as I can =20 tell, unless you remove the ampersand from the menu name, then on the =20= Mac the search will always fail and return -1. It doesn't seem to =20 matter if you leave the ampersand in for the menu item name, only the =20= menu. For example, FindMenuItem('File', '&New') and =20 FindMenuItem('File', 'New') are okay on the Mac, but =20 FindMenuItem('&File', 'New') will return -1. FindMenuItem on Windows =20 doesn't have this problem and I'm pretty sure it has always worked on =20= GTK as well. Note that FindMenu does not have a problem with an =20 ampersand in the name and as mentioned previously I don't think this =20 was broke prior to 2.5.1.0p8. You can fire up the PyShell on the Mac to confirm this. >>> mbar =3D shell.GetParent().GetMenuBar() >>> mbar.FindMenuItem('File', 'New ') 5002 >>> mbar.FindMenuItem('File', '&New ') 5002 >>> mbar.FindMenuItem('&File', '&New ') -1 =00>>> mbar.FindMenu('&File') 0 >>> mbar.FindMenu('File') 0 """ So I changed getMenuId, setChecked, and setEnabled in menu.py to strip =20= the '&' which works fine on Windows (wxPython 2.4.2.4 and wxPython =20 2.5.1.5) and Mac (wxPython 2.5.1.5), but of course I don't use Linux =20 and apparently nobody else was testing the samples and tools on Linux =20= which will tickle this particular bug: codeEditor, resourceEditor, =20 addresses, conversions, jabberChat, life, radioclient, slideshow, =20 turtle, webserver. Maybe GTK needs the & to make a match and =20 furthermore it is just wxPython 2.5.x that causes the problem. So, to verify this, simply comment out the lines menuLabel =3D =20 m.label.strip('&') and see if the problem goes away. If that's it =20 (FindMenuItem) then I'll have to do a workaround and do a 0.7.3.1 =20 release. ka On Apr 7, 2004, at 9:55 AM, Phil Edwards wrote: > On Wednesday 07 Apr 2004 12:22 pm, Phil Edwards wrote: >> >> I've got a hard drive problem on one of my machines - I've got =20 >> backups so >> it's an inconvenience as opposed to a major disaster, but it means =20= >> the new >> RPM's won't be ready until the end of today at the earliest. :-( > > Okay, back up and running, thank $DEITY for recordable DVD's.... > > Now, I have a problem with 0.7.3 when running with python 2.2.2 and =20= > wxPython > 2.5. I've installed 0.7.3 from the tarball and wxPython from the RPM = on > wxpython.org. > > When I run the resource editor from a command line prompt, I get this: > > -----begin----- > [phile@localhost phile]$ > /usr/lib/python2.2/site-packages/PythonCardPrototype/tools/=20 > resourceEditor/resourceEditor.py > Traceback (most recent call last): > File =20 > "/usr/lib/python2.2/site-packages/PythonCardPrototype/binding.py", =20 > line > 268, in dispatchOpenBackground > self.scriptable.dispatch.eventOccurred( event.OpenBackgroundEvent( > self.scriptable ) ) > File =20 > "/usr/lib/python2.2/site-packages/PythonCardPrototype/dispatch.py", > line 83, in eventOccurred > handler.getFunction()(self._scriptable, nativeEvent) > File > "/usr/lib/python2.2/site-packages/PythonCardPrototype/tools/=20 > resourceEditor/resourceEditor.py", > line 134, in on_openBackground > self.updatePanel(self.rsrc) > File > "/usr/lib/python2.2/site-packages/PythonCardPrototype/tools/=20 > resourceEditor/resourceEditor.py", > line 1243, in updatePanel > self.menuBar.setEnabled('menuFileRun', 1) > File "/usr/lib/python2.2/site-packages/PythonCardPrototype/menu.py", = =20 > line > 309, in setEnabled > self.Enable(id, aBoolean) > File "/usr/lib/python2.2/site-packages/wx/core.py", line 7602, in =20= > Enable > return _core.MenuBar_Enable(*args, **kwargs) > wx.core.PyAssertionError: C++ assertion "wxAssertFailure" failed in > ../src/common/menucmn.cpp(896): attempt to enable an item which =20 > doesn't exist > > ------end------ > > The problem is that at line 309 (line 316 in the code below) of =20 > menu.py, the > value of 'id' is set to -1 when it tries to call self.Enable(). As far = =20 > as I > can see, the code in this part of menu.py hasn't changed between 0.7.2 = =20 > and > 0.7.3, so I'm stumped as to what's going on. I put a bunch of print > statements into menu.py so it looks like this: > > 299 def setEnabled( self, aString, aBoolean=3D1) : > 300 print 'setEnabled, aString =3D [%s], aBoolean =3D [%s]' % =20= > (aString, > aBoolean) > 301 i =3D 0 > 302 for m in self.menus: > 303 print 'm is now [%s]' % m > 304 menuLabel =3D m.label.strip('&') > 305 print 'm.label =3D [%s], menuLabel =3D [%s]' % = (m.label, =20 > menuLabel) > 306 if m.name =3D=3D aString: > 307 print 'm.name =3D=3D aString' > 308 self.EnableTop(i, aBoolean) > 309 break > 310 for mi in m.items: > 311 print 'mi is now [%s]' % mi > 312 if mi.name =3D=3D aString: > 313 print 'mi.name =3D=3D aString, menuLabel =3D = [%s]' % > menuLabel > 314 id =3D self.FindMenuItem(menuLabel, mi.label) > 315 print 'found menu id [%s]' % id > 316 self.Enable(id, aBoolean) > 317 break > 318 i +=3D 1 > > When I run with this code, my output is: > > m.label =3D [&File], menuLabel =3D [File] > mi is now [MenuItem=3D{'_listeners': > [<PythonCardPrototype.dispatch.EventDispatch instance at 0x87d3d6c>], > 'checked': 0, 'name': 'menuFileNew', 'this': '_783a7d08_p_wxMenuItem', > 'checkable': 0, 'thisown': 1, 'enabled': 1, 'command': None, 'label': > '&New...\tCtrl+N'}] > mi is now [MenuItem=3D{'_listeners': > [<PythonCardPrototype.dispatch.EventDispatch instance at 0x87d4e14>], > 'checked': 0, 'name': 'menuFileOpen', 'this': = '_90587d08_p_wxMenuItem', > 'checkable': 0, 'thisown': 1, 'enabled': 1, 'command': None, 'label': > '&Open...\tCtrl+O'}] > mi is now [MenuItem=3D{'_listeners': > [<PythonCardPrototype.dispatch.EventDispatch instance at 0x87d592c>], > 'checked': 0, 'name': 'menuFileSave', 'this': = '_585d7d08_p_wxMenuItem', > 'checkable': 0, 'thisown': 1, 'enabled': 1, 'command': None, 'label': > 'Save\tCtrl+S'}] > mi is now [MenuItem=3D{'_listeners': > [<PythonCardPrototype.dispatch.EventDispatch instance at 0x87d5ffc>], > 'checked': 0, 'name': 'menuFileSaveAs', 'this': =20 > '_10627d08_p_wxMenuItem', > 'checkable': 0, 'thisown': 1, 'enabled': 1, 'command': None, 'label': =20= > 'Save > &As...'}] > mi is now [MenuItem=3D{'_listeners': > [<PythonCardPrototype.dispatch.EventDispatch instance at 0x87d647c>], > 'checked': 0, 'name': 'menuFileRevert', 'this': =20 > '_d06e7d08_p_wxMenuItem', > 'checkable': 0, 'thisown': 1, 'enabled': 1, 'command': None, 'label': > 'Revert'}] > mi is now [MenuItem=3D{'_listeners': > [<PythonCardPrototype.dispatch.EventDispatch instance at 0x87d6e8c>], > 'checked': 0, 'name': 'fileSep1', 'this': '_08747d08_p_wxMenuItem', > 'checkable': 0, 'thisown': 1, 'enabled': 1, 'command': None, 'label': =20= > '-'}] > mi is now [MenuItem=3D{'_listeners': > [<PythonCardPrototype.dispatch.EventDispatch instance at 0x87d7604>], > 'checked': 0, 'name': 'menuFileRun', 'this': '_08787d08_p_wxMenuItem', > 'checkable': 0, 'thisown': 1, 'enabled': 1, 'command': 'fileRun', =20 > 'label': > '&Run\tCtrl+R'}] > mi.name =3D=3D aString, menuLabel =3D [File] > found menu id [-1] > Traceback (most recent call last): > File =20 > "/usr/lib/python2.2/site-packages/PythonCardPrototype/binding.py", =20 > line > 268, in dispatchOpenBackground > self.scriptable.dispatch.eventOccurred( event.OpenBackgroundEvent( > self.scriptable ) ) > File =20 > "/usr/lib/python2.2/site-packages/PythonCardPrototype/dispatch.py", > line 83, in eventOccurred > handler.getFunction()(self._scriptable, nativeEvent) > File > "/usr/lib/python2.2/site-packages/PythonCardPrototype/tools/=20 > resourceEditor/resourceEditor.py", > line 134, in on_openBackground > self.updatePanel(self.rsrc) > File > "/usr/lib/python2.2/site-packages/PythonCardPrototype/tools/=20 > resourceEditor/resourceEditor.py", > line 1243, in updatePanel > self.menuBar.setEnabled('menuFileRun', 1) > File "/usr/lib/python2.2/site-packages/PythonCardPrototype/menu.py", = =20 > line > 316, in setEnabled > self.Enable(id, aBoolean) > File "/usr/lib/python2.2/site-packages/wx/core.py", line 7602, in =20= > Enable > return _core.MenuBar_Enable(*args, **kwargs) > wx.core.PyAssertionError: C++ assertion "wxAssertFailure" failed in > ../src/common/menucmn.cpp(896): attempt to enable an item which =20 > doesn't exist > > I've tried some of the other samples (proof, addresses, etc) and these = =20 > run > without any problems, it looks like its just the resource editor in =20= > this > case. > > --=20 > > Regards > > Phil Edwards > Brighton, UK > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: IBM Linux Tutorials > Free Linux tutorial presented by Daniel Robbins, President and CEO of > GenToo technologies. Learn everything from fundamentals to system > administration.http://ads.osdn.com/?ad_id=3D1470&alloc_id=3D3638&op=3Dcl= ick > _______________________________________________ > Pythoncard-users mailing list > Pyt...@li... > https://lists.sourceforge.net/lists/listinfo/pythoncard-users > |