container.py 3.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# coding: utf-8
# /*##########################################################################
#
# Copyright (c) 2016-2017 European Synchrotron Radiation Facility
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# ###########################################################################*/

__authors__ = ["H. Payno"]
__license__ = "MIT"
__date__ = "13/08/2019"


from silx.gui import qt


class _ParameterWindowContainer(qt.QWidget):
    """Embed the larch parameters windows (should contains getParameters and
    setParameters and have a sigChanged signal) and add it a 'manual' update
    mode for convenience
    """
payno's avatar
payno committed
39

40
41
    sigChanged = qt.Signal()
    """Signal emitted when some computation is required"""
payno's avatar
payno committed
42

43
44
45
46
    def __init__(self, parent, parametersWindow):
        assert parametersWindow is not None
        super().__init__(parent=parent)
        self.setLayout(qt.QGridLayout())
payno's avatar
payno committed
47
48
49
        self._mainwidget = parametersWindow(parent=self)
        assert hasattr(self._mainwidget, "setParameters")
        assert hasattr(self._mainwidget, "getParameters")
50
        self.layout().addWidget(self._mainwidget, 0, 0, 1, 3)
payno's avatar
payno committed
51
        self._autoCB = qt.QCheckBox("manual update", parent=self)
52
        self.layout().addWidget(self._autoCB, 1, 1, 1, 1)
payno's avatar
payno committed
53
54
55
56
57
58
59
        self._autoCB.setToolTip(
            "if activated will wait until you press the "
            '"update" button to launch processing. '
            "Otherwise executed for each modification in "
            "the paramters"
        )
        self._manualUpdatePB = qt.QPushButton("update")
60
61
62
63
64
65
66
67
68
        self.layout().addWidget(self._manualUpdatePB, 1, 2, 1, 1)

        # setup
        self._manualUpdatePB.setVisible(False)

        # connect signal / slot
        self._autoCB.toggled.connect(self._manualUpdatePB.setVisible)
        self._manualUpdatePB.pressed.connect(self._update)

payno's avatar
payno committed
69
        if hasattr(self._mainwidget, "sigChanged"):
70
71
            # manage larch windows
            _sig = self._mainwidget.sigChanged
payno's avatar
payno committed
72
        elif hasattr(self._mainwidget, "sigFTParametersSignal"):
73
            _sig = self._mainwidget.sigFTParametersSignal
payno's avatar
payno committed
74
        elif hasattr(self._mainwidget, "sigNormalizationParametersSignal"):
75
            _sig = self._mainwidget.sigNormalizationParametersSignal
payno's avatar
payno committed
76
        elif hasattr(self._mainwidget, "sigXASNormalizationParametersSignal"):
77
            _sig = self._mainwidget.sigXASNormalizationParametersSignal
payno's avatar
payno committed
78
        elif hasattr(self._mainwidget, "sigPostEdgeParametersSignal"):
79
80
            _sig = self._mainwidget.sigPostEdgeParametersSignal
        else:
payno's avatar
payno committed
81
            raise ValueError("window not recognized")
82
83
84
85
86
87
88
89
90

        _sig.connect(self._filteredUpdate)

    def _filteredUpdate(self, *args, **kwargs):
        """call _update only if in automatic update mode"""
        if not self._autoCB.isChecked():
            self._update()

    def _update(self, *args, **kwargs):
payno's avatar
payno committed
91
        self.sigChanged.emit()
92
93
94
95
96

    def getParameters(self):
        return self._mainwidget.getParameters()

    def setParameters(self, params):
97
        self._mainwidget.setParameters(params)