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

Renaming for clearer intent of classes

Refs #21251
parent 86b416ef
No related branches found
No related tags found
No related merge requests found
......@@ -42,10 +42,10 @@ if ( ENABLE_WORKBENCH )
mantidqt/utils/test/test_qt_utils.py
mantidqt/widgets/codeeditor/test_codeeditor.py
mantidqt/widgets/codeeditor/test_executablecodeeditor.py
mantidqt/widgets/codeeditor/test_execution.py
mantidqt/widgets/codeeditor/test_multifileeditor.py
mantidqt/widgets/codeeditor/test/test_codeeditor.py
mantidqt/widgets/codeeditor/test/test_interpreter.py
mantidqt/widgets/codeeditor/test/test_execution.py
mantidqt/widgets/codeeditor/test/test_multifileeditor.py
mantidqt/widgets/test/test_algorithmselector.py
mantidqt/widgets/test/test_jupyterconsole.py
......
......@@ -24,103 +24,5 @@ from qtpy.QtWidgets import QStatusBar, QTabWidget, QVBoxLayout, QWidget
from mantidqt.utils.qt import import_qtlib
from .execution import PythonCodeExecution
DEFAULT_EDITOR_LANGUAGE = "Python"
EXECUTION_CLS = PythonCodeExecution
IDLE_STATUS_MSG = "Status: Idle"
RUNNING_STATUS_MSG = "Status: Running"
# Import single-file editor from C++ wrapping
CodeEditor = import_qtlib('_widgetscore', 'mantidqt.widgets', 'ScriptEditor')
class ExecutableCodeEditor(QWidget):
def __init__(self, language=DEFAULT_EDITOR_LANGUAGE, parent=None):
"""
:param language: Language for syntax highlighting
:param user_globals: Dictionary for global context of execution.
:param user_locals: Dictionary for local context of execution
:param parent: A parent QWidget
"""
super(ExecutableCodeEditor, self).__init__(parent)
# layout
self.editor = CodeEditor(language, self)
self.status = QStatusBar(self)
layout = QVBoxLayout()
layout.addWidget(self.editor)
layout.addWidget(self.status)
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
# presenter
self._presenter = ExecutableCodeEditorPresenter(self, PythonCodeExecution())
def execute_all_async(self):
self._presenter.req_execute_all_async()
def set_editor_readonly(self, ro):
self.editor.setReadOnly(ro)
def set_status_message(self, msg):
self.status.showMessage(msg)
class ExecutableCodeEditorPresenter(QObject):
"""Presenter part of MVP to control actions on the editor"""
def __init__(self, view, model):
super(ExecutableCodeEditorPresenter, self).__init__()
self.view = view
self.model = model
# connect signals
self.model.sig_exec_success.connect(self.on_exec_success)
self.model.sig_exec_error.connect(self.on_exec_error)
# starts idle
self.view.set_status_message(IDLE_STATUS_MSG)
def req_execute_all_async(self):
text = self.view.editor.text()
if not text:
return
self.view.set_editor_readonly(True)
self.view.set_status_message(RUNNING_STATUS_MSG)
return self.model.execute_async(text)
def on_exec_success(self):
self.view.set_status_message(IDLE_STATUS_MSG)
def on_exec_error(self):
self.view.set_status_message(IDLE_STATUS_MSG)
class MultiFileCodeEditor(QWidget):
"""Provides a tabbed widget for editing multiple files"""
def __init__(self, parent=None):
super(MultiFileCodeEditor, self).__init__(parent)
# layout
self.editors = QTabWidget(self)
self.editors.setMovable(True)
layout = QVBoxLayout()
layout.addWidget(self.editors)
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
# add a single editor by default
self.append_new_editor(DEFAULT_EDITOR_LANGUAGE)
@property
def editor_count(self):
return self.editors.count()
def append_new_editor(self, language):
title = "New"
self.editors.addTab(ExecutableCodeEditor(language, self.editors), title)
# This file is part of the mantidqt package
#
# Copyright (C) 2017 mantidproject
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, unicode_literals)
# 3rd party imports
from qtpy.QtCore import QObject
from qtpy.QtWidgets import QStatusBar, QVBoxLayout, QWidget
# local imports
from mantidqt.widgets.codeeditor.editor import CodeEditor
from mantidqt.widgets.codeeditor.execution import PythonCodeExecution
IDLE_STATUS_MSG = "Status: Idle"
RUNNING_STATUS_MSG = "Status: Running"
class PythonFileInterpreter(QWidget):
def __init__(self, parent=None):
"""
:param parent: A parent QWidget
"""
super(PythonFileInterpreter, self).__init__(parent)
# layout
self.editor = CodeEditor("Python", self)
self.status = QStatusBar(self)
layout = QVBoxLayout()
layout.addWidget(self.editor)
layout.addWidget(self.status)
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
# presenter
self._presenter = PythonFileInterpreterPresenter(self, PythonCodeExecution())
def execute_all_async(self):
self._presenter.req_execute_all_async()
def set_editor_readonly(self, ro):
self.editor.setReadOnly(ro)
def set_status_message(self, msg):
self.status.showMessage(msg)
class PythonFileInterpreterPresenter(QObject):
"""Presenter part of MVP to control actions on the editor"""
def __init__(self, view, model):
super(PythonFileInterpreterPresenter, self).__init__()
self.view = view
self.model = model
# connect signals
self.model.sig_exec_success.connect(self.on_exec_success)
self.model.sig_exec_error.connect(self.on_exec_error)
# starts idle
self.view.set_status_message(IDLE_STATUS_MSG)
def req_execute_all_async(self):
text = self.view.editor.text()
if not text:
return
self.view.set_editor_readonly(True)
self.view.set_status_message(RUNNING_STATUS_MSG)
return self.model.execute_async(text)
def on_exec_success(self):
self.view.set_status_message(IDLE_STATUS_MSG)
def on_exec_error(self):
self.view.set_status_message(IDLE_STATUS_MSG)
# This file is part of the mantidqt package
#
# Copyright (C) 2017 mantidproject
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, unicode_literals)
# 3rd party imports
from qtpy.QtWidgets import QTabWidget, QVBoxLayout, QWidget
# local imports
from mantidqt.widgets.codeeditor.interpreter import PythonFileInterpreter
class MultiPythonFileInterpreter(QWidget):
"""Provides a tabbed widget for editing multiple files"""
def __init__(self, parent=None):
super(MultiPythonFileInterpreter, self).__init__(parent)
# layout
self.editors = QTabWidget(self)
self.editors.setMovable(True)
layout = QVBoxLayout()
layout.addWidget(self.editors)
self.setLayout(layout)
layout.setContentsMargins(0, 0, 0, 0)
# add a single editor by default
self.append_new_editor()
@property
def editor_count(self):
return self.editors.count()
def append_new_editor(self):
title = "New"
self.editors.addTab(PythonFileInterpreter(self.editors), title)
......@@ -23,7 +23,7 @@ import unittest
import six
# local imports
from mantidqt.widgets.codeeditor.editor import ExecutableCodeEditor
from mantidqt.widgets.codeeditor.interpreter import PythonFileInterpreter
from mantidqt.utils.qt.testing import requires_qapp
if six.PY2:
......@@ -33,14 +33,14 @@ else:
@requires_qapp
class ExecutableCodeEditorTest(unittest.TestCase):
class PythonFileInterpreterTest(unittest.TestCase):
def test_construction(self):
w = ExecutableCodeEditor()
w = PythonFileInterpreter()
self.assertTrue("Status: Idle", w.status.currentMessage())
def test_empty_code_does_nothing_on_exec(self):
w = ExecutableCodeEditor()
w = PythonFileInterpreter()
w._presenter.model.execute_async = mock.MagicMock()
w.execute_all_async()
......@@ -49,7 +49,7 @@ class ExecutableCodeEditorTest(unittest.TestCase):
self.assertTrue("Status: Idle", w.status.currentMessage())
def test_successful_execution(self):
w = ExecutableCodeEditor()
w = PythonFileInterpreter()
w.editor.setText("x = 1 + 2")
w.execute_all_async()
self.assertTrue("Status: Idle", w.status.currentMessage())
......
......@@ -22,17 +22,17 @@ import unittest
# third-party library imports
# local imports
from mantidqt.widgets.codeeditor.editor import MultiFileCodeEditor
from mantidqt.utils.qt.testing import requires_qapp
from mantidqt.widgets.codeeditor.multifileinterpreter import MultiPythonFileInterpreter
@requires_qapp
class MultiFileCodeEditorTest(unittest.TestCase):
class MultiPythonFileInterpreterTest(unittest.TestCase):
# Success tests
def test_default_contains_single_tab(self):
widget = MultiFileCodeEditor()
widget = MultiPythonFileInterpreter()
self.assertEqual(1, widget.editor_count)
......
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