def find_all_windows_that_are_savable(): """ Finds all windows and then checks if they have an encoder, if they do return them in a list of windows and encoders. :return: List of Lists of Windows and Encoders; Window at index 0 and Encoder at index 1 in each sub-list. """ # Get all top level widgets and check if they have an encoder list_of_windows_and_encoder = [] windows = QApplication.topLevelWidgets() for window in windows: encoder = EncoderFactory.find_encoder(window) if encoder is not None: list_of_windows_and_encoder.append((window, encoder)) return list_of_windows_and_encoder
def find_all_windows_that_are_savable(): """ Finds all windows and then checks if they have an encoder, if they do return them in a list of windows and encoders. :return: List of Lists of Windows and Encoders; Window at index 0 and Encoder at index 1 in each sub-list. """ # Get all top level widgets and check if they have an encoder list_of_windows_and_encoder = [] windows = QApplication.topLevelWidgets() for window in windows: encoder_class = EncoderFactory.find_encoder(window) if encoder_class is not None: list_of_windows_and_encoder.append((window, encoder_class)) return list_of_windows_and_encoder
# 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. from mantidqt.widgets.workspacedisplay.status_bar_view import StatusBarView from mantidqt.widgets.workspacedisplay.table.presenter import TableWorkspaceDisplay from mantidqt.widgets.workspacedisplay.table.io import TableWorkspaceDisplayDecoder, TableWorkspaceDisplayEncoder from mantidqt.project.decoderfactory import DecoderFactory from mantidqt.project.encoderfactory import EncoderFactory def compatible_check_for_encoder(obj, _): return isinstance(obj, StatusBarView) and isinstance( obj.presenter, TableWorkspaceDisplay) DecoderFactory.register_decoder(TableWorkspaceDisplayDecoder) EncoderFactory.register_encoder(TableWorkspaceDisplayEncoder, compatible_check_for_encoder)
def test_find_encoder_can_find_an_encoder(self): self.assertNotEqual(None, EncoderFactory.find_encoder(self.instrument_view))
def setUp(self): EncoderFactory.register_encoder(InstrumentViewEncoder) CreateSampleWorkspace(OutputWorkspace="ws") self.instrument_view = InstrumentViewPresenter( ADS.retrieve("ws")).container
def test_encoder_is_in_encoder_factory(self): # Shows that the decoder has been registered on import of something from mantidqt.widget.instrumentview found_encoder = EncoderFactory.find_encoder(self.instrumentView) self.assertIs(InstrumentViewEncoder, found_encoder.__class__)
def test_register_encoder_can_find_correct_encoder_from_multiple_encoders(self): EncoderFactory.register_encoder(MatrixWorkspaceDisplayEncoder) self.assertNotEqual(None, EncoderFactory.find_encoder(self.instrument_view)) self.assertEqual(2, len(EncoderFactory.encoder_dict))
def test_register_encoder_has_uniqueness_preserved(self): EncoderFactory.register_encoder(InstrumentViewEncoder) self.assertEqual(1, len(EncoderFactory.encoder_dict))
# 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 mantidqt package. from mantidqt.project.decoderfactory import DecoderFactory from mantidqt.project.encoderfactory import EncoderFactory from mantidqt.widgets.workspacedisplay.status_bar_view import StatusBarView from mantidqt.widgets.workspacedisplay.table.io import TableWorkspaceDisplayDecoder, TableWorkspaceDisplayEncoder from mantidqt.widgets.workspacedisplay.table.presenter import TableWorkspaceDisplay def compatible_check_for_encoder(obj, _): return isinstance(obj, StatusBarView) and isinstance(obj.presenter, TableWorkspaceDisplay) DecoderFactory.register_decoder(TableWorkspaceDisplayDecoder) EncoderFactory.register_encoder(TableWorkspaceDisplayEncoder, compatible_check_for_encoder)
# # """ You can run this widget independently by for example: from mantidqt.widgets.instrumentview.presenter import InstrumentView from mantid.simpleapi import Load from qtpy.QtWidgets import QApplication ws=Load('CNCS_7860') app = QApplication([]) window = InstrumentView(ws) app.exec_() """ from __future__ import (absolute_import, unicode_literals) # 3rdparty imports from qtpy import PYQT4 from mantidqt.project.decoderfactory import DecoderFactory from mantidqt.project.encoderfactory import EncoderFactory from mantidqt.widgets.instrumentview.io import InstrumentViewDecoder, InstrumentViewEncoder if PYQT4: raise ImportError("Instrument view requires Qt >= v5") # Add encoder and decoders to the relevant factory DecoderFactory.register_decoder(InstrumentViewDecoder) EncoderFactory.register_encoder(InstrumentViewEncoder)
# Mantid Repository : https://github.com/mantidproject/mantid # # Copyright © 2020 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 + from mantidqt.project.decoderfactory import DecoderFactory from mantidqt.project.encoderfactory import EncoderFactory from mantidqtinterfaces.Engineering.gui.engineering_diffraction.engineering_diffraction import EngineeringDiffractionGui from mantidqtinterfaces.Engineering.gui.engineering_diffraction.engineering_diffraction_io import EngineeringDiffractionEncoder, \ EngineeringDiffractionDecoder def compatible_check_for_encoder(obj, _): return isinstance(obj, EngineeringDiffractionGui) DecoderFactory.register_decoder(EngineeringDiffractionDecoder) EncoderFactory.register_encoder(EngineeringDiffractionEncoder, compatible_check_for_encoder)
# """ You can run this widget independently by for example: from mantidqt.widgets.instrumentview.presenter import InstrumentView from mantid.simpleapi import Load from qtpy.QtWidgets import QApplication ws=Load('CNCS_7860') app = QApplication([]) window = InstrumentView(ws) app.exec_() """ from __future__ import (absolute_import, unicode_literals) # 3rdparty imports from qtpy import PYQT4 from mantidqt.project.decoderfactory import DecoderFactory from mantidqt.project.encoderfactory import EncoderFactory from mantidqt.widgets.instrumentview.io import InstrumentViewDecoder, InstrumentViewEncoder if PYQT4: raise ImportError("Instrument view requires Qt >= v5") # Add encoder and decoders to the relevant factory DecoderFactory.register_decoder(InstrumentViewDecoder) EncoderFactory.register_encoder(InstrumentViewEncoder)