Ejemplo 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()))
    def decode(obj_dic, _=None):
        if obj_dic["encoder_version"] != IO_VERSION:
            logger.error(
                "Engineering Diffraction Interface encoder used different version, restoration may fail"
            )

        ws_names = obj_dic.get(
            "data_workspaces",
            None)  # workspaces are in ADS, need restoring into interface
        if 'workbench' in sys.modules:
            from workbench.config import get_window_config

            parent, flags = get_window_config()
        else:
            parent, flags = None, None
        gui = EngineeringDiffractionGui(parent=parent, window_flags=flags)
        presenter = gui.presenter
        gui.tabs.setCurrentIndex(obj_dic["current_tab"])
        presenter.settings_presenter.model.set_settings_dict(
            obj_dic["settings_dict"])
        presenter.settings_presenter.settings = obj_dic["settings_dict"]
        if ws_names is not None:
            fit_data_widget = presenter.fitting_presenter.data_widget
            fit_data_widget.model.restore_files(ws_names)
            fit_data_widget.presenter.plotted = set(
                obj_dic["plotted_workspaces"])
            fit_data_widget.presenter.restore_table()

            fit_results = obj_dic.get("fit_results", None)
            if fit_results is not None:
                fit_data_widget.model._fit_results = fit_results
                fit_data_widget.model.create_fit_tables()

            fit_properties = obj_dic.get("fit_properties", None)
            if fit_properties is not None:
                fit_browser = presenter.fitting_presenter.plot_widget.view.fit_browser
                fit_browser.show()  # show the fit browser, default is off
                presenter.fitting_presenter.plot_widget.view.fit_toggle(
                )  # show the fit browser, default is off
                fit_props = fit_properties["properties"]
                fit_function = fit_props["Function"]
                output_name = fit_props["Output"]
                is_plot_diff = obj_dic["plot_diff"]
                fit_browser.setWorkspaceName(output_name)
                fit_browser.setStartX(fit_props["StartX"])
                fit_browser.setEndX(fit_props["EndX"])
                fit_browser.loadFunction(fit_function)
                fit_browser.setOutputName(output_name)
                ws_name = output_name + '_Workspace'
                fit_browser.do_plot(ADS.retrieve(ws_name), is_plot_diff)
        return gui
Ejemplo n.º 3
0
    def _do_sample_logs(self, names):
        """
        Show the sample log window for the given workspaces

        :param names: A list of workspace names
        """
        parent, flags = get_window_config()
        for ws in self._ads.retrieveWorkspaces(names, unrollGroups=True):
            try:
                SampleLogs(ws=ws, parent=parent, window_flags=flags)
            except Exception as exception:
                logger.warning("Could not open sample logs for workspace '{}'."
                               "".format(ws.name()))
                logger.warning("{}: {}".format(type(exception).__name__, exception))
Ejemplo n.º 4
0
    def _do_slice_viewer(self, names):
        """
        Show the sliceviewer window for the given workspaces

        :param names: A list of workspace names
        """
        parent, flags = get_window_config()
        for ws in self._ads.retrieveWorkspaces(names, unrollGroups=True):
            try:
                presenter = SliceViewer(ws=ws, conf=CONF, parent=parent, window_flags=flags)
                presenter.view.show()
            except Exception as exception:
                logger.warning("Could not open slice viewer for workspace '{}'."
                               "".format(ws.name()))
                logger.warning("{}: {}".format(type(exception).__name__, exception))
Ejemplo n.º 5
0
 def launch_custom_cpp_gui(self, interface_name, submenu=None):
     """Create a new interface window if one does not already exist,
     else show existing window"""
     object_name = 'custom-cpp-interface-' + interface_name
     window = find_window(object_name, QMainWindow)
     if window is None:
         interface = self.interface_manager.createSubWindow(interface_name)
         interface.setObjectName(object_name)
         interface.setAttribute(Qt.WA_DeleteOnClose, True)
         parent, flags = get_window_config()
         if parent:
             interface.setParent(parent, flags)
         interface.show()
     else:
         if window.windowState() == Qt.WindowMinimized:
             window.setWindowState(Qt.WindowActive)
         else:
             window.raise_()
Ejemplo n.º 6
0
    def _do_show_instrument(self, names):
        """
        Show an instrument widget for the given workspaces

        :param names: A list of workspace names
        """
        parent, flags = get_window_config()
        for ws in self._ads.retrieveWorkspaces(names, unrollGroups=True):
            if ws.getInstrument().getName():
                try:
                    presenter = InstrumentViewPresenter(ws, parent=parent, window_flags=flags)
                    presenter.show_view()
                except Exception as exception:
                    logger.warning("Could not show instrument for workspace "
                                   "'{}':\n{}\n".format(ws.name(), exception))
            else:
                logger.warning("Could not show instrument for workspace '{}':"
                               "\nNo instrument available.\n"
                               "".format(ws.name()))
