Exemplo n.º 1
0
 def _do_show_data(self, names):
     # local import to allow this module to be imported without pyplot being imported
     import matplotlib.pyplot
     parent, flags = get_window_config()
     for ws in self._ads.retrieveWorkspaces(names, unrollGroups=True):
         try:
             MatrixWorkspaceDisplay.supports(ws)
             # the plot function is being injected in the presenter
             # this is done so that the plotting library is mockable in testing
             presenter = MatrixWorkspaceDisplay(ws,
                                                plot=plot,
                                                parent=parent,
                                                window_flags=flags)
             presenter.show_view()
         except ValueError:
             try:
                 TableWorkspaceDisplay.supports(ws)
                 presenter = TableWorkspaceDisplay(ws,
                                                   plot=matplotlib.pyplot,
                                                   parent=parent,
                                                   window_flags=flags,
                                                   batch=True)
                 presenter.show_view()
             except ValueError:
                 logger.error(
                     "Could not open workspace: {0} with neither "
                     "MatrixWorkspaceDisplay nor TableWorkspaceDisplay."
                     "".format(ws.name()))
Exemplo n.º 2
0
 def display_workspace(self, name):
     from mantidqt.widgets.workspacedisplay.matrix.presenter import MatrixWorkspaceDisplay
     from mantidqt.widgets.workspacedisplay.table.presenter import TableWorkspaceDisplay
     if AnalysisDataService.doesExist(name):
         ws = AnalysisDataService.retrieve(name)
         if isinstance(ws, MatrixWorkspace):
             presenter = MatrixWorkspaceDisplay(ws, plot=plot)
             presenter.show_view()
         elif isinstance(ws, ITableWorkspace):
             presenter = TableWorkspaceDisplay(ws, plot=matplotlib.pyplot)
             presenter.show_view()
Exemplo n.º 3
0
    def test_that_the_workspace_display_opens_and_closes_ok_with_a_ragged_workspace(
            self):
        presenter = MatrixWorkspaceDisplay(self.ragged_workspace)
        presenter.show_view()
        self.assert_widget_created()

        presenter.container.close()

        QApplication.sendPostedEvents()

        self.assert_no_toplevel_widgets()
Exemplo n.º 4
0
 def _do_show_data(self, names):
     for ws in self._ads.retrieveWorkspaces(names, unrollGroups=True):
         try:
             MatrixWorkspaceDisplay.supports(ws)
             # the plot function is being injected in the presenter
             # this is done so that the plotting library is mockable in testing
             presenter = MatrixWorkspaceDisplay(ws, plot=plot, parent=self)
             presenter.show_view()
         except ValueError:
             try:
                 TableWorkspaceDisplay.supports(ws)
                 presenter = TableWorkspaceDisplay(ws, plot=matplotlib.pyplot, parent=self)
                 presenter.show_view()
             except ValueError:
                 logger.error(
                     "Could not open workspace: {0} with neither "
                     "MatrixWorkspaceDisplay nor TableWorkspaceDisplay."
                     "".format(ws.name()))
Exemplo n.º 5
0
 def _do_show_data(self, names):
     for ws in self._ads.retrieveWorkspaces(names, unrollGroups=True):
         try:
             MatrixWorkspaceDisplay.supports(ws)
             # the plot function is being injected in the presenter
             # this is done so that the plotting library is mockable in testing
             presenter = MatrixWorkspaceDisplay(ws, plot=plot, parent=self)
             presenter.show_view()
         except ValueError:
             try:
                 TableWorkspaceDisplay.supports(ws)
                 presenter = TableWorkspaceDisplay(ws, plot=matplotlib.pyplot, parent=self)
                 presenter.show_view()
             except ValueError:
                 logger.error(
                     "Could not open workspace: {0} with neither "
                     "MatrixWorkspaceDisplay nor TableWorkspaceDisplay."
                     "".format(ws.name()))
