"Fossies" - the Fresh Open Source Software Archive

Member "relax-5.0.0/gui/menu.py" (2 Dec 2019, 14125 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-2014,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 """The main relax menu bar."""
   25 
   26 # Python module imports.
   27 import sys
   28 import wx
   29 
   30 # relax module imports.
   31 import dep_check
   32 from graphics import fetch_icon
   33 from gui.components.menu import build_menu_item
   34 from gui.uf_objects import build_uf_menus, Uf_storage; uf_store = Uf_storage()
   35 from status import Status; status = Status()
   36 from user_functions.data import Uf_info; uf_info = Uf_info()
   37 
   38 
   39 # Some IDs for the menu entries.
   40 MENU_FILE_NEW = wx.NewId()
   41 MENU_FILE_CLOSE = wx.NewId()
   42 MENU_FILE_CLOSE_ALL = wx.NewId()
   43 MENU_FILE_CWD = wx.NewId()
   44 MENU_FILE_OPEN = wx.NewId()
   45 MENU_FILE_SAVE = wx.NewId()
   46 MENU_FILE_SAVE_AS = wx.NewId()
   47 MENU_FILE_EXPORT_BMRB = wx.NewId()
   48 MENU_FILE_EXIT = wx.NewId()
   49 MENU_VIEW_CONTROLLER = wx.NewId()
   50 MENU_VIEW_SPIN_VIEW = wx.NewId()
   51 MENU_VIEW_RESULTS = wx.NewId()
   52 MENU_VIEW_PIPE_EDIT = wx.NewId()
   53 MENU_VIEW_PROMPT = wx.NewId()
   54 MENU_TOOLS_FORMAT = wx.NewId()
   55 MENU_TOOLS_TEST_SUITE = wx.NewId()
   56 MENU_TOOLS_TEST_SUITE_ALL = wx.NewId()
   57 MENU_TOOLS_TEST_SUITE_SYS = wx.NewId()
   58 MENU_TOOLS_TEST_SUITE_UNIT = wx.NewId()
   59 MENU_TOOLS_TEST_SUITE_GUI = wx.NewId()
   60 MENU_TOOLS_TEST_SUITE_VERIFICATION = wx.NewId()
   61 MENU_TOOLS_SYS_INFO = wx.NewId()
   62 MENU_HELP_MANUAL = wx.NewId()
   63 MENU_HELP_MAIL = wx.NewId()
   64 MENU_HELP_REFS = wx.NewId()
   65 MENU_HELP_GPL = wx.NewId()
   66 MENU_HELP_ABOUT = wx.NewId()
   67 
   68 
   69 class Menu:
   70     """The menu bar GUI class."""
   71 
   72     def __init__(self, gui):
   73         """Build the menu bar."""
   74 
   75         # Store the args.
   76         self.gui = gui
   77 
   78         # Create the menu bar GUI item.
   79         self.menubar = wx.MenuBar()
   80 
   81         # The 'File' menu entries.
   82         menu = wx.Menu()
   83         build_menu_item(menu, id=MENU_FILE_NEW, text="&New analysis\tCtrl+N", icon=fetch_icon('oxygen.actions.document-new', "16x16"))
   84         build_menu_item(menu, id=MENU_FILE_CLOSE, text="&Close analysis", icon=fetch_icon('oxygen.actions.document-close', "16x16"))
   85         build_menu_item(menu, id=MENU_FILE_CLOSE_ALL, text="&Close all analyses", icon=fetch_icon('oxygen.actions.dialog-close', "16x16"))
   86         menu.AppendSeparator()
   87         build_menu_item(menu, id=MENU_FILE_CWD, text="&Change directory\tCtrl+W", icon=fetch_icon('oxygen.places.folder-favorites', "16x16"))
   88         build_menu_item(menu, id=MENU_FILE_OPEN, text="&Open relax state\tCtrl+O", icon=fetch_icon('oxygen.actions.document-open', "16x16"))
   89         build_menu_item(menu, id=MENU_FILE_SAVE, text="S&ave relax state\tCtrl+S", icon=fetch_icon('oxygen.actions.document-save', "16x16"))
   90         build_menu_item(menu, id=MENU_FILE_SAVE_AS, text="Save as...\tCtrl+Shift+S", icon=fetch_icon('oxygen.actions.document-save-as', "16x16"))
   91         menu.AppendSeparator()
   92         build_menu_item(menu, id=MENU_FILE_EXPORT_BMRB, text="Export for BMRB deposition", icon=fetch_icon('relax.bmrb'))
   93         menu.AppendSeparator()
   94         build_menu_item(menu, id=MENU_FILE_EXIT, text="E&xit\tCtrl+Q", icon=fetch_icon('oxygen.actions.system-shutdown', "16x16"))
   95         self.menubar.Append(menu, "&File")
   96 
   97         # The 'File' menu actions.
   98         self.gui.Bind(wx.EVT_MENU, self.gui.analysis.menu_new, id=MENU_FILE_NEW)
   99         self.gui.Bind(wx.EVT_MENU, self.gui.analysis.menu_close, id=MENU_FILE_CLOSE)
  100         self.gui.Bind(wx.EVT_MENU, self.gui.analysis.menu_close_all, id=MENU_FILE_CLOSE_ALL)
  101         self.gui.Bind(wx.EVT_MENU, self.gui.system_cwd, id=MENU_FILE_CWD)
  102         self.gui.Bind(wx.EVT_MENU, self.gui.state_load, id=MENU_FILE_OPEN)
  103         self.gui.Bind(wx.EVT_MENU, self.gui.action_state_save, id=MENU_FILE_SAVE)
  104         self.gui.Bind(wx.EVT_MENU, self.gui.action_state_save_as, id=MENU_FILE_SAVE_AS)
  105         self.gui.Bind(wx.EVT_MENU, self.gui.action_export_bmrb, id=MENU_FILE_EXPORT_BMRB)
  106         self.gui.Bind(wx.EVT_MENU, self.gui.exit_gui, id=MENU_FILE_EXIT)
  107 
  108         # The 'View' menu entries.
  109         menu = wx.Menu()
  110         build_menu_item(menu, id=MENU_VIEW_CONTROLLER, text="&Controller\tCtrl+Z", icon=fetch_icon('oxygen.apps.preferences-system-performance', "16x16"))
  111         build_menu_item(menu, id=MENU_VIEW_SPIN_VIEW, text="&Spin viewer\tCtrl+T", icon=fetch_icon('relax.spin', "16x16"))
  112         build_menu_item(menu, id=MENU_VIEW_RESULTS, text="&Results viewer\tCtrl+R", icon=fetch_icon('oxygen.actions.view-statistics', "16x16"))
  113         build_menu_item(menu, id=MENU_VIEW_PIPE_EDIT, text="&Data pipe editor\tCtrl+D", icon=fetch_icon('relax.pipe', "16x16"))
  114         build_menu_item(menu, id=MENU_VIEW_PROMPT, text="relax &prompt\tCtrl+P", icon=fetch_icon('oxygen.mimetypes.application-x-executable-script', "16x16"))
  115         self.menubar.Append(menu, "&View")
  116 
  117         # The 'View' actions.
  118         self.gui.Bind(wx.EVT_MENU, self.gui.show_controller, id=MENU_VIEW_CONTROLLER)
  119         self.gui.Bind(wx.EVT_MENU, self.gui.show_prompt, id=MENU_VIEW_PROMPT)
  120         self.gui.Bind(wx.EVT_MENU, self.gui.show_tree, id=MENU_VIEW_SPIN_VIEW)
  121         self.gui.Bind(wx.EVT_MENU, self.gui.show_results_viewer, id=MENU_VIEW_RESULTS)
  122         self.gui.Bind(wx.EVT_MENU, self.gui.show_pipe_editor, id=MENU_VIEW_PIPE_EDIT)
  123 
  124         # The auto generated 'User functions' menu entries.
  125         self.menu_uf_ids = build_uf_menus(parent=self.gui, menubar=self.menubar)
  126 
  127         # The 'Tools' menu entries.
  128         menu = wx.Menu()
  129         build_menu_item(menu, id=MENU_TOOLS_FORMAT, text="&Free file format settings", icon=fetch_icon('oxygen.actions.document-properties', "16x16"))
  130         build_menu_item(menu, id=MENU_TOOLS_SYS_INFO, text="System &information", icon=fetch_icon('oxygen.actions.help-about', "16x16"))
  131 
  132         # The 'Tools->Test suite" sub-menu.
  133         test_suite_item = build_menu_item(menu, id=MENU_TOOLS_TEST_SUITE, text="&Test suite", icon=fetch_icon('oxygen.mimetypes.application-x-desktop', "16x16"), append=False)
  134         sub_menu = wx.Menu()
  135         test_suite_item.SetSubMenu(sub_menu)
  136         build_menu_item(sub_menu, id=MENU_TOOLS_TEST_SUITE_ALL, text="&Full test suite", icon=fetch_icon('oxygen.mimetypes.application-x-desktop', "16x16"))
  137         sub_menu.AppendSeparator()
  138         build_menu_item(sub_menu, id=MENU_TOOLS_TEST_SUITE_SYS, text="&System tests", icon=fetch_icon('oxygen.mimetypes.application-x-desktop', "16x16"))
  139         build_menu_item(sub_menu, id=MENU_TOOLS_TEST_SUITE_UNIT, text="&Unit tests", icon=fetch_icon('oxygen.mimetypes.application-x-desktop', "16x16"))
  140         build_menu_item(sub_menu, id=MENU_TOOLS_TEST_SUITE_GUI, text="&GUI tests", icon=fetch_icon('oxygen.mimetypes.application-x-desktop', "16x16"))
  141         build_menu_item(sub_menu, id=MENU_TOOLS_TEST_SUITE_VERIFICATION, text="&Verification tests", icon=fetch_icon('oxygen.mimetypes.application-x-desktop', "16x16"))
  142         if dep_check.wx_classic:
  143             menu.AppendItem(test_suite_item)
  144         else:
  145             menu.Append(test_suite_item)
  146         self.menubar.Append(menu, "&Tools")
  147 
  148         # The 'Tools' menu actions.
  149         self.gui.Bind(wx.EVT_MENU, self.gui.free_file_format_settings, id=MENU_TOOLS_FORMAT)
  150         self.gui.Bind(wx.EVT_MENU, self._sys_info, id=MENU_TOOLS_SYS_INFO)
  151         self.gui.Bind(wx.EVT_MENU, self.gui.run_test_suite, id=MENU_TOOLS_TEST_SUITE_ALL)
  152         self.gui.Bind(wx.EVT_MENU, self.gui.run_test_suite_sys, id=MENU_TOOLS_TEST_SUITE_SYS)
  153         self.gui.Bind(wx.EVT_MENU, self.gui.run_test_suite_unit, id=MENU_TOOLS_TEST_SUITE_UNIT)
  154         self.gui.Bind(wx.EVT_MENU, self.gui.run_test_suite_gui, id=MENU_TOOLS_TEST_SUITE_GUI)
  155         self.gui.Bind(wx.EVT_MENU, self.gui.run_test_suite_verification, id=MENU_TOOLS_TEST_SUITE_VERIFICATION)
  156 
  157         # The 'Help' menu entries.
  158         menu = wx.Menu()
  159         build_menu_item(menu, id=MENU_HELP_MANUAL, text="relax user &manual\tF1", icon=fetch_icon('oxygen.mimetypes.application-pdf', "16x16"))
  160         menu.AppendSeparator()
  161         build_menu_item(menu, id=MENU_HELP_MAIL, text="Mailing list &contact (relax-users@gna.org)", icon=fetch_icon('oxygen.actions.mail-mark-unread-new', "16x16"))
  162         build_menu_item(menu, id=MENU_HELP_REFS, text="&References", icon=fetch_icon('oxygen.actions.flag-blue', "16x16"))
  163         menu.AppendSeparator()
  164         build_menu_item(menu, id=MENU_HELP_GPL, text="&Licence", icon=fetch_icon('relax.gnu-head-mini', "16x16"))
  165         menu.AppendSeparator()
  166         build_menu_item(menu, id=MENU_HELP_ABOUT, text="About rela&x", icon=fetch_icon("relax.relax"))
  167         self.menubar.Append(menu, "&Help")
  168 
  169         # The 'Help' menu actions.
  170         self.gui.Bind(wx.EVT_MENU, self.gui.relax_manual, id=MENU_HELP_MANUAL)
  171         self.gui.Bind(wx.EVT_MENU, self.gui.contact_relax, id=MENU_HELP_MAIL)
  172         self.gui.Bind(wx.EVT_MENU, self.gui.references, id=MENU_HELP_REFS)
  173         self.gui.Bind(wx.EVT_MENU, self._licence, id=MENU_HELP_GPL)
  174         self.gui.Bind(wx.EVT_MENU, self.gui.about_relax, id=MENU_HELP_ABOUT)
  175 
  176         # Add the menu bar GUI item to the main frame.
  177         if status.show_gui:
  178             self.gui.SetMenuBar(self.menubar)
  179 
  180         # Menu update.
  181         self.gui.Bind(wx.EVT_MENU_OPEN, self.update_menus)
  182 
  183 
  184     def _create_menu(self, menu, entries):
  185         """Build the menu."""
  186 
  187         # Loop over the menu entries.
  188         for item in entries:
  189             # Build the menu entry.
  190             menu_item = build_menu_item(menu, id=item[0], text=item[1], icon=item[2], append=False)
  191 
  192             # A sub-menu.
  193             if len(item[4]):
  194                 # The sub-menu.
  195                 sub_menu = wx.Menu()
  196 
  197                 # Loop over the sub-menus.
  198                 for sub_item in item[4]:
  199                     # Build the menu entry.
  200                     sub_menu_item = build_menu_item(sub_menu, id=sub_item[0], text=sub_item[1], icon=sub_item[2])
  201 
  202                     # The menu actions.
  203                     self.gui.Bind(wx.EVT_MENU, sub_item[3], id=sub_item[0])
  204 
  205                 # Append the sub-menu.
  206                 menu_item.SetSubMenu(sub_menu)
  207 
  208             # A normal menu item.
  209             else:
  210                 # The menu actions.
  211                 self.gui.Bind(wx.EVT_MENU, item[3], id=item[0])
  212 
  213             # Append the menu item.
  214             if dep_check.wx_classic:
  215                 menu.AppendItem(menu_item)
  216             else:
  217                 menu.Append(menu_item)
  218 
  219 
  220     def _licence(self, event):
  221         """Show the GPL licence.
  222 
  223         @param event:   The wx event.
  224         @type event:    wx event
  225         """
  226 
  227         # Print the GPL to STDOUT.
  228         file = open('docs/COPYING')
  229         for line in file.readlines():
  230             sys.stdout.write(line)
  231         sys.stdout.flush()
  232 
  233         # Show the relax controller.
  234         self.gui.show_controller(event)
  235 
  236 
  237     def _sys_info(self, event):
  238         """Show the full system information using the sys_info user function.
  239 
  240         @param event:   The wx event.
  241         @type event:    wx event
  242         """
  243 
  244         # Launch the user function.
  245         uf_store['system.sys_info']()
  246 
  247 
  248     def update_menus(self, event):
  249         """Update the menus dependent on the relax state.
  250 
  251         @param event:   The wx event.
  252         @type event:    wx event
  253         """
  254 
  255         # The status object.
  256         status = Status()
  257 
  258         # Flag for enabling or disabling the menu entries.
  259         enable = False
  260         if not status.exec_lock.locked():
  261             enable = True
  262 
  263         # The file menu entries to enable or disable.
  264         self.menubar.Enable(MENU_FILE_NEW, enable)
  265         self.menubar.Enable(MENU_FILE_CLOSE, enable)
  266         self.menubar.Enable(MENU_FILE_CLOSE_ALL, enable)
  267         self.menubar.Enable(MENU_FILE_CWD, enable)
  268         self.menubar.Enable(MENU_FILE_OPEN, enable)
  269         self.menubar.Enable(MENU_FILE_SAVE, enable)
  270         self.menubar.Enable(MENU_FILE_SAVE_AS, enable)
  271         self.menubar.Enable(MENU_FILE_EXPORT_BMRB, enable)
  272         self.menubar.Enable(MENU_TOOLS_FORMAT, enable)
  273         self.menubar.Enable(MENU_TOOLS_TEST_SUITE, enable)
  274         self.menubar.Enable(MENU_TOOLS_SYS_INFO, enable)
  275 
  276         # The view menu entries.
  277         self.menubar.Enable(MENU_VIEW_PROMPT, enable)
  278 
  279         # Loop over the user function menus.
  280         for id in self.menu_uf_ids:
  281             # Loop over the user function menu items.
  282             menu = self.menubar.GetMenu(id)
  283             for item in menu.GetMenuItems():
  284                 # Enable/disable.
  285                 item.Enable(enable)
  286 
  287                 # Sub-menu.
  288                 submenu = item.GetSubMenu()
  289                 if submenu:
  290                     for subitem in submenu.GetMenuItems():
  291                         subitem.Enable(enable)