diff --git a/qt/applications/workbench/workbench/app/mainwindow.py b/qt/applications/workbench/workbench/app/mainwindow.py index afe3adca247db12f7743ee9d8cc8b504e9ba31e6..d95ca24403a043fbe33aa4ad76d539851720c5f6 100644 --- a/qt/applications/workbench/workbench/app/mainwindow.py +++ b/qt/applications/workbench/workbench/app/mainwindow.py @@ -43,7 +43,7 @@ requirements.check_qt() from qtpy.QtCore import (QByteArray, QCoreApplication, QEventLoop, QPoint, QSize, Qt) # noqa from qtpy.QtGui import (QColor, QPixmap) # noqa -from qtpy.QtWidgets import (QApplication, QDockWidget, QMainWindow, +from qtpy.QtWidgets import (QApplication, QDockWidget, QMainWindow, QMenu, QSplashScreen) # noqa from mantidqt.utils.qt import plugins, widget_updates_disabled # noqa @@ -103,7 +103,7 @@ from workbench.external.mantid import prepare_mantid_env # noqa class MainWindow(QMainWindow): - DOCKOPTIONS = QMainWindow.AllowTabbedDocks|QMainWindow.AllowNestedDocks + DOCKOPTIONS = QMainWindow.AllowTabbedDocks | QMainWindow.AllowNestedDocks def __init__(self): QMainWindow.__init__(self) @@ -125,6 +125,10 @@ class MainWindow(QMainWindow): # Menus self.file_menu = None self.file_menu_actions = None + self.editors_menu = None + self.editors_menu_actions = None + self.editors_execute_menu = None + self.editors_execute_menu_actions = None # Allow splash screen text to be overridden in set_splash self.splash = SPLASH @@ -149,9 +153,9 @@ class MainWindow(QMainWindow): self.ipythonconsole.register_plugin() self.set_splash("Loading code editing widget") - from workbench.plugins.codeeditor import MultiFileEditor + from workbench.plugins.editor import MultiFileEditor self.editor = MultiFileEditor(self) - self.editor.register_plugin() + self.editor.register_plugin(self.editors_menu) self.setup_layout() @@ -165,13 +169,17 @@ class MainWindow(QMainWindow): def create_menus(self): self.file_menu = self.menuBar().addMenu("&File") + self.editors_menu = self.menuBar().addMenu("&Editors") def create_actions(self): + # --- general application menu options -- + # file menu action_quit = create_action(self, "&Quit", on_triggered=self.close, shortcut="Ctrl+Q", shortcut_context=Qt.ApplicationShortcut) self.file_menu_actions = [action_quit] + def populate_menus(self): # Link to menus add_actions(self.file_menu, self.file_menu_actions) diff --git a/qt/applications/workbench/workbench/plugins/base.py b/qt/applications/workbench/workbench/plugins/base.py index b46f91359dc90b84b5f9956f71421c40128b8dab..21a452ecc62cc0a16c915666e393713bfbc0f1bd 100644 --- a/qt/applications/workbench/workbench/plugins/base.py +++ b/qt/applications/workbench/workbench/plugins/base.py @@ -37,7 +37,11 @@ class PluginWidget(QWidget): # ----------------- Plugin API -------------------- - def register_plugin(self): + def register_plugin(self, menu=None): + """Called by the parent widget/window and should + perform any setup required to use the plugin. + Supply an optional menu to fill with actions + """ raise NotImplementedError() def get_plugin_title(self): diff --git a/qt/applications/workbench/workbench/plugins/codeeditor.py b/qt/applications/workbench/workbench/plugins/editor.py similarity index 68% rename from qt/applications/workbench/workbench/plugins/codeeditor.py rename to qt/applications/workbench/workbench/plugins/editor.py index 070389867e0baaa13076cc1fe859256f19b05c94..a4f6ecee57126dbcb77d2851a73ce779e0c90959 100644 --- a/qt/applications/workbench/workbench/plugins/codeeditor.py +++ b/qt/applications/workbench/workbench/plugins/editor.py @@ -19,7 +19,8 @@ from __future__ import (absolute_import, unicode_literals) # system imports # third-party library imports -from mantidqt.widgets.codeeditor import MultiFileCodeEditor +from mantidqt.utils.qt import add_actions, create_action +from mantidqt.widgets.codeeditor.multifileinterpreter import MultiPythonFileInterpreter from qtpy.QtWidgets import QVBoxLayout # local package imports @@ -33,16 +34,27 @@ class MultiFileEditor(PluginWidget): super(MultiFileEditor, self).__init__(parent) # layout - self.editors = MultiFileCodeEditor(self) + self.editors = MultiPythonFileInterpreter(self) layout = QVBoxLayout() layout.addWidget(self.editors) layout.setContentsMargins(0, 0, 0, 0) self.setLayout(layout) -# ----------------- Plugin API -------------------- + # attributes + self.run_action = create_action(self, "Run", + on_triggered=self.execute_current) + self.editor_actions = [self.run_action] - def register_plugin(self): + # ----------- Plugin API -------------------- + + def register_plugin(self, menu=None): self.main.add_dockwidget(self) + add_actions(menu, self.editor_actions) def get_plugin_title(self): return "Editor" + + # ----------- Plugin behaviour -------------- + + def execute_current(self): + self.editors.execute_current() diff --git a/qt/applications/workbench/workbench/plugins/jupyterconsole.py b/qt/applications/workbench/workbench/plugins/jupyterconsole.py index fa4a448c63c9a62ecf010f8f2ce0228154c59d48..729bd1f73cf6d69dc67a7be0679a2cd04d7c0cf5 100644 --- a/qt/applications/workbench/workbench/plugins/jupyterconsole.py +++ b/qt/applications/workbench/workbench/plugins/jupyterconsole.py @@ -40,7 +40,7 @@ class JupyterConsole(PluginWidget): # ----------------- Plugin API -------------------- - def register_plugin(self): + def register_plugin(self, menu=None): self.main.add_dockwidget(self) def get_plugin_title(self): diff --git a/qt/applications/workbench/workbench/plugins/logmessagedisplay.py b/qt/applications/workbench/workbench/plugins/logmessagedisplay.py index 9b5cfab8448a8fb12c363db8fb46f1b10f92b0d5..86e3363304e207e3a295981c90beeaea08820357 100644 --- a/qt/applications/workbench/workbench/plugins/logmessagedisplay.py +++ b/qt/applications/workbench/workbench/plugins/logmessagedisplay.py @@ -40,6 +40,6 @@ class LogMessageDisplay(PluginWidget): def get_plugin_title(self): return "Messages" - def register_plugin(self): + def register_plugin(self, menu=None): self.display.attachLoggingChannel() self.main.add_dockwidget(self)