Exemplo n.º 6
0
class WorkspaceDisplayViewTest(unittest.TestCase, QtWidgetFinder):
    @classmethod
    def setUpClass(cls):
        cls.workspace = create_test_workspace("non-ragged")
        cls.ragged_workspace = create_test_workspace("ragged", ragged=True)

    @classmethod
    def tearDownClass(cls):
        AnalysisDataService.clear()

    def tearDown(self):
        if not sip.isdeleted(self.presenter.container):
            self.presenter.container.close()
            QApplication.sendPostedEvents()

    def test_that_the_workspace_display_opens_and_closes_ok_with_a_non_ragged_workspace(
            self):
        self.presenter = MatrixWorkspaceDisplay(self.workspace)
        self.presenter.show_view()

        self.assert_widget_created()

        self.presenter.container.close()
        QApplication.sendPostedEvents()

        self.assert_no_toplevel_widgets()

    def test_that_the_workspace_display_opens_and_closes_ok_with_a_ragged_workspace(
            self):
        self.presenter = MatrixWorkspaceDisplay(self.ragged_workspace)
        self.presenter.show_view()

        self.assert_widget_created()

        self.presenter.container.close()
        QApplication.sendPostedEvents()

        self.assert_no_toplevel_widgets()

    def test_that_copy_spectrum_to_table_does_not_cause_an_error_with_a_non_ragged_workspace(
            self):
        with mock.patch(
                'qtpy.QtCore.QItemSelectionModel.selectedRows') as patch:
            self.presenter = MatrixWorkspaceDisplay(self.workspace)
            self.presenter.show_view()
            table = self.presenter.view.currentWidget()

            patch.return_value = [table.model().index(0, 0)]

            self.presenter.action_copy_spectrum_to_table(table)

    def test_that_copy_spectrum_to_table_does_not_cause_an_error_with_a_ragged_workspace(
            self):
        with mock.patch(
                'qtpy.QtCore.QItemSelectionModel.selectedRows') as patch:
            self.presenter = MatrixWorkspaceDisplay(self.ragged_workspace)
            self.presenter.show_view()
            table = self.presenter.view.currentWidget()

            patch.return_value = [
                table.model().index(0, 0),
                table.model().index(1, 0),
                table.model().index(2, 0)
            ]

            self.presenter.action_copy_spectrum_to_table(table)
Exemplo n.º 7
0
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
#   NScD Oak Ridge National Laboratory, European Spallation Source,
#   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
#  This file is part of the mantid workbench.
#
#

# To Run - target this package with PyCharm, and __main__ will be executed

import matplotlib

matplotlib.use('Qt5Agg')

from qtpy.QtWidgets import QApplication  # noqa: F402

from mantid.simpleapi import Load  # noqa: F402
from mantidqt.widgets.workspacedisplay.matrix.presenter import MatrixWorkspaceDisplay  # noqa: F402
from mantidqt.plotting.functions import plot  # noqa: F402

app = QApplication([])
LOQ74044 = Load("LOQ74044.nxs")
window = MatrixWorkspaceDisplay(LOQ74044, plot)
window.show_view()
app.exec_()
Exemplo n.º 8
0
# Mantid Repository : https://github.com/mantidproject/mantid
#
# Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
#     NScD Oak Ridge National Laboratory, European Spallation Source
#     & Institut Laue - Langevin
# SPDX - License - Identifier: GPL - 3.0 +
#  This file is part of the mantid workbench.
#
#

# To Run - target this package with PyCharm, and __main__ will be executed

import matplotlib

matplotlib.use('Qt5Agg')

from qtpy.QtWidgets import QApplication  # noqa: F402

from mantid.simpleapi import Load  # noqa: F402
from mantidqt.widgets.workspacedisplay.matrix.presenter import MatrixWorkspaceDisplay  # noqa: F402
from mantidqt.plotting.functions import plot  # noqa: F402

app = QApplication([])
LOQ74044 = Load("LOQ74044.nxs")
window = MatrixWorkspaceDisplay(LOQ74044, plot)
window.show_view()
app.exec_()