Exemple #1
0
 def __readSettings(self):
     settings = Qt.QSettings(_COMPANY_NAME, _APP_NAME)
     settings.beginGroup("gui")
     self.resize(settings.value("MainWindow/size", Qt.QSize(400, 400)))
     self.move(settings.value("MainWindow/pos", Qt.QPoint(200, 200)))
     self.restoreState(settings.value("MainWindow/state", Qt.QByteArray()))
     settings.endGroup()
Exemple #2
0
 def __writeSettings(self):
     settings = Qt.QSettings(_COMPANY_NAME, _APP_NAME)
     settings.beginGroup("GUI")
     settings.setValue("MainWindow/size", self.size())
     settings.setValue("MainWindow/pos", self.pos())
     settings.setValue('MainWindow/state', self.saveState())
     settings.endGroup()
Exemple #3
0
def pyFAI_calib2_main():
    # It have to be done before loading Qt
    # --help must also work without Qt
    options = parse_options()

    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    # Then we can load Qt
    if options.opengl:
        silx.config.DEFAULT_PLOT_BACKEND = "opengl"

    pyFAI.resources.silx_integration()
    settings = qt.QSettings(qt.QSettings.IniFormat, qt.QSettings.UserScope,
                            "pyfai", "pyfai-calib2", None)

    context = CalibrationContext(settings)
    context.restoreSettings()

    setup_model(context.getCalibrationModel(), options)
    window = CalibrationWindowXdart(context)
    window.setVisible(True)
    window.setAttribute(qt.Qt.WA_DeleteOnClose, True)

    context.saveSettings()
Exemple #4
0
def main():
    # It have to be done before loading Qt
    # --help must also work without Qt
    options = parse_options()

    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    # Then we can load Qt
    import silx
    from silx.gui import qt
    if options.opengl:
        silx.config.DEFAULT_PLOT_BACKEND = "opengl"

    # Make sure matplotlib is loaded first by silx
    import silx.gui.plot.matplotlib
    from pyFAI.gui.CalibrationWindow import CalibrationWindow
    from pyFAI.gui.CalibrationContext import CalibrationContext

    sys.excepthook = logUncaughtExceptions
    if options.qtargs is None:
        qtArgs = []
    else:
        qtArgs = options.qtargs.split()
    app = qt.QApplication(qtArgs)
    pyFAI.resources.silx_integration()

    settings = qt.QSettings(qt.QSettings.IniFormat, qt.QSettings.UserScope,
                            "pyfai", "pyfai-calib2", None)

    context = CalibrationContext(settings)
    context.restoreSettings()

    setup_model(context.getCalibrationModel(), options)
    window = CalibrationWindow(context)
    window.setVisible(True)
    window.setAttribute(qt.Qt.WA_DeleteOnClose, True)

    result = app.exec_()
    context.saveSettings()

    # remove ending warnings relative to QTimer
    app.deleteLater()

    return result
Exemple #5
0
def main():
    dt = DiffMap()
    options, config = dt.parse(with_config=True)

    if not options.gui:
        dt.setup_ai()
        dt.makeHDF5()
        dt.process()
        dt.show_stats()
    else:
        from silx.gui import qt
        from pyFAI.gui.diffmap_widget import DiffMapWidget
        from pyFAI.gui.ApplicationContext import ApplicationContext
        settings = qt.QSettings(qt.QSettings.IniFormat, qt.QSettings.UserScope,
                                "pyfai", "pyfai-integrate", None)
        # initialization of the singleton
        context = ApplicationContext(settings)
        app = qt.QApplication([])
        window = DiffMapWidget()
        window.set_config(config)
        # window.restore()
        window.show()
        sys.exit(app.exec_())
Exemple #6
0
def main():
    sys.excepthook = logUncaughtExceptions
    app = qt.QApplication([])
    pyFAI.resources.silx_integration()

    settings = qt.QSettings(qt.QSettings.IniFormat, qt.QSettings.UserScope,
                            "pyfai", "pyfai-calib2", None)

    context = CalibrationContext(settings)
    context.restoreSettings()

    setup(context.getCalibrationModel())
    window = CalibrationWindow(context)
    window.setVisible(True)
    window.setAttribute(qt.Qt.WA_DeleteOnClose, True)

    result = app.exec_()
    context.saveSettings()

    # remove ending warnings relative to QTimer
    app.deleteLater()

    return result
