diff --git a/qt/applications/workbench/workbench/app/mainwindow.py b/qt/applications/workbench/workbench/app/mainwindow.py index d95ca24403a043fbe33aa4ad76d539851720c5f6..48e1364dc4a5dcc3d8db1d623259256662a7f99e 100644 --- a/qt/applications/workbench/workbench/app/mainwindow.py +++ b/qt/applications/workbench/workbench/app/mainwindow.py @@ -179,7 +179,6 @@ class MainWindow(QMainWindow): 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/editor.py b/qt/applications/workbench/workbench/plugins/editor.py index a4f6ecee57126dbcb77d2851a73ce779e0c90959..959009584df15e23b978167c649b2c97fcc8916c 100644 --- a/qt/applications/workbench/workbench/plugins/editor.py +++ b/qt/applications/workbench/workbench/plugins/editor.py @@ -21,12 +21,23 @@ from __future__ import (absolute_import, unicode_literals) # third-party library imports from mantidqt.utils.qt import add_actions, create_action from mantidqt.widgets.codeeditor.multifileinterpreter import MultiPythonFileInterpreter +from qtpy.QtCore import Qt from qtpy.QtWidgets import QVBoxLayout # local package imports from workbench.plugins.base import PluginWidget +# Initial content +DEFAULT_CONTENT = """# The following line helps with future compatibility with Python 3 +# print must now be used as a function, e.g print('Hello','World') +from __future__ import (absolute_import, division, print_function, unicode_literals) + +# Import all mantid algorithms +from mantid.simpleapi import * +""" + + class MultiFileEditor(PluginWidget): """Provides a tab widget for editing multiple files""" @@ -34,7 +45,8 @@ class MultiFileEditor(PluginWidget): super(MultiFileEditor, self).__init__(parent) # layout - self.editors = MultiPythonFileInterpreter(self) + self.editors = MultiPythonFileInterpreter(default_content=DEFAULT_CONTENT, + parent=self) layout = QVBoxLayout() layout.addWidget(self.editors) layout.setContentsMargins(0, 0, 0, 0) @@ -42,7 +54,9 @@ class MultiFileEditor(PluginWidget): # attributes self.run_action = create_action(self, "Run", - on_triggered=self.execute_current) + on_triggered=self.execute_current, + shortcut="Ctrl+Return", + shortcut_context=Qt.ApplicationShortcut) self.editor_actions = [self.run_action] # ----------- Plugin API -------------------- diff --git a/qt/python/mantidqt/widgets/codeeditor/interpreter.py b/qt/python/mantidqt/widgets/codeeditor/interpreter.py index 3a1e65f99b861c932578a15c53004d3ae2d600fc..858a66db0139282f196a1e6dcef9ec31dd5a670e 100644 --- a/qt/python/mantidqt/widgets/codeeditor/interpreter.py +++ b/qt/python/mantidqt/widgets/codeeditor/interpreter.py @@ -31,10 +31,9 @@ RUNNING_STATUS_MSG = "Status: Running" # Editor colors CURRENTLINE_BKGD = QColor(247, 236, 248) - class PythonFileInterpreter(QWidget): - def __init__(self, parent=None): + def __init__(self, default_content=None, parent=None): """ :param parent: A parent QWidget """ @@ -49,7 +48,7 @@ class PythonFileInterpreter(QWidget): self.setLayout(layout) layout.setContentsMargins(0, 0, 0, 0) - self._setup_editor() + self._setup_editor(default_content) # presenter self._presenter = PythonFileInterpreterPresenter(self, PythonCodeExecution()) @@ -63,7 +62,7 @@ class PythonFileInterpreter(QWidget): def set_status_message(self, msg): self.status.showMessage(msg) - def _setup_editor(self): + def _setup_editor(self, default_content): editor = self.editor # use fixed with font font = QFont("Courier New") @@ -79,6 +78,10 @@ class PythonFileInterpreter(QWidget): font_metrics = QFontMetrics(font) editor.setMarginWidth(1, font_metrics.averageCharWidth()*3 + 12) + # fill with content if supplied + if default_content is not None: + editor.setText(default_content) + class PythonFileInterpreterPresenter(QObject): """Presenter part of MVP to control actions on the editor""" diff --git a/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py b/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py index c72f5f9d2203f8f3f3c6402f0457cc749dcfc937..4e9ee97534f6740de0c7e58484122af36991729a 100644 --- a/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py +++ b/qt/python/mantidqt/widgets/codeeditor/multifileinterpreter.py @@ -26,9 +26,12 @@ from mantidqt.widgets.codeeditor.interpreter import PythonFileInterpreter class MultiPythonFileInterpreter(QWidget): """Provides a tabbed widget for editing multiple files""" - def __init__(self, parent=None): + def __init__(self, default_content=None, parent=None): super(MultiPythonFileInterpreter, self).__init__(parent) + # attributes + self.default_content = default_content + # layout self._editors = QTabWidget(self) self._editors.setMovable(True) @@ -52,6 +55,7 @@ class MultiPythonFileInterpreter(QWidget): def append_new_editor(self): title = "New" - self._editors.addTab(PythonFileInterpreter(self._editors), + self._editors.addTab(PythonFileInterpreter(self.default_content, + parent=None), title)