diff --git a/qt/applications/workbench/workbench/plugins/workspacewidget.py b/qt/applications/workbench/workbench/plugins/workspacewidget.py index fa8480f95af914b0829d54b88b21a0edda89eee0..e87b87f93a58bda3ef36aca333e27825430cf775 100644 --- a/qt/applications/workbench/workbench/plugins/workspacewidget.py +++ b/qt/applications/workbench/workbench/plugins/workspacewidget.py @@ -19,6 +19,7 @@ from __future__ import (absolute_import, unicode_literals) # system imports # third-party library imports +from mantid.api import AnalysisDataService from mantidqt.widgets.workspacewidget.mantidtreemodel import MantidTreeModel from mantidqt.widgets.workspacewidget.workspacetreewidget import PlotSelectionDialog, WorkspaceTreeWidget from qtpy.QtWidgets import QVBoxLayout @@ -53,6 +54,7 @@ class WorkspaceWidget(PluginWidget): # ----------------- Behaviour -------------------- - def _do_plot1d(self): - selection_dlg = PlotSelectionDialog([], parent=self) + def _do_plot1d(self, selected_ws): + workspaces = [AnalysisDataService.Instance()[selected_ws.encode('utf-8')]] + selection_dlg = PlotSelectionDialog(workspaces, parent=self) selection_dlg.exec_() diff --git a/qt/python/CMakeLists.txt b/qt/python/CMakeLists.txt index e9ba664c03618e0927cd37e640409baa3a4f534f..d49770267099717aab8a67b060d57997d7eeb9e4 100644 --- a/qt/python/CMakeLists.txt +++ b/qt/python/CMakeLists.txt @@ -66,6 +66,8 @@ if ( ENABLE_WORKBENCH ) mantidqt/widgets/codeeditor/test/test_interpreter.py mantidqt/widgets/codeeditor/test/test_multifileinterpreter.py + mantidqt/widgets/workspacewidget/test/test_plotselectiondialog.py + mantidqt/widgets/test/test_algorithmselector.py mantidqt/widgets/test/test_jupyterconsole.py mantidqt/widgets/test/test_messagedisplay.py diff --git a/qt/python/mantidqt/widgets/workspacewidget/plotselectiondialog.ui b/qt/python/mantidqt/widgets/workspacewidget/plotselectiondialog.ui index e8f0f3e32eca39b298f9a13c6bfa5c3453050cb2..51e988e2a8f33a3d0e2aec9c13c81c30dc7204c1 100644 --- a/qt/python/mantidqt/widgets/workspacewidget/plotselectiondialog.ui +++ b/qt/python/mantidqt/widgets/workspacewidget/plotselectiondialog.ui @@ -14,19 +14,6 @@ <string>Plot 1D</string> </property> <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="1"> - <widget class="QLineEdit" name="specNums"/> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="wkspIndices"/> - </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Workspace Indices:</string> - </property> - </widget> - </item> <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="text"> @@ -34,7 +21,7 @@ </property> </widget> </item> - <item row="3" column="0"> + <item row="4" column="0"> <widget class="QLabel" name="label_3"> <property name="text"> <string>Plot type:</string> @@ -44,7 +31,7 @@ </property> </widget> </item> - <item row="4" column="1"> + <item row="5" column="1"> <widget class="QDialogButtonBox" name="buttonBox"> <property name="standardButtons"> <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::YesToAll</set> @@ -54,7 +41,20 @@ </property> </widget> </item> - <item row="3" column="1"> + <item row="0" column="1"> + <widget class="QLineEdit" name="specNums"/> + </item> + <item row="2" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> + <string>Workspace Indices:</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QLineEdit" name="wkspIndices"/> + </item> + <item row="4" column="1"> <layout class="QHBoxLayout" name="horizontalLayout"> <item> <widget class="QComboBox" name="plotType"> @@ -86,6 +86,13 @@ </item> </layout> </item> + <item row="1" column="1"> + <widget class="QLabel" name="label_4"> + <property name="text"> + <string>Or</string> + </property> + </widget> + </item> </layout> </widget> <resources/> diff --git a/qt/python/mantidqt/widgets/workspacewidget/test/__init__.py b/qt/python/mantidqt/widgets/workspacewidget/test/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/qt/python/mantidqt/widgets/workspacewidget/test/test_plotselectiondialog.py b/qt/python/mantidqt/widgets/workspacewidget/test/test_plotselectiondialog.py new file mode 100644 index 0000000000000000000000000000000000000000..707f782719dc4ab824bb83ae71e62b9b50786534 --- /dev/null +++ b/qt/python/mantidqt/widgets/workspacewidget/test/test_plotselectiondialog.py @@ -0,0 +1,56 @@ +# 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/>. + +# std imports +import unittest + +# 3rdparty imports +from mantid.simpleapi import CreateSampleWorkspace, CropWorkspace + +# local imports +from mantidqt.utils.qt.testing import requires_qapp +from mantidqt.widgets.workspacewidget.workspacetreewidget import PlotSelectionDialog + + +@requires_qapp +class PlotSelectionDialogTest(unittest.TestCase): + + def test_filling_workspace_details_single_workspace(self): + workspaces = [CreateSampleWorkspace(OutputWorkspace='ws', StoreInADS=False)] + dlg = PlotSelectionDialog(workspaces) + self.assertEqual("1-200", dlg._ui.specNums.placeholderText()) + self.assertEqual("0-199", dlg._ui.wkspIndices.placeholderText()) + + def test_filling_workspace_details_multiple_workspaces_of_same_size(self): + workspaces = [CreateSampleWorkspace(OutputWorkspace='ws', StoreInADS=False), + CreateSampleWorkspace(OutputWorkspace='ws2', StoreInADS=False)] + dlg = PlotSelectionDialog(workspaces) + self.assertEqual("1-200", dlg._ui.specNums.placeholderText()) + self.assertEqual("0-199", dlg._ui.wkspIndices.placeholderText()) + + def test_filling_workspace_details_multiple_workspaces_of_different_sizes(self): + ws1 = CreateSampleWorkspace(OutputWorkspace='ws', NumBanks=1, StoreInADS=False) + ws1 = CropWorkspace(ws1, StartWorkspaceIndex=50) + ws2 = CreateSampleWorkspace(OutputWorkspace='ws', StoreInADS=False) + + dlg = PlotSelectionDialog([ws1, ws2]) + self.assertEqual("51-100", dlg._ui.specNums.placeholderText()) + self.assertEqual("0-49", dlg._ui.wkspIndices.placeholderText()) + + +if __name__ == '__main__': + unittest.main() diff --git a/qt/python/mantidqt/widgets/workspacewidget/workspacetreewidget.py b/qt/python/mantidqt/widgets/workspacewidget/workspacetreewidget.py index a43c29eae5480f25ab1ee98b880290df35637109..83fcbb4b2fd94c2216a28a83ee0c78b00366945d 100644 --- a/qt/python/mantidqt/widgets/workspacewidget/workspacetreewidget.py +++ b/qt/python/mantidqt/widgets/workspacewidget/workspacetreewidget.py @@ -16,8 +16,10 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. from __future__ import (absolute_import) +# std imports + # 3rd party imports -from qtpy.QtWidgets import QDialog, QVBoxLayout +from qtpy.QtWidgets import QDialogButtonBox # local imports from mantidqt.utils.qt import import_qtlib, load_ui @@ -32,9 +34,35 @@ PlotSelectionDialogUI, PlotSelectionDialogUIBase = load_ui(__file__, 'plotselect class PlotSelectionDialog(PlotSelectionDialogUIBase): def __init__(self, workspaces, - parent=None): + parent=None): super(PlotSelectionDialog, self).__init__(parent) + # attributes + self._workspaces = workspaces + # layout ui = PlotSelectionDialogUI() ui.setupUi(self) - self.ui = ui + self._ui = ui + # overwrite the "Yes to All" button text + ui.buttonBox.button(QDialogButtonBox.YesToAll).setText('Plot All') + + # populate details + self._fill_workspace_details() + + # ------------------- Private ------------------------- + def _fill_workspace_details(self): + """Sets placeholder text to indicate the ranges possible""" + workspaces = self._workspaces + # workspace index range + wi_max = min([ws.getNumberHistograms() - 1 for ws in workspaces]) + self._ui.wkspIndices.setPlaceholderText("{}-{}".format(0, wi_max)) + + # spectra range + ws_spectra = [{ws.getSpectrum(i).getSpectrumNo() for i in range(ws.getNumberHistograms())} for ws in workspaces] + plottable = ws_spectra[0] + if len(ws_spectra) > 1: + for sp_set in ws_spectra[1:]: + plottable = plottable.intersection(sp_set) + plottable = sorted(plottable) + spec_min, spec_max = min(plottable), max(plottable) + self._ui.specNums.setPlaceholderText("{}-{}".format(spec_min, spec_max))