|
From: Kevin A. <al...@se...> - 2001-09-05 01:25:53
|
In order to make a menu item checkable, you need to specify that in the
.rsrc.py file. For example, I modified conversions.rsrc.py:
{ 'type':'Menu',
'name':'mnuConvert',
'label':'Convert',
'items': [
{ 'type':'MenuItem',
'name':'menuConvertMorseCode',
'label':'Morse Code',
'checkable':1 },
{ 'type':'MenuItem',
'name':'menuConvertTemperature',
'label':'Temperature',
'checkable':1,
'checked':1} ]
}
So, both 'Convert' menu items are checkable and I set 'Temperature' to be
checked when the application starts. I modified conversions.py, so that when
one of the items is checked, the other one is unchecked.
def on_menuConvertMorseCode_select(self, menu, event):
self.conversion = MorseCodeConversion(self.components)
self.menuBar.setChecked('menuConvertMorseCode')
self.menuBar.setChecked('menuConvertTemperature', 0)
def on_menuConvertTemperature_select(self, menu, event):
self.conversion = TemperatureConversion(self.components)
self.menuBar.setChecked('menuConvertMorseCode', 0)
self.menuBar.setChecked('menuConvertTemperature')
The defaults (specified in spec.py) are that menus are enabled, and menu
items are enabled, but not 'checkable', so the other samples run without
modifications. If you specify that a menu item is checkable and want it
checked you'll have to specify that, since the default is 0, which is why it
is specified for 'Temperature' above.
ka
> -----Original Message-----
> From: pyt...@li...
> [mailto:pyt...@li...]On Behalf Of Kevin
> Altis
> Sent: Tuesday, September 04, 2001 4:36 PM
> To: pyt...@li...
> Subject: RE: [Pythoncard-users] enable and check menu items
>
>
> I changed the method names to
> getChecked
> setChecked
> getEnabled
> setEnabled
>
> getChecked and getEnabled return -1 if the MenuItem can't be found
>
> >>> bg.menuBar.getEnabled('bogus')
> -1
>
> You can enable or disable a whole menu like so (example using proof.py):
>
> >>> bg.menuBar.setEnabled('mnuFile', 0)
>
> Due to a missing feature in wxPython, finding out whether a whole menu is
> enabled or disabled will have to wait until 2.3.2 is released
> unless I find
> that I missed a method in the docs.
>
> BTW, the methods above obviously aren't dot notation. You would need to do
> something like:
> >>> bg.menubar.mnuFile.mnuExit.enabled = 1
>
> which menu.py doesn't currently support. Since menu.py needs to be
> completely rewritten at some point, we'll probably wait until the
> rewrite to
> do dot notation. The existing module won't accomodate it very easily.
>
> ka
>
> > -----Original Message-----
> > From: pyt...@li...
> > [mailto:pyt...@li...]On Behalf Of Kevin
> > Altis
> > Sent: Tuesday, September 04, 2001 3:31 PM
> > To: pythoncard-Users
> > Subject: [Pythoncard-users] enable and check menu items
> >
> >
> > I updated menu.py in cvs, so you can now enable/disable and
> check/uncheck
> > menu items. You pass in the 'name' of the MenuItem object as
> > defined in the
> > .rsrc.py file for the application.
> >
> > For example, if you run proof.py with the shell, you can disable
> > the File ->
> > Exit menu item with:
> >
> > >>> bg.menuBar.enable('mnuExit', 0)
> >
> > and then enable it with:
> >
> > >>> bg.menuBar.enable('mnuExit')
> >
> > you can check a menu item the same way. You can't disable/enable a whole
> > menu right now, because the method I wanted to use apparently isn't in
> > wxPython 2.3.1 even though it is in the docs. If I figure out
> > another way to
> > do it, I'll make the change.
> >
> > I updated the addresses sample to use this method rather that relying on
> > wxPython method calls directly.
> >
> > #menubar = self.GetMenuBar()
> > #id = menubar.FindMenuItem('File', 'Import Outlook')
> > #menubar.Enable(id, 0)
> > self.menuBar.enable('menuFileImportOutlook', 0)
> >
> > ka
> >
> >
> > _______________________________________________
> > Pythoncard-users mailing list
> > Pyt...@li...
> > https://lists.sourceforge.net/lists/listinfo/pythoncard-users
> >
>
>
> _______________________________________________
> Pythoncard-users mailing list
> Pyt...@li...
> https://lists.sourceforge.net/lists/listinfo/pythoncard-users
>
|