Ejemplo 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 +
# pylint: disable=invalid-name
import sys
from mantidqt.gui_helper import set_matplotlib_backend, get_qapplication
set_matplotlib_backend(
)  # must be called before anything tries to use matplotlib
from mantidqtinterfaces.FilterEvents import eventFilterGUI  # noqa

app, within_mantid = get_qapplication()

if 'workbench' in sys.modules:
    from workbench.config import get_window_config

    parent, flags = get_window_config()
else:
    parent, flags = None, None
reducer = eventFilterGUI.MainWindow(
    parent, flags)  #the main ui class in this file is called MainWindow
reducer.show()
if not within_mantid:
    sys.exit(app.exec_())
Ejemplo n.º 8
0
    def __init__(self, canvas, num):
        assert QAppThreadCall.is_qapp_thread(
        ), "FigureManagerWorkbench cannot be created outside of the QApplication thread"
        QObject.__init__(self)

        parent, flags = get_window_config()
        self.window = FigureWindow(canvas, parent=parent, window_flags=flags)
        self.window.activated.connect(self._window_activated)
        self.window.closing.connect(canvas.close_event)
        self.window.closing.connect(self.destroy)
        self.window.visibility_changed.connect(self.fig_visibility_changed)

        self.window.setWindowTitle("Figure %d" % num)
        canvas.figure.set_label("Figure %d" % num)

        FigureManagerBase.__init__(self, canvas, num)
        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        canvas.setFocusPolicy(Qt.StrongFocus)
        canvas.setFocus()

        self.window._destroying = False

        # add text label to status bar
        self.statusbar_label = QLabel()
        self.window.statusBar().addWidget(self.statusbar_label)

        self.plot_options_dialog = None
        self.toolbar = self._get_toolbar(canvas, self.window)
        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            self.toolbar.message.connect(self.statusbar_label.setText)
            self.toolbar.sig_grid_toggle_triggered.connect(self.grid_toggle)
            self.toolbar.sig_toggle_fit_triggered.connect(self.fit_toggle)
            self.toolbar.sig_toggle_superplot_triggered.connect(
                self.superplot_toggle)
            self.toolbar.sig_copy_to_clipboard_triggered.connect(
                self.copy_to_clipboard)
            self.toolbar.sig_plot_options_triggered.connect(
                self.launch_plot_options)
            self.toolbar.sig_plot_help_triggered.connect(self.launch_plot_help)
            self.toolbar.sig_generate_plot_script_clipboard_triggered.connect(
                self.generate_plot_script_clipboard)
            self.toolbar.sig_generate_plot_script_file_triggered.connect(
                self.generate_plot_script_file)
            self.toolbar.sig_home_clicked.connect(
                self.set_figure_zoom_to_display_all)
            self.toolbar.sig_waterfall_reverse_order_triggered.connect(
                self.waterfall_reverse_line_order)
            self.toolbar.sig_waterfall_offset_amount_triggered.connect(
                self.launch_waterfall_offset_options)
            self.toolbar.sig_waterfall_fill_area_triggered.connect(
                self.launch_waterfall_fill_area_options)
            self.toolbar.sig_waterfall_conversion.connect(
                self.update_toolbar_waterfall_plot)
            self.toolbar.sig_change_line_collection_colour_triggered.connect(
                self.change_line_collection_colour)
            self.toolbar.setFloatable(False)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height + sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.fit_browser = FitPropertyBrowser(
            canvas, ToolbarStateManager(self.toolbar))
        self.fit_browser.closing.connect(self.handle_fit_browser_close)
        self.window.setCentralWidget(canvas)
        self.window.addDockWidget(Qt.LeftDockWidgetArea, self.fit_browser)

        self.superplot = None

        # Need this line to stop the bug where the dock window snaps back to its original size after resizing.
        # 0 argument is arbitrary and has no effect on fit widget size
        # This is a qt bug reported at (https://bugreports.qt.io/browse/QTBUG-65592)
        if QT_VERSION >= LooseVersion("5.6"):
            self.window.resizeDocks([self.fit_browser], [1], Qt.Horizontal)
        self.fit_browser.hide()

        if matplotlib.is_interactive():
            self.window.show()
            canvas.draw_idle()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()

        canvas.figure.add_axobserver(notify_axes_change)

        # Register canvas observers
        self._fig_interaction = FigureInteraction(self)
        self._ads_observer = FigureManagerADSObserver(self)

        self.window.raise_()
