Commit d05ecda9 authored by payno's avatar payno

[gui][larch] integrate E0 calculator in the larch normalization widget

parent 2491d9b4
......@@ -39,6 +39,9 @@ class _MPreEdgeParameters(qt.QWidget):
sigChanged = qt.Signal()
"""Signal emitted when parameters changed"""
sigE0CalculatorRequest = qt.Signal()
"""Signal emitted when E0 calculator is requested"""
def __init__(self, parent=None):
qt.QWidget.__init__(self, parent)
self.setLayout(qt.QGridLayout())
......@@ -52,6 +55,13 @@ class _MPreEdgeParameters(qt.QWidget):
self._e0SB.setValue(None)
self.layout().addWidget(qt.QLabel('e0', parent=self), 0, 0)
self.layout().addWidget(self._e0SB, 0, 1)
style = qt.QApplication.instance().style()
e0_icon = style.standardIcon(qt.QStyle.SP_FileDialogContentsView)
self._e0calculationPB = qt.QPushButton(e0_icon, '', parent=self)
self._e0calculationPB.setToolTip('Open E0 calculation dialog to compute'
'mean or median E value from a roi')
self.layout().addWidget(self._e0calculationPB, 0, 2)
# step
self._stepSP = _OptionalQDoubleSpinBox(parent=self)
self._stepSP.setToolTip('edge jump. If None, it will be determined')
......@@ -161,6 +171,7 @@ class _MPreEdgeParameters(qt.QWidget):
self._nvictSB.editingFinished.connect(self._valueChanged)
self._makeFlatCB.toggled.connect(self._valueChanged)
self._eminAreaSB.sigChanged.connect(self._valueChanged)
self._e0calculationPB.released.connect(self._updateE0FromDialog)
# avoid several emission of the sigChanged signal
self._lastParameters = None
......@@ -215,9 +226,35 @@ class _MPreEdgeParameters(qt.QWidget):
def setE0(self, value):
self._e0SB.setValue(value=value)
def _updateE0FromDialog(self):
self.sigE0CalculatorRequest.emit()
if __name__ == '__main__':
from est.gui.e0calculator import E0CalculatorDialog
from est.core.utils import spectra as spectra_utils
from est.core.types import XASObject
import functools
def create_dataset():
dim1, dim2 = 20, 40
energy, spectra = spectra_utils.create_dataset(shape=(256, dim1, dim2),
noise=True)
return XASObject(energy=energy,
spectra=spectra,
dim1=dim1,
dim2=dim2)
def launchE0Calculator(xas_object, pre_edge_widget):
dialog = E0CalculatorDialog(xas_obj=xas_object, parent=None)
if dialog.exec_():
pre_edge_widget.setE0(dialog.getE0())
xas_object = create_dataset()
app = qt.QApplication([])
widget = _MPreEdgeParameters()
widget.sigE0CalculatorRequest.connect(functools.partial(launchE0Calculator, xas_object, widget))
widget.show()
app.exec_()
Markdown is supported
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