Exemple #7
0
def integrate_gui(options, args):
    from silx.gui import qt
    from pyFAI.gui.IntegrationDialog import IntegrationDialog
    from pyFAI.gui.IntegrationDialog import IntegrationProcess

    app = qt.QApplication([])

    from pyFAI.gui.ApplicationContext import ApplicationContext
    settings = qt.QSettings(qt.QSettings.IniFormat, qt.QSettings.UserScope,
                            "pyfai", "pyfai-integrate", None)
    context = ApplicationContext(settings)

    def moveCenterTo(window, center):
        half = window.size() * 0.5
        half = qt.QPoint(half.width(), half.height())
        corner = center - half
        window.move(corner)

    def processData():
        center = window.geometry().center()
        window.setVisible(False)
        window.deleteLater()
        input_data = window.input_data
        if input_data is None or len(input_data) == 0:
            dialog = qt.QFileDialog(directory=os.getcwd())
            dialog.setWindowTitle("Select images to integrate")

            from pyFAI.gui.utils import FilterBuilder
            builder = FilterBuilder.FilterBuilder()
            builder.addImageFormat("EDF image files", "edf")
            builder.addImageFormat("TIFF image files", "tif tiff")
            builder.addImageFormat("NumPy binary files", "npy")
            builder.addImageFormat("CBF files", "cbf")
            builder.addImageFormat("MarCCD image files", "mccd")
            dialog.setNameFilters(builder.getFilters())

            dialog.setFileMode(qt.QFileDialog.ExistingFiles)
            moveCenterTo(dialog, center)
            result = dialog.exec_()
            if not result:
                return
            input_data = [str(i) for i in dialog.selectedFiles()]
            center = dialog.geometry().center()
            dialog.close()

        config = window.get_config()

        dialog = IntegrationProcess(None)
        dialog.adjustSize()
        moveCenterTo(dialog, center)

        class QtProcess(qt.QThread):
            def run(self):
                observer = dialog.createObserver(qtSafe=True)
                process(input_data, window.output_path, config,
                        options.monitor_key, observer, options.write_mode)

        qtProcess = QtProcess()
        qtProcess.start()

        result = dialog.exec_()
        if result:
            qt.QMessageBox.information(dialog, "Integration",
                                       "Batch processing completed.")
        else:
            qt.QMessageBox.information(dialog, "Integration",
                                       "Batch processing interrupted.")
        dialog.deleteLater()

    window = IntegrationDialog(args,
                               options.output,
                               json_file=options.json,
                               context=context)
    window.batchProcessRequested.connect(processData)
    window.show()

    result = app.exec_()
    context.saveSettings()
    return result
def mainQt(options):
    """Part of the main depending on Qt"""
    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    #
    # Import most of the things here to be sure to use the right logging level
    #

    try:
        # it should be loaded before h5py
        import hdf5plugin  # noqa
    except ImportError:
        _logger.debug("Backtrace", exc_info=True)

    import h5py

    import silx
    import silx.utils.files
    from silx.gui import qt
    # Make sure matplotlib is configured
    # Needed for Debian 8: compatibility between Qt4/Qt5 and old matplotlib
    from silx.gui.plot import matplotlib

    app = qt.QApplication([])
    qt.QLocale.setDefault(qt.QLocale.c())

    def sigintHandler(*args):
        """Handler for the SIGINT signal."""
        qt.QApplication.quit()

    signal.signal(signal.SIGINT, sigintHandler)
    sys.excepthook = qt.exceptionHandler

    timer = qt.QTimer()
    timer.start(500)
    # Application have to wake up Python interpreter, else SIGINT is not
    # catched
    timer.timeout.connect(lambda: None)

    settings = qt.QSettings(qt.QSettings.IniFormat, qt.QSettings.UserScope,
                            "silx", "silx-view", None)
    if options.fresh_preferences:
        settings.clear()

    from .Viewer import Viewer
    window = Viewer(parent=None, settings=settings)
    window.setAttribute(qt.Qt.WA_DeleteOnClose, True)

    if options.use_opengl_plot:
        # It have to be done after the settings (after the Viewer creation)
        silx.config.DEFAULT_PLOT_BACKEND = "opengl"

    # NOTE: under Windows, cmd does not convert `*.tif` into existing files
    options.files = silx.utils.files.expand_filenames(options.files)

    for filename in options.files:
        # TODO: Would be nice to add a process widget and a cancel button
        try:
            window.appendFile(filename)
        except IOError as e:
            _logger.error(e.args[0])
            _logger.debug("Backtrace", exc_info=True)

    window.show()
    result = app.exec_()
    # remove ending warnings relative to QTimer
    app.deleteLater()
    return result
Exemple #9
0
 def create_context(self):
     settings = qt.QSettings()
     context = CalibrationContext(settings)
     return context
Exemple #10
0
def main():
    # It have to be done before loading Qt
    # --help must also work without Qt
    options = parse_options()

    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    # Then we can load Qt
    import silx
    from silx.gui import qt

    if options.opengl:
        silx.config.DEFAULT_PLOT_BACKEND = "opengl"

    # Make sure matplotlib is loaded first by silx
    import silx.gui.plot.matplotlib
    from pyFAI.gui.CalibrationWindow import CalibrationWindow
    from pyFAI.gui.CalibrationContext import CalibrationContext

    sys.excepthook = logUncaughtExceptions
    if options.qtargs is None:
        qtArgs = []
    else:
        qtArgs = options.qtargs.split()
    app = qt.QApplication(qtArgs)
    pyFAI.resources.silx_integration()

    settings = qt.QSettings(
        qt.QSettings.IniFormat, qt.QSettings.UserScope, "pyfai", "pyfai-calib2", None
    )

    context = CalibrationContext(settings)
    context.restoreSettings()

    setup_model(context.getCalibrationModel(), options)
    window = CalibrationWindow(context)

    # Begin modifications for bluesky_widgets

    from qtpy.QtWidgets import QDialog
    from bluesky_widgets.components.search.searches import Search
    from bluesky_widgets.qt.searches import QtSearch
    from bluesky_widgets.examples.utils.generate_msgpack_data import get_catalog
    from bluesky_widgets.examples.utils.add_search_mixin import columns

    from qtpy.QtWidgets import QAction, QHBoxLayout, QPushButton, QVBoxLayout, QWidget

    example_catalog = get_catalog()

    class SearchDialog(QDialog):
        """
        Combine the QtSearches widget with a button that processes selected Runs.
        """

        def __init__(self, model, *args, **kwargs):
            super().__init__(*args, **kwargs)
            layout = QVBoxLayout()
            self.setLayout(layout)
            self.setModal(True)
            layout.addWidget(QtSearch(model))

            accept = QPushButton("Open")
            reject = QPushButton("Cancel")
            # We'll just slip this into an existing widget --- not great form, but
            # this is just a silly example.
            accept.clicked.connect(self.accept)
            reject.clicked.connect(self.reject)
            buttons_widget = QWidget()
            buttons_layout = QHBoxLayout()
            buttons_widget.setLayout(buttons_layout)
            buttons_layout.addWidget(accept)
            buttons_layout.addWidget(reject)
            layout.addWidget(buttons_widget)

    def launch_dialog():
        model = Search(example_catalog, columns=columns)
        dialog = SearchDialog(model)

        def open_catalog():
            catalog = model.selection_as_catalog
            # TODO Extract the data from this.
            print(f"Open {len(catalog)} runs")

        dialog.accepted.connect(open_catalog)
        dialog.exec()

    menu = window.menuBar().addMenu("&Data Broker")
    launch_dialog_action = QAction("&Search")
    menu.addAction(launch_dialog_action)
    launch_dialog_action.triggered.connect(launch_dialog)
    # End modifications for bluesky_widgets

    window.setVisible(True)
    window.setAttribute(qt.Qt.WA_DeleteOnClose, True)

    result = app.exec_()
    context.saveSettings()

    # remove ending warnings relative to QTimer
    app.deleteLater()

    return result
Exemple #11
0
 def __init__(self, parent):
     self.__parent = weakref.ref(parent)
     self.__defaultColormap = None
     self.__defaultColormapDialog = None
     self.__settings = qt.QSettings("silx", "silx-view", parent=parent)
     self.__recentFiles = []