Ejemplo n.º 9
0
    def __init__(self, canvas, num):
        QObject.__init__(self)
        FigureManagerBase.__init__(self, canvas, num)
        # Patch show/destroy to be thread aware
        self._destroy_orig = self.destroy
        self.destroy = QAppThreadCall(self._destroy_orig)
        self._show_orig = self.show
        self.show = QAppThreadCall(self._show_orig)
        self._window_activated_orig = self._window_activated
        self._window_activated = QAppThreadCall(self._window_activated_orig)
        self.set_window_title_orig = self.set_window_title
        self.set_window_title = QAppThreadCall(self.set_window_title_orig)
        self.fig_visibility_changed_orig = self.fig_visibility_changed
        self.fig_visibility_changed = QAppThreadCall(self.fig_visibility_changed_orig)

        parent, flags = get_window_config()
        self.window = FigureWindow(canvas, parent=parent, window_flags=flags)
        self.window.activated.connect(self._window_activated)
        self.window.closing.connect(canvas.close_event)
        self.window.closing.connect(self.destroy)
        self.window.visibility_changed.connect(self.fig_visibility_changed)

        self.window.setWindowTitle("Figure %d" % num)
        canvas.figure.set_label("Figure %d" % num)

        # Give the keyboard focus to the figure instead of the
        # manager; StrongFocus accepts both tab and click to focus and
        # will enable the canvas to process event w/o clicking.
        # ClickFocus only takes the focus is the window has been
        # clicked
        # on. http://qt-project.org/doc/qt-4.8/qt.html#FocusPolicy-enum or
        # http://doc.qt.digia.com/qt/qt.html#FocusPolicy-enum
        canvas.setFocusPolicy(Qt.StrongFocus)
        canvas.setFocus()

        self.window._destroying = False

        # add text label to status bar
        self.statusbar_label = QLabel()
        self.window.statusBar().addWidget(self.statusbar_label)

        self.plot_options_dialog = None
        self.toolbar = self._get_toolbar(canvas, self.window)
        if self.toolbar is not None:
            self.window.addToolBar(self.toolbar)
            self.toolbar.message.connect(self.statusbar_label.setText)
            self.toolbar.sig_grid_toggle_triggered.connect(self.grid_toggle)
            self.toolbar.sig_toggle_fit_triggered.connect(self.fit_toggle)
            self.toolbar.sig_plot_options_triggered.connect(self.launch_plot_options)
            self.toolbar.sig_generate_plot_script_clipboard_triggered.connect(
                self.generate_plot_script_clipboard)
            self.toolbar.sig_generate_plot_script_file_triggered.connect(
                self.generate_plot_script_file)
            self.toolbar.sig_home_clicked.connect(self.set_figure_zoom_to_display_all)
            self.toolbar.sig_waterfall_reverse_order_triggered.connect(
                self.waterfall_reverse_line_order)
            self.toolbar.sig_waterfall_offset_amount_triggered.connect(
                self.launch_waterfall_offset_options)
            self.toolbar.sig_waterfall_fill_area_triggered.connect(
                self.launch_waterfall_fill_area_options)
            self.toolbar.sig_waterfall_conversion.connect(self.update_toolbar_waterfall_plot)
            self.toolbar.setFloatable(False)
            tbs_height = self.toolbar.sizeHint().height()
        else:
            tbs_height = 0

        # resize the main window so it will display the canvas with the
        # requested size:
        cs = canvas.sizeHint()
        sbs = self.window.statusBar().sizeHint()
        self._status_and_tool_height = tbs_height + sbs.height()
        height = cs.height() + self._status_and_tool_height
        self.window.resize(cs.width(), height)

        self.fit_browser = FitPropertyBrowser(canvas, ToolbarStateManager(self.toolbar))
        self.fit_browser.closing.connect(self.handle_fit_browser_close)
        self.window.setCentralWidget(canvas)
        self.window.addDockWidget(Qt.LeftDockWidgetArea, self.fit_browser)
        self.fit_browser.hide()

        if matplotlib.is_interactive():
            self.window.show()
            canvas.draw_idle()

        def notify_axes_change(fig):
            # This will be called whenever the current axes is changed
            if self.toolbar is not None:
                self.toolbar.update()

        canvas.figure.add_axobserver(notify_axes_change)

        # Register canvas observers
        self._fig_interaction = FigureInteraction(self)
        self._ads_observer = FigureManagerADSObserver(self)

        self.window.raise_()