"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/gui/components/menu.py" (2 Dec 2019, 3211 Bytes) of package /linux/privat/relax-5.0.0.src.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "menu.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 4.1.3_vs_5.0.0.

    1 ###############################################################################
    2 #                                                                             #
    3 # Copyright (C) 2009-2010 Michael Bieri                                       #
    4 # Copyright (C) 2009-2011,2019 Edward d'Auvergne                              #
    5 #                                                                             #
    6 # This file is part of the program relax (http://www.nmr-relax.com).          #
    7 #                                                                             #
    8 # This program is free software: you can redistribute it and/or modify        #
    9 # it under the terms of the GNU General Public License as published by        #
   10 # the Free Software Foundation, either version 3 of the License, or           #
   11 # (at your option) any later version.                                         #
   12 #                                                                             #
   13 # This program is distributed in the hope that it will be useful,             #
   14 # but WITHOUT ANY WARRANTY; without even the implied warranty of              #
   15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
   16 # GNU General Public License for more details.                                #
   17 #                                                                             #
   18 # You should have received a copy of the GNU General Public License           #
   19 # along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
   20 #                                                                             #
   21 ###############################################################################
   22 
   23 # Module docstring.
   24 """Module for the main relax menu bar."""
   25 
   26 # Python module imports.
   27 import wx
   28 
   29 # relax module imports.
   30 import dep_check
   31 
   32 
   33 def build_menu_item(menu, parent=None, id=-1, text='', tooltip='', icon=None, fn=None, append=True):
   34     """Construct and return the menu sub-item.
   35 
   36     @param menu:        The menu object to place this entry in.
   37     @type menu:         wx.Menu instance
   38     @keyword id:        The element identification number.
   39     @type id:           int
   40     @keyword text:      The text for the menu entry.
   41     @type text:         None or str
   42     @keyword tooltip:   A tool tip.
   43     @type tooltip:      str
   44     @keyword icon:      The bitmap icon path.
   45     @type icon:         None or str
   46     @keyword fn:        The function to bind to the menu entry.
   47     @type fn:           class method
   48     @keyword append:    A flag which if true will cause the element to be appended to the given menu.
   49     @type append:       bool
   50     @return:            The initialised wx.MenuItem() instance.
   51     @rtype:             wx.MenuItem() instance
   52     """
   53 
   54     # Initialise the GUI element.
   55     element = wx.MenuItem(menu, id, text, tooltip)
   56 
   57     # Set the icon.
   58     if icon:
   59         element.SetBitmap(wx.Bitmap(icon))
   60 
   61     # Bind the menu entry.
   62     if fn and parent:
   63         parent.Bind(wx.EVT_MENU, fn, id=id)
   64 
   65     # Append the item.
   66     if append:
   67         if dep_check.wx_classic:
   68              menu.AppendItem(element)
   69         else:
   70              menu.Append(element)
   71 
   72     # Return the element.
   73     return element