Bob Klahn wrote:
Hi Bob,
> I like the approach Robin lays out in Listing 6.4 (pages 159-160) of
> "wxPython in Action" to create an application's menu bar, menus, and
> menu items.
>
> But I need to be able to disable or enable specific menu items as
> various situations arise. Robin's approach does not create separate
> menu-item id's, so I'm currently at a loss as to how best to accomplish that.Well, you could accomplish this with a couple of approach:
[snip]Thanks, Andrea ... but I didn't make myself clear. I already have working menus. I simply want to streamline my code and make the overall menu structure as visually clear as possible in the code, and Robin's code that I cited above does that.
So what I'm looking for is how to extend Robin's code so that I can enable/disable selected items, each ideally with al single line of code.
Said differently, I'm not looking for a whole new approach. Rather, I'd like to use Robin's approach if it's possible to do so elegantly. I just don't see how to do that at the moment.
well Bob,
nothing against Robin's code, most times it's wonderful,
but in this case Robin's code is not the most streamlined code I can imagine.
Although my code is very premature, you might take a look and maybe even improve it
This all I've to define for a menu and
this small piece of code already gives me all bindings for the standard events !!
# *************************************************************
# Define the menu
# *************************************************************
menus = [
['&File', [ ( '&New/Open\tCtrl+O', 'Open'),
( '&Save\tCtrl+S', 'Save'),
( 'Save &As ...', 'Save_As'),
( '-' ),
( '&Print\tCtrl+P', 'Print'),
( 'Pr&int Preview', 'Print_Preview'),
( 'Page Setup', 'Page_Setup'),
( '-' ),
( '&Export', 'Export'),
( '-' ),
( '&Close', 'Close') ]],
['&Edit', [ ( '&ToDo', 'ToDo'),
( '&Edit', 'Edit') ]],
['&Settings', [ ( '&ToDo', 'ToDo') ]],
['&View', [ ( '&ToDo', 'ToDo'),
( '&View', 'View') ]],
['&Help', [ ( '&PyLab_Works', 'Prog_Help'),
( '&Send &Bug Report', 'Send_Bug_Report'),
( 'Check For New Version', 'Check_New_Version'),
( '&About', 'About') ]]]
# Create the menu
Create_Menus ( self, menus )
# *************************************************************
I've attached the library, which has free running demo mode.
cheers,
Stef
menu_support.py (4.65 KB)
···
At 08:00 PM 11/25/2007, Andrea Gavana wrote:
On Nov 26, 2007 12:07 AM, Bob Klahn wrote: