From 537127957f5f950b0f5259f0e891dac3ea581064 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 08:50:58 +0100 Subject: [PATCH 01/23] ColormapDialog: move _DataInPlotMode to public API --- src/silx/gui/dialog/ColormapDialog.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index 7d2e55d7ff..31aa061d44 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -66,6 +66,7 @@ import logging import numpy +from typing import Union from .. import qt from .. import utils @@ -300,7 +301,7 @@ def setAutoRange(self, autoRange): self.setChecked(autoRange[0] if autoRange[0] == autoRange[1] else False) @enum.unique -class _DataInPlotMode(enum.Enum): +class DataInPlotMode(enum.Enum): """Enum for each mode of display of the data in the plot.""" RANGE = 'range' HISTOGRAM = 'histogram' @@ -332,7 +333,7 @@ class _ColormapHistogram(qt.QWidget): def __init__(self, parent): qt.QWidget.__init__(self, parent=parent) - self._dataInPlotMode = _DataInPlotMode.RANGE + self._dataInPlotMode = DataInPlotMode.RANGE self._finiteRange = None, None self._initPlot() @@ -550,7 +551,7 @@ def _initPlot(self): action.setToolTip("Display the data range within the colormap range. A fast data processing have to be done.") action.setIcon(icons.getQIcon('colormap-range')) action.setCheckable(True) - action.setData(_DataInPlotMode.RANGE) + action.setData(DataInPlotMode.RANGE) action.setChecked(action.data() == self._dataInPlotMode) self._plotToolbar.addAction(action) group.addAction(action) @@ -558,7 +559,7 @@ def _initPlot(self): action.setToolTip("Display the data histogram within the colormap range. A slow data processing have to be done. ") action.setIcon(icons.getQIcon('colormap-histogram')) action.setCheckable(True) - action.setData(_DataInPlotMode.HISTOGRAM) + action.setData(DataInPlotMode.HISTOGRAM) action.setChecked(action.data() == self._dataInPlotMode) self._plotToolbar.addAction(action) group.addAction(action) @@ -749,15 +750,19 @@ def _plotGammaMarkerConstraint(self, x, y): x = min(x, vmax) return x, y - def _setDataInPlotMode(self, mode): + def setDataInPlotMode(self, mode: Union[str, DataInPlotMode]): + mode = DataInPlotMode.from_value(mode) if self._dataInPlotMode == mode: return self._dataInPlotMode = mode self._updateDataInPlot() + def getDataInPlotMode(self) -> DataInPlotMode: + return self._dataInPlotMode + def _displayDataInPlotModeChanged(self, action): mode = action.data() - self._setDataInPlotMode(mode) + self.setDataInPlotMode(mode) def invalidateData(self): self._histogramData = {} @@ -779,7 +784,7 @@ def _updateDataInPlot(self): axis = self._plot.getXAxis() axis.setScale(scale) - if mode == _DataInPlotMode.RANGE: + if mode == DataInPlotMode.RANGE: dataRange = self._getNormalizedDataRange() xmin, xmax = dataRange if xmax is None or xmin is None: @@ -795,7 +800,7 @@ def _updateDataInPlot(self): fill=True, z=1) - elif mode == _DataInPlotMode.HISTOGRAM: + elif mode == DataInPlotMode.HISTOGRAM: histogram, bin_edges = self._getNormalizedHistogram() if histogram is None or bin_edges is None: self._plot.remove(legend='Data', kind='histogram') From 4953e3a5d66ca5a44487f4443e7bec93dcb544b2 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 10:19:46 +0100 Subject: [PATCH 02/23] silx.gui.plot.actions.control: rename 'setColorDialog' to 'setColormapDialog' --- src/silx/gui/data/DataViews.py | 2 +- src/silx/gui/plot/actions/control.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/silx/gui/data/DataViews.py b/src/silx/gui/data/DataViews.py index 8754dbc746..deba312d17 100644 --- a/src/silx/gui/data/DataViews.py +++ b/src/silx/gui/data/DataViews.py @@ -1657,7 +1657,7 @@ def createWidget(self, parent): from silx.gui.data.NXdataWidgets import XYVScatterPlot widget = XYVScatterPlot(parent) widget.getScatterView().setColormap(self.defaultColormap()) - widget.getScatterView().getScatterToolBar().getColormapAction().setColorDialog( + widget.getScatterView().getScatterToolBar().getColormapAction().setColormapDialog( self.defaultColorDialog()) return widget diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index 0fdfc932bd..fca8e22bb7 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -330,7 +330,7 @@ def __init__(self, plot, parent=None): self.plot.sigActiveImageChanged.connect(self._updateColormap) self.plot.sigActiveScatterChanged.connect(self._updateColormap) - def setColorDialog(self, colorDialog): + def setColormapDialog(self, colorDialog): """Set a specific color dialog instead of using the default dialog.""" assert(colorDialog is not None) assert(self._dialog is None) From ef1fbb8e6189f07f42283fa58fe49b23181afaa3 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 10:20:09 +0100 Subject: [PATCH 03/23] silx.gui.plot.actions.control: add 'setColorDialog' --- src/silx/gui/plot/actions/control.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index fca8e22bb7..ee9b4dc220 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -338,6 +338,12 @@ def setColormapDialog(self, colorDialog): self._dialog.visibleChanged.connect(self._dialogVisibleChanged) self.setChecked(self._dialog.isVisible()) + def getColormapDialog(self): + if self._dialog is None: + self._dialog = self._createDialog(self.plot) + self._dialog.visibleChanged.connect(self._dialogVisibleChanged) + return self._dialog + @staticmethod def _createDialog(parent): """Create the dialog if not already existing From 294cffe02a6f6f8a5a28f913a15f9a8f70c73dd7 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 10:20:52 +0100 Subject: [PATCH 04/23] silx.gui.dialog.ColormapDialog: make DataInPlotMode benefit from silx.utils.enum.Enum --- src/silx/gui/dialog/ColormapDialog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index 31aa061d44..61a9157f4f 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -85,6 +85,7 @@ from silx.math.histogram import Histogramnd from silx.gui.plot.items.roi import RectangleROI from silx.gui.plot.tools.roi import RegionOfInterestManager +from silx.utils.enum import Enum as _Enum _logger = logging.getLogger(__name__) @@ -301,7 +302,7 @@ def setAutoRange(self, autoRange): self.setChecked(autoRange[0] if autoRange[0] == autoRange[1] else False) @enum.unique -class DataInPlotMode(enum.Enum): +class DataInPlotMode(_Enum): """Enum for each mode of display of the data in the plot.""" RANGE = 'range' HISTOGRAM = 'histogram' From e661e8ba6706dd6e63c587c1edc3b956e34f4af4 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 10:21:10 +0100 Subject: [PATCH 05/23] ColormapDialog: add a getter for the HistoWidget --- src/silx/gui/dialog/ColormapDialog.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index 61a9157f4f..75b3c01240 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -1060,6 +1060,9 @@ def __init__(self, parent=None, title="Colormap Dialog"): self._applyColormap() + def getHistoWidget(self): + return self._histoWidget + def _invalidateColormap(self): if self.isVisible(): self._applyColormap() From 1116be13cb4d58aff9cb47e23e1ff17f06deb758 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 10:22:11 +0100 Subject: [PATCH 06/23] ColormapAction: benefit from getColormapDialog --- src/silx/gui/plot/actions/control.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index ee9b4dc220..02c55efce2 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -358,16 +358,13 @@ def _createDialog(parent): def _actionTriggered(self, checked=False): """Create a cmap dialog and update active image and default cmap.""" - if self._dialog is None: - self._dialog = self._createDialog(self.plot) - self._dialog.visibleChanged.connect(self._dialogVisibleChanged) - + dialog = self.getColormapDialog() # Run the dialog listening to colormap change if checked is True: self._updateColormap() - self._dialog.show() + dialog.show() else: - self._dialog.hide() + dialog.hide() def _dialogVisibleChanged(self, isVisible): self.setChecked(isVisible) From a89b80b5c6fa96bbbdfcf7a82e82e869aec6dfad Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 11:01:01 +0100 Subject: [PATCH 07/23] ColormapDialog: store "Data Range" and "Data Histogram" actions --- src/silx/gui/dialog/ColormapDialog.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index 75b3c01240..0f5dabd297 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -547,7 +547,7 @@ def _initPlot(self): group = qt.QActionGroup(self._plotToolbar) group.setExclusive(True) - + # data range mode action = qt.QAction("Data range", self) action.setToolTip("Display the data range within the colormap range. A fast data processing have to be done.") action.setIcon(icons.getQIcon('colormap-range')) @@ -556,6 +556,8 @@ def _initPlot(self): action.setChecked(action.data() == self._dataInPlotMode) self._plotToolbar.addAction(action) group.addAction(action) + self._dataRangeAction = action + # histogram mode action = qt.QAction("Histogram", self) action.setToolTip("Display the data histogram within the colormap range. A slow data processing have to be done. ") action.setIcon(icons.getQIcon('colormap-histogram')) @@ -564,6 +566,7 @@ def _initPlot(self): action.setChecked(action.data() == self._dataInPlotMode) self._plotToolbar.addAction(action) group.addAction(action) + self._dataHistogramAction = action group.triggered.connect(self._displayDataInPlotModeChanged) plotBoxLayout = qt.QHBoxLayout() From c1ee5e25d1bc115ed80ef35d3912e3a4e947c472 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 11:01:35 +0100 Subject: [PATCH 08/23] ColormapDialog: make ActionGroup composed of "Data Range" and "Data Histogram" exclusive --- src/silx/gui/dialog/ColormapDialog.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index 0f5dabd297..dc9e81b4b3 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -567,6 +567,7 @@ def _initPlot(self): self._plotToolbar.addAction(action) group.addAction(action) self._dataHistogramAction = action + group.setExclusive(True) group.triggered.connect(self._displayDataInPlotModeChanged) plotBoxLayout = qt.QHBoxLayout() From eada669c47319ff8ee03ea7b67f0184ad790c68f Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 11:04:21 +0100 Subject: [PATCH 09/23] _ColormapHistogram: recreate '_setDataInPlotMode' and make 'setDataInPlotMode' checked directly the action which sumplify things --- src/silx/gui/dialog/ColormapDialog.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index dc9e81b4b3..bdb9713125 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -757,6 +757,16 @@ def _plotGammaMarkerConstraint(self, x, y): def setDataInPlotMode(self, mode: Union[str, DataInPlotMode]): mode = DataInPlotMode.from_value(mode) + if mode is DataInPlotMode.HISTOGRAM: + action = self._dataHistogramAction + elif mode is DataInPlotMode.RANGE: + action = self._dataRangeAction + else: + raise NotImplementedError + action.setChecked(True) + self._displayDataInPlotModeChanged(action) + + def _setDataInPlotMode(self, mode): if self._dataInPlotMode == mode: return self._dataInPlotMode = mode @@ -767,7 +777,7 @@ def getDataInPlotMode(self) -> DataInPlotMode: def _displayDataInPlotModeChanged(self, action): mode = action.data() - self.setDataInPlotMode(mode) + self._setDataInPlotMode(mode) def invalidateData(self): self._histogramData = {} From a76f15472f0ce9dbf53065698ad12e4fb3962876 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 11:08:41 +0100 Subject: [PATCH 10/23] ColormapAction: setColormapDialog: get ride of 'assert(self._dialog is None)' Signed-off-by: payno --- src/silx/gui/plot/actions/control.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index 02c55efce2..3cadcb4082 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -333,9 +333,11 @@ def __init__(self, plot, parent=None): def setColormapDialog(self, colorDialog): """Set a specific color dialog instead of using the default dialog.""" assert(colorDialog is not None) - assert(self._dialog is None) + if self._dialog is not None: + self._dialog.visibleChanged.disconnect(self._dialogVisibleChanged) + self._dialog = colorDialog - self._dialog.visibleChanged.connect(self._dialogVisibleChanged) + self._dialog.visibleChanged.connect(self._dialogVisibleChanged, qt.Qt.UniqueConnection) self.setChecked(self._dialog.isVisible()) def getColormapDialog(self): From 139fb02ef3eba19d1d6ff44cca3ef8504357ba24 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 11:29:58 +0100 Subject: [PATCH 11/23] ColormapAction: setColormapDialog: rename `colorDialog` to `colormapDialog` --- src/silx/gui/plot/actions/control.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index 3cadcb4082..c6c504ec64 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -330,13 +330,13 @@ def __init__(self, plot, parent=None): self.plot.sigActiveImageChanged.connect(self._updateColormap) self.plot.sigActiveScatterChanged.connect(self._updateColormap) - def setColormapDialog(self, colorDialog): + def setColormapDialog(self, colormapDialog): """Set a specific color dialog instead of using the default dialog.""" - assert(colorDialog is not None) + assert(colormapDialog is not None) if self._dialog is not None: self._dialog.visibleChanged.disconnect(self._dialogVisibleChanged) - self._dialog = colorDialog + self._dialog = colormapDialog self._dialog.visibleChanged.connect(self._dialogVisibleChanged, qt.Qt.UniqueConnection) self.setChecked(self._dialog.isVisible()) From f334c2a00ab28e1509ee49535d78915be41c0ea2 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 11:30:13 +0100 Subject: [PATCH 12/23] ColormapAction: add deprecation for `setColorDialog` --- src/silx/gui/plot/actions/control.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index c6c504ec64..4ff7c91248 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -55,6 +55,7 @@ from silx.gui.plot._utils import applyZoomToPlot as _applyZoomToPlot from silx.gui import qt from silx.gui import icons +from silx.utils.deprecation import deprecated _logger = logging.getLogger(__name__) @@ -340,6 +341,10 @@ def setColormapDialog(self, colormapDialog): self._dialog.visibleChanged.connect(self._dialogVisibleChanged, qt.Qt.UniqueConnection) self.setChecked(self._dialog.isVisible()) + @deprecated(replacement="setColormapDialog", since_version="2.0") + def setColorDialog(self, colorDialog): + self.setColormapDialog(colormapDialog=colorDialog) + def getColormapDialog(self): if self._dialog is None: self._dialog = self._createDialog(self.plot) From 95dd28ae397416628d54a63ecac1dc9c64790444 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 16:18:25 +0100 Subject: [PATCH 13/23] Update src/silx/gui/dialog/ColormapDialog.py Co-authored-by: Thomas VINCENT --- src/silx/gui/dialog/ColormapDialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index bdb9713125..bd15604d25 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -755,7 +755,7 @@ def _plotGammaMarkerConstraint(self, x, y): x = min(x, vmax) return x, y - def setDataInPlotMode(self, mode: Union[str, DataInPlotMode]): + def setDataInPlotMode(self, mode: str | DataInPlotMode): mode = DataInPlotMode.from_value(mode) if mode is DataInPlotMode.HISTOGRAM: action = self._dataHistogramAction From 903c6335774e995ce513248910de2cb921e2da5d Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 16:19:29 +0100 Subject: [PATCH 14/23] replace usage of Union by usage of __anotations__ --- src/silx/gui/dialog/ColormapDialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index bd15604d25..1a1b62e61e 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -66,7 +66,7 @@ import logging import numpy -from typing import Union +from future import __annotations__ from .. import qt from .. import utils From 1a58423ce813ba1922132294051478f307266029 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 16:20:40 +0100 Subject: [PATCH 15/23] replace usage of setColorDialog by setColormapDialog --- src/silx/gui/data/DataViews.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/silx/gui/data/DataViews.py b/src/silx/gui/data/DataViews.py index deba312d17..ff807aa9ac 100644 --- a/src/silx/gui/data/DataViews.py +++ b/src/silx/gui/data/DataViews.py @@ -1032,7 +1032,7 @@ def createWidget(self, parent): from silx.gui import plot widget = plot.Plot2D(parent=parent) widget.setDefaultColormap(self.defaultColormap()) - widget.getColormapAction().setColorDialog(self.defaultColorDialog()) + widget.getColormapAction().setColormapDialog(self.defaultColorDialog()) widget.getIntensityHistogramAction().setVisible(True) widget.setKeepDataAspectRatio(True) widget.getXAxis().setLabel('X') @@ -1148,7 +1148,7 @@ def createWidget(self, parent): widget.setColormap(self.defaultColormap(), mode=ComplexImageView.ComplexMode.SQUARE_AMPLITUDE) widget.setColormap(self.defaultColormap(), mode=ComplexImageView.ComplexMode.REAL) widget.setColormap(self.defaultColormap(), mode=ComplexImageView.ComplexMode.IMAGINARY) - widget.getPlot().getColormapAction().setColorDialog(self.defaultColorDialog()) + widget.getPlot().getColormapAction().setColormapDialog(self.defaultColorDialog()) widget.getPlot().getIntensityHistogramAction().setVisible(True) widget.getPlot().setKeepDataAspectRatio(True) widget.getXAxis().setLabel('X') @@ -1248,7 +1248,7 @@ def createWidget(self, parent): from silx.gui import plot widget = plot.StackView(parent=parent) widget.setColormap(self.defaultColormap()) - widget.getPlotWidget().getColormapAction().setColorDialog(self.defaultColorDialog()) + widget.getPlotWidget().getColormapAction().setColormapDialog(self.defaultColorDialog()) widget.setKeepDataAspectRatio(True) widget.setLabels(self.axesNames(None, None)) # hide default option panel @@ -1720,7 +1720,7 @@ def createWidget(self, parent): from silx.gui.data.NXdataWidgets import ArrayImagePlot widget = ArrayImagePlot(parent) widget.getPlot().setDefaultColormap(self.defaultColormap()) - widget.getPlot().getColormapAction().setColorDialog(self.defaultColorDialog()) + widget.getPlot().getColormapAction().setColormapDialog(self.defaultColorDialog()) return widget def axesNames(self, data, info): @@ -1775,7 +1775,7 @@ def __init__(self, parent): def createWidget(self, parent): from silx.gui.data.NXdataWidgets import ArrayComplexImagePlot widget = ArrayComplexImagePlot(parent, colormap=self.defaultColormap()) - widget.getPlot().getColormapAction().setColorDialog(self.defaultColorDialog()) + widget.getPlot().getColormapAction().setColormapDialog(self.defaultColorDialog()) return widget def clear(self): @@ -1827,7 +1827,7 @@ def createWidget(self, parent): from silx.gui.data.NXdataWidgets import ArrayStackPlot widget = ArrayStackPlot(parent) widget.getStackView().setColormap(self.defaultColormap()) - widget.getStackView().getPlotWidget().getColormapAction().setColorDialog(self.defaultColorDialog()) + widget.getStackView().getPlotWidget().getColormapAction().setColormapDialog(self.defaultColorDialog()) return widget def axesNames(self, data, info): @@ -1932,7 +1932,7 @@ def createWidget(self, parent): from silx.gui.data.NXdataWidgets import ArrayStackPlot widget = ArrayStackPlot(parent) widget.getStackView().setColormap(self.defaultColormap()) - widget.getStackView().getPlotWidget().getColormapAction().setColorDialog(self.defaultColorDialog()) + widget.getStackView().getPlotWidget().getColormapAction().setColormapDialog(self.defaultColorDialog()) return widget def axesNames(self, data, info): @@ -1983,7 +1983,7 @@ def __init__(self, parent): def createWidget(self, parent): from silx.gui.data.NXdataWidgets import ArrayComplexImagePlot widget = ArrayComplexImagePlot(parent, colormap=self.defaultColormap()) - widget.getPlot().getColormapAction().setColorDialog(self.defaultColorDialog()) + widget.getPlot().getColormapAction().setColormapDialog(self.defaultColorDialog()) return widget def axesNames(self, data, info): From 9c384a5bf71b9adb76196549f073e8cd4f1086ee Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 16:22:33 +0100 Subject: [PATCH 16/23] Update src/silx/gui/dialog/ColormapDialog.py Co-authored-by: Thomas VINCENT --- src/silx/gui/dialog/ColormapDialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index bd15604d25..5db53b586c 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -1074,7 +1074,7 @@ def __init__(self, parent=None, title="Colormap Dialog"): self._applyColormap() - def getHistoWidget(self): + def getHistogramWidget(self): return self._histoWidget def _invalidateColormap(self): From d359f2ca6db9e9f6e9708a1b62aa361b45923641 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 16:22:43 +0100 Subject: [PATCH 17/23] Update src/silx/gui/plot/actions/control.py Co-authored-by: Thomas VINCENT --- src/silx/gui/plot/actions/control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index 4ff7c91248..897c3d1412 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -331,7 +331,7 @@ def __init__(self, plot, parent=None): self.plot.sigActiveImageChanged.connect(self._updateColormap) self.plot.sigActiveScatterChanged.connect(self._updateColormap) - def setColormapDialog(self, colormapDialog): + def setColormapDialog(self, dialog): """Set a specific color dialog instead of using the default dialog.""" assert(colormapDialog is not None) if self._dialog is not None: From fdb44547812fee2bf41d06cea27204892779c9c5 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 16:22:55 +0100 Subject: [PATCH 18/23] Update src/silx/gui/plot/actions/control.py Co-authored-by: Thomas VINCENT --- src/silx/gui/plot/actions/control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index 897c3d1412..b48bef0a1f 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -332,7 +332,7 @@ def __init__(self, plot, parent=None): self.plot.sigActiveScatterChanged.connect(self._updateColormap) def setColormapDialog(self, dialog): - """Set a specific color dialog instead of using the default dialog.""" + """Set a specific colormap dialog instead of using the default one.""" assert(colormapDialog is not None) if self._dialog is not None: self._dialog.visibleChanged.disconnect(self._dialogVisibleChanged) From 6a3bd6bce6d74638a2c2c3d3ac0aef7e6b6d7993 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 16 Nov 2023 16:23:13 +0100 Subject: [PATCH 19/23] Update src/silx/gui/plot/actions/control.py Co-authored-by: Thomas VINCENT --- src/silx/gui/plot/actions/control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index b48bef0a1f..c774032cca 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -333,7 +333,7 @@ def __init__(self, plot, parent=None): def setColormapDialog(self, dialog): """Set a specific colormap dialog instead of using the default one.""" - assert(colormapDialog is not None) + assert colormapDialog is not None if self._dialog is not None: self._dialog.visibleChanged.disconnect(self._dialogVisibleChanged) From ac50db6297f7f75d3fdba04828a9cdb3a49c1dc6 Mon Sep 17 00:00:00 2001 From: payno Date: Mon, 20 Nov 2023 08:35:11 +0100 Subject: [PATCH 20/23] Update src/silx/gui/dialog/ColormapDialog.py Co-authored-by: Thomas VINCENT --- src/silx/gui/dialog/ColormapDialog.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index 1a32c6d535..745f2131be 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -762,7 +762,7 @@ def setDataInPlotMode(self, mode: str | DataInPlotMode): elif mode is DataInPlotMode.RANGE: action = self._dataRangeAction else: - raise NotImplementedError + raise ValueError("Mode not supported") action.setChecked(True) self._displayDataInPlotModeChanged(action) From 2efdebb17861f2424a5f2b8f6a67f8f68149cf74 Mon Sep 17 00:00:00 2001 From: payno Date: Thu, 23 Nov 2023 15:42:22 +0100 Subject: [PATCH 21/23] Rename DataInPlotMode (previously _DataInPlotMode) to DisplayMode --- src/silx/gui/dialog/ColormapDialog.py | 52 +++++++++++++-------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index 745f2131be..4e85ed46ae 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -302,7 +302,7 @@ def setAutoRange(self, autoRange): self.setChecked(autoRange[0] if autoRange[0] == autoRange[1] else False) @enum.unique -class DataInPlotMode(_Enum): +class DisplayMode(_Enum): """Enum for each mode of display of the data in the plot.""" RANGE = 'range' HISTOGRAM = 'histogram' @@ -334,7 +334,7 @@ class _ColormapHistogram(qt.QWidget): def __init__(self, parent): qt.QWidget.__init__(self, parent=parent) - self._dataInPlotMode = DataInPlotMode.RANGE + self._displayMode = DisplayMode.RANGE self._finiteRange = None, None self._initPlot() @@ -351,7 +351,7 @@ def __init__(self, parent): def paintEvent(self, event): if self._invalidated: - self._updateDataInPlot() + self._updateDisplayMode() self._invalidated = False self._updateMarkerPosition() return super(_ColormapHistogram, self).paintEvent(event) @@ -552,8 +552,8 @@ def _initPlot(self): action.setToolTip("Display the data range within the colormap range. A fast data processing have to be done.") action.setIcon(icons.getQIcon('colormap-range')) action.setCheckable(True) - action.setData(DataInPlotMode.RANGE) - action.setChecked(action.data() == self._dataInPlotMode) + action.setData(DisplayMode.RANGE) + action.setChecked(action.data() == self._displayMode) self._plotToolbar.addAction(action) group.addAction(action) self._dataRangeAction = action @@ -562,13 +562,13 @@ def _initPlot(self): action.setToolTip("Display the data histogram within the colormap range. A slow data processing have to be done. ") action.setIcon(icons.getQIcon('colormap-histogram')) action.setCheckable(True) - action.setData(DataInPlotMode.HISTOGRAM) - action.setChecked(action.data() == self._dataInPlotMode) + action.setData(DisplayMode.HISTOGRAM) + action.setChecked(action.data() == self._displayMode) self._plotToolbar.addAction(action) group.addAction(action) self._dataHistogramAction = action group.setExclusive(True) - group.triggered.connect(self._displayDataInPlotModeChanged) + group.triggered.connect(self._displayModeChanged) plotBoxLayout = qt.QHBoxLayout() plotBoxLayout.setContentsMargins(0, 0, 0, 0) @@ -755,29 +755,29 @@ def _plotGammaMarkerConstraint(self, x, y): x = min(x, vmax) return x, y - def setDataInPlotMode(self, mode: str | DataInPlotMode): - mode = DataInPlotMode.from_value(mode) - if mode is DataInPlotMode.HISTOGRAM: + def setDisplayMode(self, mode: str | DisplayMode): + mode = DisplayMode.from_value(mode) + if mode is DisplayMode.HISTOGRAM: action = self._dataHistogramAction - elif mode is DataInPlotMode.RANGE: + elif mode is DisplayMode.RANGE: action = self._dataRangeAction else: raise ValueError("Mode not supported") action.setChecked(True) - self._displayDataInPlotModeChanged(action) + self._displayModeChanged(action) - def _setDataInPlotMode(self, mode): - if self._dataInPlotMode == mode: + def _setDisplayMode(self, mode): + if self._displayMode == mode: return - self._dataInPlotMode = mode - self._updateDataInPlot() + self._displayMode = mode + self._updateDisplayMode() - def getDataInPlotMode(self) -> DataInPlotMode: - return self._dataInPlotMode + def getDsiplayMode(self) -> DisplayMode: + return self._displayMode - def _displayDataInPlotModeChanged(self, action): + def _displayModeChanged(self, action): mode = action.data() - self._setDataInPlotMode(mode) + self._setDisplayMode(mode) def invalidateData(self): self._histogramData = {} @@ -785,8 +785,8 @@ def invalidateData(self): self._invalidated = True self.update() - def _updateDataInPlot(self): - mode = self._dataInPlotMode + def _updateDisplayMode(self): + mode = self._displayMode norm = self._getNorm() if norm == Colormap.LINEAR: @@ -799,7 +799,7 @@ def _updateDataInPlot(self): axis = self._plot.getXAxis() axis.setScale(scale) - if mode == DataInPlotMode.RANGE: + if mode == DisplayMode.RANGE: dataRange = self._getNormalizedDataRange() xmin, xmax = dataRange if xmax is None or xmin is None: @@ -815,7 +815,7 @@ def _updateDataInPlot(self): fill=True, z=1) - elif mode == DataInPlotMode.HISTOGRAM: + elif mode == DisplayMode.HISTOGRAM: histogram, bin_edges = self._getNormalizedHistogram() if histogram is None or bin_edges is None: self._plot.remove(legend='Data', kind='histogram') @@ -849,7 +849,7 @@ def _getNorm(self): return norm def updateNormalization(self): - self._updateDataInPlot() + self._updateDisplayMode() self.update() From 9d38fd7d14fa234e732f8cb564a8c6ae43adaacf Mon Sep 17 00:00:00 2001 From: payno Date: Tue, 28 Nov 2023 10:51:49 +0100 Subject: [PATCH 22/23] fix import of __anotations__ --- src/silx/gui/dialog/ColormapDialog.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/silx/gui/dialog/ColormapDialog.py b/src/silx/gui/dialog/ColormapDialog.py index 4e85ed46ae..9c22cda199 100644 --- a/src/silx/gui/dialog/ColormapDialog.py +++ b/src/silx/gui/dialog/ColormapDialog.py @@ -58,6 +58,8 @@ :attr:`ColormapDialog.sigColormapChanged`. """ # noqa +from __future__ import annotations + __authors__ = ["V.A. Sole", "T. Vincent", "H. Payno"] __license__ = "MIT" __date__ = "08/12/2020" @@ -66,7 +68,6 @@ import logging import numpy -from future import __annotations__ from .. import qt from .. import utils From 31465d9b287af534577a9ab3773e026ec7e7eb35 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Tue, 28 Nov 2023 11:19:43 +0100 Subject: [PATCH 23/23] Fix naming of dialog argument --- src/silx/gui/plot/actions/control.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/silx/gui/plot/actions/control.py b/src/silx/gui/plot/actions/control.py index c774032cca..c163f02ebe 100755 --- a/src/silx/gui/plot/actions/control.py +++ b/src/silx/gui/plot/actions/control.py @@ -333,17 +333,17 @@ def __init__(self, plot, parent=None): def setColormapDialog(self, dialog): """Set a specific colormap dialog instead of using the default one.""" - assert colormapDialog is not None + assert dialog is not None if self._dialog is not None: self._dialog.visibleChanged.disconnect(self._dialogVisibleChanged) - self._dialog = colormapDialog + self._dialog = dialog self._dialog.visibleChanged.connect(self._dialogVisibleChanged, qt.Qt.UniqueConnection) self.setChecked(self._dialog.isVisible()) @deprecated(replacement="setColormapDialog", since_version="2.0") def setColorDialog(self, colorDialog): - self.setColormapDialog(colormapDialog=colorDialog) + self.setColormapDialog(colorDialog) def getColormapDialog(self): if self._dialog is None: