summaryrefslogtreecommitdiff
path: root/silx/gui/plot/CurvesROIWidget.py
diff options
context:
space:
mode:
authorAlexandre Marie <alexandre.marie@synchrotron-soleil.fr>2019-07-09 10:20:20 +0200
committerAlexandre Marie <alexandre.marie@synchrotron-soleil.fr>2019-07-09 10:20:20 +0200
commit654a6ac93513c3cc1ef97cacd782ff674c6f4559 (patch)
tree3b986e4972de7c57fa465820367602fc34bcb0d3 /silx/gui/plot/CurvesROIWidget.py
parenta763e5d1b3921b3194f3d4e94ab9de3fbe08bbdd (diff)
New upstream version 0.11.0+dfsg
Diffstat (limited to 'silx/gui/plot/CurvesROIWidget.py')
-rw-r--r--silx/gui/plot/CurvesROIWidget.py46
1 files changed, 33 insertions, 13 deletions
diff --git a/silx/gui/plot/CurvesROIWidget.py b/silx/gui/plot/CurvesROIWidget.py
index b426a23..050b344 100644
--- a/silx/gui/plot/CurvesROIWidget.py
+++ b/silx/gui/plot/CurvesROIWidget.py
@@ -75,14 +75,19 @@ class CurvesROIWidget(qt.QWidget):
"""
sigROISignal = qt.Signal(object)
- """Deprecated signal for backward compatibility with silx < 0.7.
- Prefer connecting directly to :attr:`CurvesRoiWidget.sigRoiSignal`
- """
def __init__(self, parent=None, name=None, plot=None):
super(CurvesROIWidget, self).__init__(parent)
if name is not None:
self.setWindowTitle(name)
+ self.__lastSigROISignal = None
+ """Store the last value emitted for the sigRoiSignal. In the case the
+ active curve change we need to add this extra step in order to make
+ sure we won't send twice the sigROISignal.
+ This come from the fact sigROISignal is connected to the
+ activeROIChanged signal which is emitted when raw and net counts
+ values are changing but are not embed in the sigROISignal.
+ """
assert plot is not None
self._plotRef = weakref.ref(plot)
self._showAllMarkers = False
@@ -91,12 +96,12 @@ class CurvesROIWidget(qt.QWidget):
layout = qt.QVBoxLayout(self)
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(0)
- ##############
+
self.headerLabel = qt.QLabel(self)
self.headerLabel.setAlignment(qt.Qt.AlignHCenter)
self.setHeader()
layout.addWidget(self.headerLabel)
- ##############
+
widgetAllCheckbox = qt.QWidget(parent=self)
self._showAllCheckBox = qt.QCheckBox("show all ROI",
parent=widgetAllCheckbox)
@@ -106,14 +111,13 @@ class CurvesROIWidget(qt.QWidget):
widgetAllCheckbox.layout().addWidget(spacer)
widgetAllCheckbox.layout().addWidget(self._showAllCheckBox)
layout.addWidget(widgetAllCheckbox)
- ##############
+
self.roiTable = ROITable(self, plot=plot)
rheight = self.roiTable.horizontalHeader().sizeHint().height()
self.roiTable.setMinimumHeight(4 * rheight)
layout.addWidget(self.roiTable)
self._roiFileDir = qt.QDir.home().absolutePath()
self._showAllCheckBox.toggled.connect(self.roiTable.showAllMarkers)
- #################
hbox = qt.QWidget(self)
hboxlayout = qt.QHBoxLayout(hbox)
@@ -216,7 +220,6 @@ class CurvesROIWidget(qt.QWidget):
i += 1
newroi = "newroi %d" % i
return newroi
-
roi = ROI(name=getNextRoiName())
if roi.getName() == "ICR":
@@ -231,7 +234,6 @@ class CurvesROIWidget(qt.QWidget):
fromdata, dummy0, todata, dummy1 = self._getAllLimits()
roi.setFrom(fromdata)
roi.setTo(todata)
-
self.roiTable.addRoi(roi)
# back compatibility pymca roi signals
@@ -257,7 +259,9 @@ class CurvesROIWidget(qt.QWidget):
def _reset(self):
"""Reset button clicked handler"""
self.roiTable.clear()
+ old = self.blockSignals(True) # avoid several sigROISignal emission
self._add()
+ self.blockSignals(old)
# back compatibility pymca roi signals
ddict = {}
@@ -402,7 +406,9 @@ class CurvesROIWidget(qt.QWidget):
if visible:
# if no ROI existing yet, add the default one
if self.roiTable.rowCount() is 0:
+ old = self.blockSignals(True) # avoid several sigROISignal emission
self._add()
+ self.blockSignals(old)
self.calculateRois()
def fillFromROIDict(self, *args, **kwargs):
@@ -416,7 +422,10 @@ class CurvesROIWidget(qt.QWidget):
ddict['current'] = self.roiTable.activeRoi.getName()
else:
ddict['current'] = None
- self.sigROISignal.emit(ddict)
+
+ if self.__lastSigROISignal != ddict:
+ self.__lastSigROISignal = ddict
+ self.sigROISignal.emit(ddict)
@property
def currentRoi(self):
@@ -563,8 +572,11 @@ class ROITable(TableWidget):
# backward compatibility since 0.10.0
if isinstance(rois, dict):
for roiName, roi in rois.items():
- roi['name'] = roiName
- _roi = ROI._fromDict(roi)
+ if isinstance(roi, ROI):
+ _roi = roi
+ else:
+ roi['name'] = roiName
+ _roi = ROI._fromDict(roi)
self.addRoi(_roi)
else:
for roi in rois:
@@ -688,12 +700,14 @@ class ROITable(TableWidget):
activeItems = self.selectedItems()
if len(activeItems) is 0:
return
+ old = self.blockSignals(True) # avoid several emission of sigROISignal
roiToRm = set()
for item in activeItems:
row = item.row()
itemID = self.item(row, self.COLUMNS_INDEX['ID'])
roiToRm.add(self._roiDict[int(itemID.text())])
[self.removeROI(roi) for roi in roiToRm]
+ self.blockSignals(old)
self.setActiveRoi(None)
def removeROI(self, roi):
@@ -730,7 +744,10 @@ class ROITable(TableWidget):
else:
assert isinstance(roi, ROI)
if roi and roi.getID() in self._roiToItems.keys():
+ # avoid several call back to setActiveROI
+ old = self.blockSignals(True)
self.selectRow(self._roiToItems[roi.getID()].row())
+ self.blockSignals(old)
self._markersHandler.setActiveRoi(roi)
self.activeROIChanged.emit()
@@ -931,9 +948,12 @@ class ROITable(TableWidget):
if ddict['event'] == 'markerMoved':
label = ddict['label']
roiID = self._markersHandler.getRoiID(markerID=label)
- if roiID:
+ if roiID is not None:
+ # avoid several emission of sigROISignal
+ old = self.blockSignals(True)
self._markersHandler.changePosition(markerID=label,
x=ddict['x'])
+ self.blockSignals(old)
self._updateRoiInfo(roiID)
def showEvent(self, event):