From fbea97bb03383d382958ef7e1b55f5de0ee4dcc3 Mon Sep 17 00:00:00 2001 From: Martyn Gigg <martyn.gigg@gmail.com> Date: Thu, 4 Jan 2018 16:17:48 +0000 Subject: [PATCH] Add IPython console plugin to workbench Also fix minor style issues is messagedisplay. Refs #21251 --- .../workbench/workbench/plugins/base.py | 13 ++++- .../workbench/plugins/ipythonconsole.py | 47 +++++++++++++++++++ .../workbench/plugins/logmessagedisplay.py | 6 ++- 3 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 qt/applications/workbench/workbench/plugins/ipythonconsole.py diff --git a/qt/applications/workbench/workbench/plugins/base.py b/qt/applications/workbench/workbench/plugins/base.py index fb967b5f24a..5fb3d29f4f1 100644 --- a/qt/applications/workbench/workbench/plugins/base.py +++ b/qt/applications/workbench/workbench/plugins/base.py @@ -18,7 +18,7 @@ from __future__ import absolute_import from qtpy.QtCore import Qt -from qtpy.QtWidgets import QDockWidget, QWidget +from qtpy.QtWidgets import QDockWidget, QMainWindow, QWidget class PluginWidget(QWidget): @@ -29,7 +29,9 @@ class PluginWidget(QWidget): def __init__(self, main_window): QWidget.__init__(self, main_window) + assert isinstance(main_window, QMainWindow) + self.dockwidget = None self.main = main_window # ----------------- Plugin API -------------------- @@ -50,4 +52,13 @@ class PluginWidget(QWidget): dock.setAllowedAreas(self.ALLOWED_AREAS) dock.setFeatures(self.FEATURES) dock.setWidget(self) + self.dockwidget = dock return dock, self.LOCATION + + def toggle_view(self, checked): + """Toggle view visible or hidden""" + if checked: + self.dockwidget.show() + self.dockwidget.raise_() + else: + self.dockwidget.hide() diff --git a/qt/applications/workbench/workbench/plugins/ipythonconsole.py b/qt/applications/workbench/workbench/plugins/ipythonconsole.py new file mode 100644 index 00000000000..ee8957586c7 --- /dev/null +++ b/qt/applications/workbench/workbench/plugins/ipythonconsole.py @@ -0,0 +1,47 @@ +# This file is part of the mantid workbench. +# +# 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) + +# system imports + +# third-party library imports +from mantidqt.widgets.ipythonconsole import InProcessIPythonConsole +from qtpy.QtWidgets import QVBoxLayout + +# local package imports +from workbench.plugins.base import PluginWidget + + +class IPythonConsole(PluginWidget): + """Provides an in-process IPython console""" + + def __init__(self, parent): + super(IPythonConsole, self).__init__(parent) + + # layout + self.console = InProcessIPythonConsole(self) + layout = QVBoxLayout() + layout.addWidget(self.console) + self.setLayout(layout) + +# ----------------- Plugin API -------------------- + + def register_plugin(self): + self.main.add_dockwidget(self) + + def get_plugin_title(self): + return "IPython" diff --git a/qt/applications/workbench/workbench/plugins/logmessagedisplay.py b/qt/applications/workbench/workbench/plugins/logmessagedisplay.py index ac830092aba..9b5cfab8448 100644 --- a/qt/applications/workbench/workbench/plugins/logmessagedisplay.py +++ b/qt/applications/workbench/workbench/plugins/logmessagedisplay.py @@ -14,18 +14,20 @@ # # 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 +from __future__ import (absolute_import, unicode_literals) +# 3rdparty imports from mantidqt.widgets.messagedisplay import MessageDisplay from qtpy.QtWidgets import QHBoxLayout +# local imports from workbench.plugins.base import PluginWidget class LogMessageDisplay(PluginWidget): def __init__(self, parent): - PluginWidget.__init__(self, parent) + super(LogMessageDisplay, self).__init__(parent) # layout self.display = MessageDisplay(parent) -- GitLab