Skip to content
Snippets Groups Projects
Muon_Analysis_2.py 3.87 KiB
Newer Older
# 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 +
# pylint: disable=invalid-name
from __future__ import (absolute_import, division, print_function)

import sys

import PyQt4.QtGui as QtGui
import PyQt4.QtCore as QtCore
from mantid.kernel import ConfigServiceImpl
from Muon.GUI.Common.muon_data_context import MuonDataContext
from save_python import getWidgetIfOpen
from Muon.GUI.MuonAnalysis.load_widget.load_widget import LoadWidget
import Muon.GUI.Common.message_box as message_box
from Muon.GUI.Common.muon_load_data import MuonLoadData
from Muon.GUI.Common.grouping_tab_widget.grouping_tab_widget import GroupingTabWidget
Name = "Muon_Analysis_2"
SUPPORTED_FACILITIES = ["ISIS", "SmuS"]


def check_facility():
    """
    Get the currently set facility and check if it is in the list
    of supported facilities, raising an AttributeError if not.
    """
    current_facility = ConfigServiceImpl.Instance().getFacility().name()
    if current_facility not in SUPPORTED_FACILITIES:
        raise AttributeError("Your facility {} is not supported by MuonAnalysis 2.0, so you"
                             "will not be able to load any files. \n \n"
                             "Supported facilities are :"
                             + "\n - ".join(SUPPORTED_FACILITIES))


class MuonAnalysisGui(QtGui.QMainWindow):
    """
    The Muon Analaysis 2.0 interface.
    """

    @staticmethod
    def warning_popup(message):
        message_box.warning(str(message))

    def __init__(self, parent=None):
        super(MuonAnalysisGui, self).__init__(parent)
        self.setFocusPolicy(QtCore.Qt.StrongFocus)

        try:
            check_facility()
        except AttributeError as error:
            self.warning_popup(error.args[0])

        # initialise the data storing classes of the interface
        self.loaded_data = MuonLoadData()
        self.context = MuonDataContext(load_data=self.loaded_data)

        # construct all the widgets.
        self.load_widget = LoadWidget(self.loaded_data, self.context.instrument, self)
        self.grouping_tab_widget = GroupingTabWidget(self.context)
        splitter = QtGui.QSplitter(QtCore.Qt.Vertical)
        splitter.addWidget(self.load_widget.load_widget_view)
        splitter.addWidget(self.grouping_tab_widget.group_tab_view)

        self.setCentralWidget(splitter)
        self.setWindowTitle("Muon Analysis version 2")
        self.load_widget.load_widget.loadNotifier.add_subscriber(self.grouping_tab_widget.group_tab_presenter.loadObserver)
    def closeEvent(self, event):


def qapp():
    if QtGui.QApplication.instance():
        _app = QtGui.QApplication.instance()
    else:
        _app = QtGui.QApplication(sys.argv)
    return _app


    widget = getWidgetIfOpen(Name)
    if widget is not None:
        # if GUI is open bring to front
        widget.raise_()
        return widget
        muon.resize(700, 700)
        muon.show()
        muon = QtGui.QWidget()
        QtGui.QMessageBox.warning(muon, Name, str(error))
    widget = getWidgetIfOpen(Name)
    project = widget.saveToProject()
    global muonGUI
    muonGUI.dock_widget.loadFromProject(project)
    muonGUI.loadFromContext(project)
    muon = main()
    # cannot assign straight to muonGUI
    # prevents reopening to the same GUI
    muonGUI = muon