Commit 62f3a148 authored by payno's avatar payno
Browse files

[orangecontrib] add _ParameterWindowContainer to add a auto/manual option for...

[orangecontrib] add _ParameterWindowContainer to add a auto/manual option for computation in OW from larch and pymca
parent 120626d6
......@@ -46,10 +46,11 @@ from xas.gui.XasObjectViewer import _plot_bkg, _plot_spectrum, _plot_knots
from xas.gui.larch.autobk import _AutobkParameters
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
from .container import _ParameterWindowContainer
_logger = logging.getLogger(__file__)
_USE_THREAD = True
_USE_THREAD = False
class AutobkWindow(qt.QMainWindow):
......@@ -62,7 +63,8 @@ class AutobkWindow(qt.QMainWindow):
self.xasObjViewer._spectrumViews[0]._plot.getXAxis().setLabel("Energy (eV)")
self.xasObjViewer._spectrumViews[0]._plot.getYAxis().setLabel("Absorption (a.u.)")
self.setCentralWidget(self.xasObjViewer)
self._parametersWindow = _AutobkParameters(parent=self)
self._parametersWindow = _ParameterWindowContainer(parent=self,
parametersWindow=_AutobkParameters)
dockWidget = qt.QDockWidget(parent=self)
# parameters window
......
# 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
"""
sigChanged = qt.Signal()
"""Signal emitted when some computation is required"""
def __init__(self, parent, parametersWindow):
assert parametersWindow is not None
super().__init__(parent=parent)
self.setLayout(qt.QGridLayout())
self._mainwidget = parametersWindow(parent=self)
assert hasattr(self._mainwidget, 'setParameters')
assert hasattr(self._mainwidget, 'getParameters')
self.layout().addWidget(self._mainwidget, 0, 0, 1, 3)
self._autoCB = qt.QCheckBox('manual update', parent=self)
self.layout().addWidget(self._autoCB, 1, 1, 1, 1)
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')
self.layout().addWidget(self._manualUpdatePB, 1, 2, 1, 1)
# setup
self._manualUpdatePB.setVisible(False)
# expose API
self.setParameters = self._mainwidget.setParameters
self.getParameters = self._mainwidget.getParameters
# connect signal / slot
self._autoCB.toggled.connect(self._manualUpdatePB.setVisible)
self._manualUpdatePB.pressed.connect(self._update)
if hasattr(self._mainwidget, 'sigChanged'):
# manage larch windows
_sig = self._mainwidget.sigChanged
elif hasattr(self._mainwidget, 'sigFTParametersSignal'):
_sig = self._mainwidget.sigFTParametersSignal
elif hasattr(self._mainwidget, 'sigNormalizationParametersSignal'):
_sig = self._mainwidget.sigNormalizationParametersSignal
elif hasattr(self._mainwidget,
'sigXASNormalizationParametersSignal'):
_sig = self._mainwidget.sigXASNormalizationParametersSignal
elif hasattr(self._mainwidget, 'sigPostEdgeParametersSignal'):
_sig = self._mainwidget.sigPostEdgeParametersSignal
else:
raise ValueError('window not recognized')
_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):
self.sigChanged.emit()
\ No newline at end of file
......@@ -46,10 +46,11 @@ from xas.gui.larch.mback import _MBackParameters
from orangecontrib.xas.progress import QProgress
from xas.gui.XasObjectViewer import _plot_norm, _plot_raw, _plot_fpp, _plot_f2
from orangecontrib.xas.utils import Converter
from .container import _ParameterWindowContainer
_logger = logging.getLogger(__file__)
_USE_THREAD = True
_USE_THREAD = False
class MbackWindow(qt.QMainWindow):
......@@ -61,7 +62,8 @@ class MbackWindow(qt.QMainWindow):
self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
self.xasObjViewer._spectrumViews[0]._plot.getXAxis().setLabel("Energy (eV)")
self.setCentralWidget(self.xasObjViewer)
self._parametersWindow = _MBackParameters(parent=self)
self._parametersWindow = _ParameterWindowContainer(parent=self,
parametersWindow=_MBackParameters)
dockWidget = qt.QDockWidget(parent=self)
# parameters window
......
......@@ -46,10 +46,11 @@ from xas.gui.XasObjectViewer import _plot_norm, _plot_mback_mu
from xas.gui.larch.mback import _MBackParameters
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
from .container import _ParameterWindowContainer
_logger = logging.getLogger(__file__)
_USE_THREAD = True
_USE_THREAD = False
class Mback_normWindow(qt.QMainWindow):
......@@ -61,7 +62,8 @@ class Mback_normWindow(qt.QMainWindow):
self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
self.xasObjViewer._spectrumViews[0]._plot.getXAxis().setLabel("Energy (eV)")
self.setCentralWidget(self.xasObjViewer)
self._parametersWindow = _MBackParameters(parent=self)
self._parametersWindow = _ParameterWindowContainer(parent=self,
parametersWindow=_MBackParameters)
dockWidget = qt.QDockWidget(parent=self)
# parameters window
......
......@@ -47,10 +47,10 @@ from xas.gui.XasObjectViewer import (_plot_edge, _plot_norm, _plot_norm_area,
from xas.gui.larch.pre_edge import _MPreEdgeParameters
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
from .container import _ParameterWindowContainer
_logger = logging.getLogger(__file__)
_USE_THREAD = False
......@@ -63,7 +63,8 @@ class _PreEdgeParameters(qt.QWidget):
def __init__(self, parent):
super().__init__(parent=parent)
self.setLayout(qt.QGridLayout())
self._mainwidget = _MPreEdgeParameters(parent=self)
self._mainwidget = _ParameterWindowContainer(parent=self,
parametersWindow=_MPreEdgeParameters)
self.layout().addWidget(self._mainwidget, 0, 0, 1, 3)
self._autoCB = qt.QCheckBox('manual update', parent=self)
self.layout().addWidget(self._autoCB, 1, 1, 1, 1)
......
......@@ -46,10 +46,11 @@ from xas.gui.XasObjectViewer import XasObjectViewer, ViewType, _plot_chir_mag,\
from xas.gui.larch.xftf import _MXFTFParameters
from orangecontrib.xas.progress import QProgress
from orangecontrib.xas.utils import Converter
from .container import _ParameterWindowContainer
_logger = logging.getLogger(__file__)
_USE_THREAD = True
_USE_THREAD = False
def _get_title(dgroup, title=None):
......@@ -79,7 +80,8 @@ class XFTFWindow(qt.QMainWindow):
self.xasObjViewer = XasObjectViewer(mapKeys=mapKeys)
self.xasObjViewer._spectrumViews[0]._plot.getXAxis().setLabel("Energy (eV)")
self.setCentralWidget(self.xasObjViewer)
self._parametersWindow = _MXFTFParameters(parent=self)
self._parametersWindow = _ParameterWindowContainer(parent=self,
parametersWindow=_MXFTFParameters)
dockWidget = qt.QDockWidget(parent=self)
# parameters window
......
......@@ -38,7 +38,7 @@ if _DEBUG:
def process_spectr_autobk(spectrum, configuration, overwrite=True,
callback=None, output=None, output_dict=None):
callbacks=None, output=None, output_dict=None):
"""
:param spectrum: spectrum to process
......
......@@ -37,7 +37,7 @@ if _DEBUG:
from larch.symboltable import Group
def process_spectr_mback(spectrum, configuration, overwrite=True, callback=None,
def process_spectr_mback(spectrum, configuration, overwrite=True, callbacks=None,
output=None, output_dict=None):
"""
......
......@@ -38,7 +38,7 @@ if _DEBUG:
def process_spectr_mback_norm(spectrum, configuration, overwrite=True,
callback=None, output=None, output_dict=None):
callbacks=None, output=None, output_dict=None):
"""
:param spectrum: spectrum to process
......
......@@ -37,7 +37,7 @@ if _DEBUG:
from larch.symboltable import Group
def process_spectr_xftf(spectrum, configuration, overwrite=True, callback=None,
def process_spectr_xftf(spectrum, configuration, overwrite=True, callbacks=None,
output=None, output_dict=None):
"""
......
......@@ -41,7 +41,7 @@ from xas.core.types import XASObject, Spectrum
_logger = logging.getLogger(__name__)
def process_spectr_exafs(spectrum, configuration, overwrite=True, callback=None,
def process_spectr_exafs(spectrum, configuration, overwrite=True, callbacks=None,
output=None, output_dict=None):
"""
......
......@@ -40,7 +40,7 @@ from xas.core.types import XASObject, Spectrum
_logger = logging.getLogger(__name__)
def process_spectr_ft(spectrum, configuration, overwrite=True, callback=None,
def process_spectr_ft(spectrum, configuration, overwrite=True, callbacks=None,
output=None, output_dict=None):
"""
......
......@@ -40,7 +40,7 @@ from xas.core.types import XASObject, Spectrum
_logger = logging.getLogger(__name__)
def process_spectr_k(spectrum, configuration, overwrite=True, callback=None,
def process_spectr_k(spectrum, configuration, overwrite=True, callbacks=None,
output=None, output_dict=None):
"""
......
......@@ -40,7 +40,7 @@ from xas.core.types import Spectrum, XASObject
_logger = logging.getLogger(__name__)
def process_spectr_norm(spectrum, configuration, overwrite=True, callback=None,
def process_spectr_norm(spectrum, configuration, overwrite=True, callbacks=None,
output=None, output_dict=None):
"""
......@@ -50,7 +50,7 @@ def process_spectr_norm(spectrum, configuration, overwrite=True, callback=None,
:type: dict
:param overwrite: False if we want to return a new Spectrum instance
:type: bool
:param callback: callback to execute.
:param callbacks: callback to execute.
:param output: list to store the result, needed for pool processing
:type: multiprocessing.manager.list
:param output_dict: key is input spectrum, value is index in the output
......
......@@ -187,22 +187,25 @@ class _AutobkParameters(qt.QWidget):
self.setSigmaErr = self._errSignalSB.setValue
# connect signal / slots
self._rbkgSB.valueChanged.connect(self._parametersChanged)
self._e0SB.sigChanged.connect(self._parametersChanged)
self._edgeStepSB.sigChanged.connect(self._parametersChanged)
self._rbkgSB.valueChanged.connect(self._valueChanged)
self._e0SB.sigChanged.connect(self._valueChanged)
self._edgeStepSB.sigChanged.connect(self._valueChanged)
# self._nknotsSB.sigChanged.connect(self._parametersChanged)
self._kminSB.valueChanged.connect(self._parametersChanged)
self._kmaxSB.sigChanged.connect(self._parametersChanged)
self._kweightSB.valueChanged.connect(self._parametersChanged)
self._dkSB.valueChanged.connect(self._parametersChanged)
self._windowCB.currentTextChanged.connect(self._parametersChanged)
self._nfftSB.valueChanged.connect(self._parametersChanged)
self._kstepSB.valueChanged.connect(self._parametersChanged)
self._nclampSB.valueChanged.connect(self._parametersChanged)
self._clampLoSB.valueChanged.connect(self._parametersChanged)
self._clampHiSB.valueChanged.connect(self._parametersChanged)
self._calcUncertaintiesCB.toggled.connect(self._parametersChanged)
self._errSignalSB.valueChanged.connect(self._parametersChanged)
self._kminSB.valueChanged.connect(self._valueChanged)
self._kmaxSB.sigChanged.connect(self._valueChanged)
self._kweightSB.valueChanged.connect(self._valueChanged)
self._dkSB.valueChanged.connect(self._valueChanged)
self._windowCB.currentTextChanged.connect(self._valueChanged)
self._nfftSB.valueChanged.connect(self._valueChanged)
self._kstepSB.valueChanged.connect(self._valueChanged)
self._nclampSB.valueChanged.connect(self._valueChanged)
self._clampLoSB.valueChanged.connect(self._valueChanged)
self._clampHiSB.valueChanged.connect(self._valueChanged)
self._calcUncertaintiesCB.toggled.connect(self._valueChanged)
self._errSignalSB.valueChanged.connect(self._valueChanged)
# avoid several emission of the sigChanged signal
self._lastParameters = None
def getParameters(self):
return {
......@@ -268,5 +271,8 @@ class _AutobkParameters(qt.QWidget):
else:
_logger.warning(window + ' not found.')
def _parametersChanged(self, *args, **kwargs):
self.sigChanged.emit()
\ No newline at end of file
def _valueChanged(self, *args, **kwargs):
currentParameters = self.getParameters()
if currentParameters != self._lastParameters:
self._lastParameters = currentParameters
self.sigChanged.emit()
......@@ -152,8 +152,14 @@ class _MBackParameters(qt.QWidget):
self._tableCB.currentIndexChanged.connect(self._valueChanged)
self._fiterfc.toggled.connect(self._valueChanged)
# avoid several emission of the sigChanged signal
self._lastParameters = None
def _valueChanged(self, *arg, **kwargs):
self.sigChanged.emit()
currentParameters = self.getParameters()
if currentParameters != self._lastParameters:
self._lastParameters = currentParameters
self.sigChanged.emit()
def getParameters(self):
return {
......
......@@ -156,13 +156,13 @@ class _MPreEdgeParameters(qt.QWidget):
self._makeFlatCB.toggled.connect(self._valueChanged)
self._eminAreaSB.sigChanged.connect(self._valueChanged)
#
self._last_values = None
# avoid several emission of the sigChanged signal
self._lastParameters = None
def _valueChanged(self, *arg, **kwargs):
current_values = self.getParameters()
if current_values != self._last_values:
self._last_values = current_values
if current_values != self._lastParameters:
self._lastParameters = current_values
self.sigChanged.emit()
def getParameters(self):
......
......@@ -137,6 +137,9 @@ class _MXFTFParameters(qt.QWidget):
self._nfftSB.valueChanged.connect(self._valueChanged)
self._kstepSB.valueChanged.connect(self._valueChanged)
# avoid several emission of the sigChanged signal
self._lastParameters = None
def setWindow(self, window):
assert window in self._VALID_WINDOWS
index = self._windowCB.findText(window)
......@@ -144,7 +147,10 @@ class _MXFTFParameters(qt.QWidget):
self._windowCB.setCurrentIndex(index)
def _valueChanged(self, *arg, **kwargs):
self.sigChanged.emit()
currentParameters = self.getParameters()
if currentParameters != self._lastParameters:
self._lastParameters = currentParameters
self.sigChanged.emit()
def getParameters(self):
return {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment