Skip to content
Snippets Groups Projects
Commit e56d79a0 authored by Martyn Gigg's avatar Martyn Gigg
Browse files

Add default content to each new file.

Refs #21251
parent 0b763ee7
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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 --------------------
......
......@@ -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"""
......
......@@ -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)
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