Author: bugman Date: Thu Jun 30 13:29:08 2011 New Revision: 13338 URL: http://svn.gna.org/viewcvs/relax?rev=13338&view=rev Log: Expanded the build_menu_item() menu method to accept a function to bind to the entry. The method also creates a unique ID for the entry if none is given. Modified: branches/gui_testing/gui/menu.py Modified: branches/gui_testing/gui/menu.py URL: http://svn.gna.org/viewcvs/relax/branches/gui_testing/gui/menu.py?rev=13338&r1=13337&r2=13338&view=diff ============================================================================== --- branches/gui_testing/gui/menu.py (original) +++ branches/gui_testing/gui/menu.py Thu Jun 30 13:29:08 2011 @@ -120,7 +120,7 @@ self.gui.Bind(wx.EVT_MENU_OPEN, self.update_menus) - def build_menu_item(self, menu, id=None, text='', tooltip='', icon=None): + def build_menu_item(self, menu, id=None, text='', tooltip='', icon=None, fn=None): """Construct and return the menu sub-item. @param menu: The menu object to place this entry in. @@ -133,16 +133,26 @@ @type tooltip: str @keyword icon: The bitmap icon path. @type icon: None or str + @keyword fn: The function to bind to the menu entry. + @type fn: class method @return: The initialised wx.MenuItem() instance. @rtype: wx.MenuItem() instance """ + # A new ID if necessary. + if id == None: + id = wx.NewId() + # Initialise the GUI element. element = wx.MenuItem(menu, id, text, tooltip) # Set the icon. if icon: element.SetBitmap(wx.Bitmap(icon)) + + # Bind the menu entry. + if fn: + self.gui.Bind(wx.EVT_MENU, fn, id) # Return the element. return element