Exemple #12
0
def mainQt(options):
    """Part of the main depending on Qt"""
    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    #
    # Import most of the things here to be sure to use the right logging level
    #

    # Use max opened files hard limit as soft limit
    try:
        import resource
    except ImportError:
        _logger.debug("No resource module available")
    else:
        if hasattr(resource, 'RLIMIT_NOFILE'):
            try:
                hard_nofile = resource.getrlimit(resource.RLIMIT_NOFILE)[1]
                resource.setrlimit(resource.RLIMIT_NOFILE,
                                   (hard_nofile, hard_nofile))
            except (ValueError, OSError):
                _logger.warning(
                    "Failed to retrieve and set the max opened files limit")
            else:
                _logger.debug("Set max opened files to %d", hard_nofile)

    # This needs to be done prior to load HDF5
    hdf5_file_locking = 'TRUE' if options.hdf5_file_locking else 'FALSE'
    _logger.info('Set HDF5_USE_FILE_LOCKING=%s', hdf5_file_locking)
    os.environ['HDF5_USE_FILE_LOCKING'] = hdf5_file_locking

    try:
        # it should be loaded before h5py
        import hdf5plugin  # noqa
    except ImportError:
        _logger.debug("Backtrace", exc_info=True)

    import h5py

    import silx
    import silx.utils.files
    from silx.gui import qt
    # Make sure matplotlib is configured
    # Needed for Debian 8: compatibility between Qt4/Qt5 and old matplotlib
    import silx.gui.utils.matplotlib  # noqa

    app = qt.QApplication([])
    qt.QLocale.setDefault(qt.QLocale.c())

    def sigintHandler(*args):
        """Handler for the SIGINT signal."""
        qt.QApplication.quit()

    signal.signal(signal.SIGINT, sigintHandler)
    sys.excepthook = qt.exceptionHandler

    timer = qt.QTimer()
    timer.start(500)
    # Application have to wake up Python interpreter, else SIGINT is not
    # catched
    timer.timeout.connect(lambda: None)

    settings = qt.QSettings(qt.QSettings.IniFormat, qt.QSettings.UserScope,
                            "silx", "silx-view", None)
    if options.fresh_preferences:
        settings.clear()

    window = createWindow(parent=None, settings=settings)
    window.setAttribute(qt.Qt.WA_DeleteOnClose, True)

    if options.use_opengl_plot:
        # It have to be done after the settings (after the Viewer creation)
        silx.config.DEFAULT_PLOT_BACKEND = "opengl"

    # NOTE: under Windows, cmd does not convert `*.tif` into existing files
    options.files = silx.utils.files.expand_filenames(options.files)

    for filename in options.files:
        # TODO: Would be nice to add a process widget and a cancel button
        try:
            window.appendFile(filename)
        except IOError as e:
            _logger.error(e.args[0])
            _logger.debug("Backtrace", exc_info=True)

    window.show()
    result = app.exec()
    # remove ending warnings relative to QTimer
    app.deleteLater()
    return result
Exemple #13
0
def main(argv):
    """
    Main function to launch the viewer as an application

    :param argv: Command line arguments
    :returns: exit status
    """
    parser = createParser()
    options = parser.parse_args(argv[1:])

    if options.debug:
        logging.root.setLevel(logging.DEBUG)

    #
    # Import most of the things here to be sure to use the right logging level
    #

    try:
        # it should be loaded before h5py
        import hdf5plugin  # noqa
    except ImportError:
        _logger.debug("Backtrace", exc_info=True)

    try:
        import h5py
    except ImportError:
        _logger.debug("Backtrace", exc_info=True)
        h5py = None

    if h5py is None:
        message = "Module 'h5py' is not installed but is mandatory."\
            + " You can install it using \"pip install h5py\"."
        _logger.error(message)
        return -1

    #
    # Run the application
    #

    app = qt.QApplication([])
    qt.QLocale.setDefault(qt.QLocale.c())

    signal.signal(signal.SIGINT, sigintHandler)
    sys.excepthook = qt.exceptionHandler

    timer = qt.QTimer()
    timer.start(500)
    # Application have to wake up Python interpreter, else SIGINT is not
    # catched
    timer.timeout.connect(lambda: None)

    settings = qt.QSettings(qt.QSettings.IniFormat, qt.QSettings.UserScope,
                            "silx", "silx-view", None)
    if options.fresh_preferences:
        settings.clear()

    from .Viewer import Viewer
    window = Viewer(parent=None, settings=settings)
    window.setAttribute(qt.Qt.WA_DeleteOnClose, True)

    if options.use_opengl_plot:
        # It have to be done after the settings (after the Viewer creation)
        silx.config.DEFAULT_PLOT_BACKEND = "opengl"

    for filename in options.files:
        try:
            window.appendFile(filename)
        except IOError as e:
            _logger.error(e.args[0])
            _logger.debug("Backtrace", exc_info=True)

    window.show()
    result = app.exec_()
    # remove ending warnings relative to QTimer
    app.deleteLater()
    return result