Skip to content
Snippets Groups Projects
Unverified Commit 47a9595e authored by Hahn, Steven's avatar Hahn, Steven Committed by GitHub
Browse files

Merge pull request #23761 from mantidproject/workbench_custom_interfaces

Add custom interfaces to workbench menus
parents 428a8aae 728f7909
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,7 @@ requirements.check_qt()
# -----------------------------------------------------------------------------
# Qt
# -----------------------------------------------------------------------------
from qtpy.QtCore import (QEventLoop, Qt, QCoreApplication, QSettings, QPoint, QSize) # noqa
from qtpy.QtCore import (QEventLoop, Qt, QCoreApplication, QPoint, QSize) # noqa
from qtpy.QtGui import (QColor, QPixmap) # noqa
from qtpy.QtWidgets import (QApplication, QDesktopWidget, QFileDialog,
QMainWindow, QSplashScreen) # noqa
......@@ -131,6 +131,7 @@ class MainWindow(QMainWindow):
self.editor_menu = None
self.view_menu = None
self.view_menu_actions = None
self.interfaces_menu = None
# Allow splash screen text to be overridden in set_splash
self.splash = SPLASH
......@@ -200,6 +201,7 @@ class MainWindow(QMainWindow):
self.file_menu = self.menuBar().addMenu("&File")
self.editor_menu = self.menuBar().addMenu("&Editor")
self.view_menu = self.menuBar().addMenu("&View")
self.interfaces_menu = self.menuBar().addMenu('&Interfaces')
def create_actions(self):
# --- general application menu options --
......@@ -248,6 +250,49 @@ class MainWindow(QMainWindow):
add_actions(self.file_menu, self.file_menu_actions)
add_actions(self.view_menu, self.view_menu_actions)
def launchCustomGUI(self, name):
try:
importlib.import_module(name)
except ImportError:
from mantid.kernel import logger
logger.error(str('Failed to load {} interface'.format(name))) # TODO logger should accept unicode
raise
def populateAfterMantidImport(self):
from mantid.kernel import ConfigService, logger
# TODO ConfigService should accept unicode strings
interface_dir = ConfigService[str('mantidqt.python_interfaces_directory')]
items = ConfigService[str('mantidqt.python_interfaces')].split()
# list of custom interfaces that have been made qt4/qt5 compatible
# TODO need to make *anything* compatible
GUI_WHITELIST = []
# detect the python interfaces
interfaces = {}
for item in items:
key,scriptname = item.split('/')
if not os.path.exists(os.path.join(interface_dir, scriptname)):
logger.warning('Failed to find script "{}" in "{}"'.format(scriptname, interface_dir))
continue
if scriptname not in GUI_WHITELIST:
continue
temp = interfaces.get(key, [])
temp.append(scriptname)
interfaces[key] = temp
# add the interfaces to the menu
keys = list(interfaces.keys())
keys.sort()
for key in keys:
submenu = self.interfaces_menu.addMenu(key)
names = interfaces[key]
names.sort()
for name in names:
action = submenu.addAction(name.replace('.py', '').replace('_', ' '))
script = name.replace('.py', '')
action.triggered.connect(lambda checked, script=script:self.launchCustomGUI(script))
def add_dockwidget(self, plugin):
"""Create a dockwidget around a plugin and add the dock to window"""
dockwidget, location = plugin.create_dockwidget()
......@@ -453,6 +498,7 @@ def start_workbench(app, command_line_options):
# start mantid
main_window.set_splash('Preloading mantid')
importlib.import_module('mantid')
main_window.populateAfterMantidImport()
main_window.show()
if main_window.splash:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment