ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> wxpython-users
wxpython-users
[wxpython-users] Newbie question re:wxMenuBar events
by Randy Rue other posts by this author
May 7 2008 9:12AM messages near this date
Re: [wxpython-users] Open Source Hero my @$$! | Re: [wxpython-users] Newbie question re:wxMenuBar events
Hello,

I'm using wxGlade to create a frame with menubars and several items within.
Generating code seems to create the frame and menubar correctly:

<snip> 
# Menu Bar
self.CW_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.NewId(), "Exit\tCtrl+Q", "", wx.ITEM_NORMAL)
self.CraigsWatch_menubar.Append(wxglade_tmp_menu, "System")
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.NewId(), "Contents", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.NewId(), "Buy CW", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.NewId(), "Enter Key", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.NewId(), "Contact Us", "", wx.ITEM_NORMAL)
wxglade_tmp_menu.Append(wx.NewId(), "About", "", wx.ITEM_NORMAL)
self.CW_menubar.Append(wxglade_tmp_menu, "Help")
self.SetMenuBar(self.CW_menubar)
</snip> 


Later in the code, the menu bar items are bound to events as I'd expect:
<snip> 
self.Bind(wx.EVT_MENU, self.close_cw, id=-1)
self.Bind(wx.EVT_MENU, self.open_help, id=-1)
self.Bind(wx.EVT_MENU, self.buy_license, id=-1)
self.Bind(wx.EVT_MENU, self.enter_key, id=-1)
self.Bind(wx.EVT_MENU, self.contact_us, id=-1)
self.Bind(wx.EVT_MENU, self.open_about, id=-1)
</snip> 

And later still, function stubs are set for the events:

<snip> 
    def close_cw(self, event): # wxGlade: MainFrame.<event_handler> 
        print "Event handler `close_cw' not implemented!"
        event.Skip()

    def open_help(self, event): # wxGlade: MainFrame.<event_handler> 
        print "Event handler `open_help' not implemented!"
        event.Skip()

    def buy_license(self, event): # wxGlade: MainFrame.<event_handler> 
        print "Event handler `buy_license' not implemented!"
        event.Skip()

    def enter_key(self, event): # wxGlade: MainFrame.<event_handler> 
        print "Event handler `enter_license_key' not implemented!"
        event.Skip()

    def contact_us(self, event): # wxGlade: MainFrame.<event_handler> 
        print "Event handler `contact_us' not implemented!"
        event.Skip()

    def open_about(self, event): # wxGlade: MainFrame.<event_handler> 
        print "Event handler `open_about' not implemented!"
        event.Skip()
</snip> 

Here's my problem. When I run the code (activestate python 2.5 and wxPython
2.8 on Windows XP), selecting any of the menu items runs every event on the
menu bar.



Bear with me if I'm missing anything obvious, this is my first GUI-based
python project. wxGlade has been a huge help in laying out the frames but
I'm finding I still need to dig into the code it creates to understand its
quirks...

rrue
Seattle, WA
Thread:
Randy Rue
Chester
Gre7g Luterman
Christopher Barker

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved