Example #1
0
#   Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
# SPDX - License - Identifier: GPL - 3.0 +
# pylint: disable=line-too-long, invalid-name, unused-import
"""
Module to import and run the PyChop GUI for use either on the commandline or as a MantidPlot interface
"""

import sys
from PyChop import PyChopGui
try:
    from mantidqt.gui_helper import set_matplotlib_backend, get_qapplication
except ImportError:
    within_mantid = False
    from qtpy.QtWidgets import QApplication
    app = QApplication(sys.argv)
    parent, flags = None, None
else:
    set_matplotlib_backend(
    )  # must be called before anything tries to use matplotlib
    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

window = PyChopGui.PyChopGui(parent, flags)
window.show()
if not within_mantid:
    sys.exit(app.exec_())
Example #2
0
# pylint: disable=line-too-long, invalid-name, unused-import
"""
Module to import and run the PyChop GUI for use either on the commandline or as a MantidPlot interface
"""

import sys
from PyQt4 import QtGui
from PyChop import PyChopGui

if __name__ == '__main__':
    if QtGui.QApplication.instance():
        app = QtGui.QApplication.instance()
    else:
        app = QtGui.QApplication(sys.argv)
    window = PyChopGui.PyChopGui()
    window.show()
    try:  # check if started from within mantidplot
        import mantidplot  # noqa
    except ImportError:
        sys.exit(app.exec_())
Example #3
0
    def setUpClass(cls):
        class fake_QMainWindow():
            def __init__(self, *args, **kwargs):
                self.menuBar = mock.MagicMock()
                self.setCentralWidget = mock.MagicMock()
                self.setWindowTitle = mock.MagicMock()

            def setWindowFlags(self, *args, **kwargs):  # noqa: E306
                pass

            def show(self):  # noqa: E306
                pass

        class fake_QCombo(mock.MagicMock):  # noqa: E306
            def __init__(self, *args, **kwargs):
                super().__init__(*args, **kwargs)
                self.clear()

            def clear(self):  # noqa: E306
                self.items = []
                self.currentIndex = 0

            def addItem(self, item):  # noqa: E306
                self.items.append(item)

            def currentText(self):  # noqa: E306
                return self.items[self.currentIndex]

            def count(self):  # noqa: E306
                return len(self.items)

            def itemText(self, idx):  # noqa: E306
                return self.items[idx]

            def setCurrentIndex(self, idx):  # noqa: E306
                self.currentIndex = idx

            def __getattr__(self, attribute):  # noqa: E306
                if attribute not in self.__dict__:
                    self.__dict__[attribute] = mock.MagicMock()
                return self.__dict__[attribute]

        class fake_Line(mock.MagicMock):  # noqa: E306
            def __init__(self, parent, *args, **kwargs):
                super().__init__(*args, **kwargs)
                self.parent = parent

            def set_label(self, label):  # noqa: E306
                parent.legends[self] = label

        class fake_Axes(mock.MagicMock):  # noqa: E306
            def __init__(self, *args, **kwargs):
                super().__init__(*args, **kwargs)
                self.legends = {}

            def plot(self, *args, **kwargs):  # noqa: E306
                self.lines.append(fake_Line(self))
                return self.lines[-1],

            def get_legend_handles_labels(self):  # noqa: E306
                labels = [self.legends[line] for line in self.lines]
                return self.lines, labels

        class fake_Figure(mock.MagicMock):  # noqa: E306
            def add_subplot(self, *args, **kwargs):
                return fake_Axes()

        class fake_Slider(mock.MagicMock):  # noqa: E306
            def __init__(self, parent, label, valmin, valmax, **kwargs):
                super().__init__(parent, label, valmin, valmax, **kwargs)
                self.parent, self.label, self.valmin, self.valmax = parent, label, valmin, valmax
                self.val = kwargs.pop('valinit', 0.5)
                self.valtext = mock.MagicMock()
                self.on_changed = mock.MagicMock()

        cls.mock_modules = MockImports(
            include=['qtpy', 'matplotlib', 'mantidqt', 'mantid.plots'],
            replace={
                'QMainWindow': fake_QMainWindow,
                'QComboBox': MockedModule(mock_class=fake_QCombo),
                'Figure': MockedModule(mock_class=fake_Figure),
                'Slider': MockedModule(mock_class=fake_Slider)
            })
        # Mess around with import mechanism _inside_ PyChopGui so GUI libs not really imported
        with patch('builtins.__import__', cls.mock_modules.import_func):
            from PyChop import PyChopGui
            cls.window = PyChopGui.PyChopGui()
            cls.window.eiPlots.isChecked = mock.MagicMock(return_value=False)
            cls.mock_modules.matplotlib.__version__ = '2.1.0'