From 20f3306e03ed80593c441b2263f6297479d86afd Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Wed, 8 Jul 2020 16:54:52 +0200 Subject: [PATCH 1/8] When the histogram is updated, use the range from the histogram --- silx/gui/dialog/ColormapDialog.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index 7e5358526d..3c9b201acc 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -1588,7 +1588,11 @@ def _histogramRangeMoved(self, vmin, vmax): """ xmin = self._minValue.getValue() xmax = self._maxValue.getValue() - self._setColormapRange(xmin, xmax) + if vmin is None: + vmin = xmin + if vmax is None: + vmax = xmax + self._setColormapRange(vmin, vmax) def keyPressEvent(self, event): """Override key handling. From 412e6cfab9022de1cee1a9f23a667fedf10177d5 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Wed, 8 Jul 2020 16:57:11 +0200 Subject: [PATCH 2/8] Do not reset the histogram range when an handle is about to drag --- silx/gui/dialog/ColormapDialog.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index 3c9b201acc..28cbede19e 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -376,6 +376,9 @@ def __init__(self, parent): self._histogramData = {} """Histogram displayed in the plot""" + self._dragging = False, False + """True, if the min or the max handle is dragging""" + self._dataRange = {} """Histogram displayed in the plot""" @@ -399,8 +402,15 @@ def setFiniteRange(self, vRange): not be None, except if there is no range or marker to display. """ + # Do not reset the limit for handle about to be dragged + if self._dragging[0]: + vRange = self._finiteRange[0], vRange[1] + if self._dragging[1]: + vRange = vRange[0], self._finiteRange[1] + if vRange == self._finiteRange: return + self._finiteRange = vRange self.update() @@ -604,10 +614,12 @@ def _plotEventReceived(self, event): if kind == 'markerMoving': value = event['xdata'] if event['label'] == 'Min': + self._dragging = True, False self._finiteRange = value, self._finiteRange[1] self._last = value, None self.sigRangeMoving.emit(*self._last) elif event['label'] == 'Max': + self._dragging = False, True self._finiteRange = self._finiteRange[0], value self._last = None, value self.sigRangeMoving.emit(*self._last) @@ -615,6 +627,7 @@ def _plotEventReceived(self, event): elif kind == 'markerMoved': self.sigRangeMoved.emit(*self._last) self._plot.resetZoom() + self._dragging = False, False else: pass @@ -628,7 +641,7 @@ def _updateMarkerPosition(self): isDraggable = colormap.isEditable() with utils.blockSignals(self): - if posMin is not None: + if posMin is not None and not self._dragging[0]: self._plot.addXMarker( posMin, legend='Min', @@ -636,7 +649,7 @@ def _updateMarkerPosition(self): draggable=isDraggable, color="blue", constraint=self._plotMinMarkerConstraint) - if posMax is not None: + if posMax is not None and not self._dragging[1]: self._plot.addXMarker( posMax, legend='Max', From b51054c785e514522968ff7ef4800391a699931d Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Thu, 9 Jul 2020 12:27:04 +0200 Subject: [PATCH 3/8] Remove dead code - _dataValue is always None - setFiniteValue is not used --- silx/gui/dialog/ColormapDialog.py | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index 28cbede19e..70012ef002 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -140,14 +140,12 @@ def __init__(self, parent=None, value=0.0): self._numVal.editingFinished.connect(self.__editingFinished) self.setFocusProxy(self._numVal) - self._dataValue = None - self.__textWasEdited = False """True if the text was edited, in order to send an event at the end of the user interaction""" self.__realValue = None - """Store the real value set by setValue/setFiniteValue, to avoid + """Store the real value set by setValue, to avoid rounding of the widget""" def __textEdited(self): @@ -178,12 +176,10 @@ def getFiniteValue(self): if self.__realValue is not None: return self.__realValue return self._numVal.value() - elif self._dataValue is None: + else: if self.__realValue is not None: return self.__realValue return self._numVal.value() - else: - return self._dataValue def _autoToggled(self, enabled): self._numVal.setEnabled(not enabled) @@ -191,22 +187,10 @@ def _autoToggled(self, enabled): self.sigAutoScaleChanged.emit(enabled) def _updateDisplayedText(self): - # if dataValue is finite self.__textWasEdited = False - if self._autoCB.isChecked() and self._dataValue is not None: + if self._autoCB.isChecked() and self.__realValue is not None: with utils.blockSignals(self._numVal): - self._numVal.setValue(self._dataValue) - - def setDataValue(self, dataValue): - self._dataValue = dataValue - self._updateDisplayedText() - - def setFiniteValue(self, value): - assert(value is not None) - old = self._numVal.blockSignals(True) - self._numVal.setValue(value) - self.__realValue = value - self._numVal.blockSignals(old) + self._numVal.setValue(self.__realValue) def setValue(self, value, isAuto=False): self._autoCB.setChecked(isAuto or value is None) From 8576d64afa800fb213f5663fce51666ef0acb1d8 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Thu, 9 Jul 2020 12:57:57 +0200 Subject: [PATCH 4/8] Update the value only if the text edit was not edited --- silx/gui/dialog/ColormapDialog.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index 70012ef002..291c5d8edf 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -194,10 +194,12 @@ def _updateDisplayedText(self): def setValue(self, value, isAuto=False): self._autoCB.setChecked(isAuto or value is None) - if value is not None: - self._numVal.setValue(value) + with utils.blockSignals(self._numVal): + if isAuto or self.__realValue != value: + if not self.__textWasEdited: + self._numVal.setValue(value) self.__realValue = value - self._updateDisplayedText() + self._numVal.setEnabled(not isAuto) class _AutoscaleModeComboBox(qt.QComboBox): From 84a3ea14ad71e40187a627ea32fc76ad007cd31d Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Thu, 9 Jul 2020 13:07:28 +0200 Subject: [PATCH 5/8] Fix the formatting at the end of the text edition --- silx/gui/dialog/ColormapDialog.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index 291c5d8edf..b61d43847c 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -155,6 +155,9 @@ def __editingFinished(self): if self.__textWasEdited: value = self._numVal.value() self.__realValue = value + with utils.blockSignals(self._numVal): + # Fix the formatting + self._numVal.setValue(self.__realValue) self.sigValueChanged.emit(value) self.__textWasEdited = False From 3b34c4812a084a3e6ab00a9b1de9d4a96e7125d9 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 10 Jul 2020 11:07:10 +0200 Subject: [PATCH 6/8] Make sure setValue is used as it is supposed to be --- silx/gui/dialog/ColormapDialog.py | 9 ++++++++- silx/gui/dialog/test/test_colormapdialog.py | 12 ++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index b61d43847c..54de163c93 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -196,7 +196,14 @@ def _updateDisplayedText(self): self._numVal.setValue(self.__realValue) def setValue(self, value, isAuto=False): - self._autoCB.setChecked(isAuto or value is None) + """Set the value of the boundary. + + :param float value: A finite value for the boundary + :param bool isAuto: If true, the finite value was automatically computed + from the data, else it is a fixed custom value. + """ + assert value is not None + self._autoCB.setChecked(isAuto) with utils.blockSignals(self._numVal): if isAuto or self.__realValue != value: if not self.__textWasEdited: diff --git a/silx/gui/dialog/test/test_colormapdialog.py b/silx/gui/dialog/test/test_colormapdialog.py index 8efe8bc56a..61e6365d85 100644 --- a/silx/gui/dialog/test/test_colormapdialog.py +++ b/silx/gui/dialog/test/test_colormapdialog.py @@ -99,9 +99,9 @@ def testGUIModalOk(self): self.qapp.processEvents() self.colormapDiag.setColormap(self.colormap) self.assertTrue(self.colormap.getVMin() is not None) - self.colormapDiag._minValue.setValue(None) + self.colormapDiag._minValue.sigAutoScaleChanged.emit(True) self.assertTrue(self.colormap.getVMin() is None) - self.colormapDiag._maxValue.setValue(None) + self.colormapDiag._maxValue.sigAutoScaleChanged.emit(True) self.mouseClick( widget=self.colormapDiag._buttonsModal.button(qt.QDialogButtonBox.Ok), button=qt.Qt.LeftButton @@ -118,7 +118,7 @@ def testGUIModalCancel(self): self.qapp.processEvents() self.colormapDiag.setColormap(self.colormap) self.assertTrue(self.colormap.getVMin() is not None) - self.colormapDiag._minValue.setValue(None) + self.colormapDiag._minValue.sigAutoScaleChanged.emit(True) self.assertTrue(self.colormap.getVMin() is None) self.mouseClick( widget=self.colormapDiag._buttonsModal.button(qt.QDialogButtonBox.Cancel), @@ -133,7 +133,7 @@ def testGUIModalClose(self): self.qapp.processEvents() self.colormapDiag.setColormap(self.colormap) self.assertTrue(self.colormap.getVMin() is not None) - self.colormapDiag._minValue.setValue(None) + self.colormapDiag._minValue.sigAutoScaleChanged.emit(True) self.assertTrue(self.colormap.getVMin() is None) self.mouseClick( widget=self.colormapDiag._buttonsNonModal.button(qt.QDialogButtonBox.Close), @@ -148,7 +148,7 @@ def testGUIModalReset(self): self.qapp.processEvents() self.colormapDiag.setColormap(self.colormap) self.assertTrue(self.colormap.getVMin() is not None) - self.colormapDiag._minValue.setValue(None) + self.colormapDiag._minValue.sigAutoScaleChanged.emit(True) self.assertTrue(self.colormap.getVMin() is None) self.mouseClick( widget=self.colormapDiag._buttonsNonModal.button(qt.QDialogButtonBox.Reset), @@ -164,7 +164,7 @@ def testGUIClose(self): self.qapp.processEvents() self.colormapDiag.setColormap(self.colormap) self.assertTrue(self.colormap.getVMin() is not None) - self.colormapDiag._minValue.setValue(None) + self.colormapDiag._minValue.sigAutoScaleChanged.emit(True) self.assertTrue(self.colormap.getVMin() is None) self.colormapDiag.close() self.qapp.processEvents() From 52aa6aa8973938b16ec60850d6429d5bf1dfe8db Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 10 Jul 2020 11:15:29 +0200 Subject: [PATCH 7/8] Always update the colormap when boundaries are about to be moved --- silx/gui/dialog/ColormapDialog.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index 54de163c93..8af463e9f0 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -1581,14 +1581,12 @@ def _histogramRangeMoving(self, vmin, vmax): """ colormap = self.getColormap() if vmin is not None: - if colormap.getVMin() is None: - with self._colormapChange: - colormap.setVMin(vmin) + with self._colormapChange: + colormap.setVMin(vmin) self._minValue.setValue(vmin) if vmax is not None: - if colormap.getVMax() is None: - with self._colormapChange: - colormap.setVMax(vmax) + with self._colormapChange: + colormap.setVMax(vmax) self._maxValue.setValue(vmax) def _histogramRangeMoved(self, vmin, vmax): From 786193f0b1d6871aeb8f5adc54d0d9cae0e0f550 Mon Sep 17 00:00:00 2001 From: Valentin Valls Date: Fri, 10 Jul 2020 11:20:25 +0200 Subject: [PATCH 8/8] Remove dead code --- silx/gui/dialog/ColormapDialog.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/silx/gui/dialog/ColormapDialog.py b/silx/gui/dialog/ColormapDialog.py index 8af463e9f0..6b5d83bacb 100644 --- a/silx/gui/dialog/ColormapDialog.py +++ b/silx/gui/dialog/ColormapDialog.py @@ -174,16 +174,6 @@ def getValue(self): return self.__realValue return self._numVal.value() - def getFiniteValue(self): - if not self._autoCB.isChecked(): - if self.__realValue is not None: - return self.__realValue - return self._numVal.value() - else: - if self.__realValue is not None: - return self.__realValue - return self._numVal.value() - def _autoToggled(self, enabled): self._numVal.setEnabled(not enabled) self._updateDisplayedText()