コード例 #1
0
    def closeEvent(self, event):
        poniFile = self.model().experimentSettingsModel().poniFile()

        if not poniFile.isSynchronized():
            button = qt.QMessageBox.question(
                self, "calib2",
                "The PONI file was not saved.\nDo you really want to close the application?",
                qt.QMessageBox.Cancel | qt.QMessageBox.No | qt.QMessageBox.Yes,
                qt.QMessageBox.Yes)
            if button != qt.QMessageBox.Yes:
                event.ignore()
                return

        event.accept()
        CalibrationContext._releaseSingleton()
コード例 #2
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()
コード例 #3
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
コード例 #4
0
ファイル: model_transform.py プロジェクト: kif/pyFAI
def initPeaksFromControlPoints(peakSelectionModel, controlPoints, context=None):
    """Initialize peak selection model using control points object

    :rtype: pyFAI.control_points.ControlPoints
    """
    if not isinstance(peakSelectionModel, PeakSelectionModel):
        raise TypeError("Unexpected model type")
    if not isinstance(controlPoints, ControlPoints):
        raise TypeError("Unexpected model type")

    if context is None:
        context = CalibrationContext.instance()

    peakSelectionModel.clear()
    for label in controlPoints.get_labels():
        group = controlPoints.get(lbl=label)
        peakModel = createRing(group.points, peakSelectionModel=peakSelectionModel, context=context)
        peakModel.setRingNumber(group.ring + 1)
        peakModel.setName(label)
        peakSelectionModel.append(peakModel)
コード例 #5
0
ファイル: model_transform.py プロジェクト: silx-kit/pyFAI
def createRing(points, peakSelectionModel, ringNumber=None, context=None):
    """Create a new ring from a group of points

    :rtype: PeakModel
    """
    if context is None:
        context = CalibrationContext.instance()

    name = _findUnusedName(peakSelectionModel)
    if ringNumber is None:
        ringNumber = 1
    color = context.getMarkerColor(ringNumber - 1)

    peakModel = PeakModel(peakSelectionModel)
    peakModel.setName(name)
    peakModel.setColor(color)
    peakModel.setCoords(points)
    peakModel.setRingNumber(ringNumber)

    return peakModel
コード例 #6
0
ファイル: calib2.py プロジェクト: silx-kit/pyFAI
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
コード例 #7
0
ファイル: model_transform.py プロジェクト: kif/pyFAI
def createRing(points, peakSelectionModel, context=None):
    """Create a new ring from a group of points"""

    if context is None:
        context = CalibrationContext.instance()

    # reach the bigger name
    names = ["% 8s" % p.name() for p in peakSelectionModel]
    if len(names) > 0:
        names = list(sorted(names))
        bigger = names[-1].strip()
        number = 0
        for c in bigger:
            number = number * 26 + (ord(c) - ord('a'))
    else:
        number = -1
    number = number + 1

    # compute the next one
    name = ""
    if number == 0:
        name = "a"
    else:
        n = number
        while n > 0:
            c = n % 26
            n = n // 26
            name = chr(c + ord('a')) + name

    color = context.getMarkerColor(number)

    # TODO: color and name should be removed from the model
    # TODO: As result this function should be removed
    peakModel = PeakModel(peakSelectionModel)
    peakModel.setName(name)
    peakModel.setColor(color)
    peakModel.setCoords(points)
    peakModel.setRingNumber(1)

    return peakModel
コード例 #8
0
ファイル: model_transform.py プロジェクト: vivianel/pyFAI
def createRing(points, peakSelectionModel, context=None):
    """Create a new ring from a group of points"""

    if context is None:
        context = CalibrationContext.instance()

    # reach the bigger name
    names = ["% 8s" % p.name() for p in peakSelectionModel]
    if len(names) > 0:
        names = list(sorted(names))
        bigger = names[-1].strip()
        number = 0
        for c in bigger:
            number = number * 26 + (ord(c) - ord('a'))
    else:
        number = -1
    number = number + 1

    # compute the next one
    name = ""
    if number == 0:
        name = "a"
    else:
        n = number
        while n > 0:
            c = n % 26
            n = n // 26
            name = chr(c + ord('a')) + name

    color = context.getMarkerColor(number)

    # TODO: color and name should be removed from the model
    # TODO: As result this function should be removed
    peakModel = PeakModel(peakSelectionModel)
    peakModel.setName(name)
    peakModel.setColor(color)
    peakModel.setCoords(points)
    peakModel.setRingNumber(1)

    return peakModel
コード例 #9
0
ファイル: model_transform.py プロジェクト: silx-kit/pyFAI
def initPeaksFromControlPoints(peakSelectionModel, controlPoints, context=None):
    """Initialize peak selection model using control points object

    :rtype: pyFAI.control_points.ControlPoints
    """
    if not isinstance(peakSelectionModel, PeakSelectionModel):
        raise TypeError("Unexpected model type")
    if not isinstance(controlPoints, ControlPoints):
        raise TypeError("Unexpected model type")

    if context is None:
        context = CalibrationContext.instance()

    peakSelectionModel.clear()
    for label in controlPoints.get_labels():
        group = controlPoints.get(lbl=label)
        color = context.getMarkerColor(group.ring)
        points = numpy.array(group.points)
        peakModel = createRing(points, peakSelectionModel=peakSelectionModel, context=context)
        peakModel.setRingNumber(group.ring + 1)
        peakModel.setColor(color)
        peakModel.setName(label)
        peakSelectionModel.append(peakModel)
コード例 #10
0
 def create_context(self):
     settings = qt.QSettings()
     context = CalibrationContext(settings)
     return context
コード例 #11
0
 def setUp(self):
     # FIXME: It would be good to remove this singleton
     CalibrationContext._releaseSingleton()
     super(TestCalibration, self).setUp()
コード例 #12
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