From c8d19dd910d71057c744047494b4659213bf3eb4 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 18 Nov 2024 16:25:47 +0100 Subject: [PATCH 1/4] simpler implementation by using self._stackItem --- src/silx/gui/plot/StackView.py | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/silx/gui/plot/StackView.py b/src/silx/gui/plot/StackView.py index 63b8f59eeb..86a2dbe938 100644 --- a/src/silx/gui/plot/StackView.py +++ b/src/silx/gui/plot/StackView.py @@ -302,15 +302,7 @@ def getAggregationModeAction(self) -> AggregationModeAction: return self.__aggregationModeAction def _aggregationModeChanged(self): - plot = self.getPlotWidget() - item = plot._getItem("image") - - if item is None: - return - - if isinstance(item, ImageDataAggregated): - aggregationMode = self.getAggregationModeAction().getAggregationMode() - item.setAggregationMode(aggregationMode) + self._stackItem.setAggregationMode(self.getAggregationModeAction().getAggregationMode()) def _saveImageStack(self, plot, filename, nameFilter): """Save all images from the stack into a volume. From c934c5ecdc1b5367dd1b8231727cc6a7c2b35a55 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 18 Nov 2024 16:26:43 +0100 Subject: [PATCH 2/4] remove unused import and useless code in _NXdataImageView it's already done in ArrayImagePlot --- src/silx/gui/data/DataViews.py | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/silx/gui/data/DataViews.py b/src/silx/gui/data/DataViews.py index f04add1e7c..5c8c5dc762 100644 --- a/src/silx/gui/data/DataViews.py +++ b/src/silx/gui/data/DataViews.py @@ -39,7 +39,6 @@ from silx.gui.dialog.ColormapDialog import ColormapDialog from silx.gui.plot.items.image import ImageDataAggregated from silx.gui.plot.actions.image import AggregationModeAction -from silx._utils import NP_OPTIONAL_COPY __authors__ = ["V. Valls", "P. Knobel"] __license__ = "MIT" @@ -1336,7 +1335,7 @@ def createWidget(self, parent): maskToolWidget = widget.getPlotWidget().getMaskToolsDockWidget().widget() maskToolWidget.setItemMaskUpdated(True) return widget - + def clear(self): self.getWidget().clear() self.__resetZoomNextTime = True @@ -1826,6 +1825,7 @@ def createWidget(self, parent): self.defaultColorDialog() ) return widget + def axesNames(self, data, info): # disabled (used by default axis selector widget in Hdf5Viewer) return None @@ -1861,14 +1861,6 @@ def setData(self, data): yscale=y_scale, keep_ratio=(x_units == y_units), ) - - item = self.getWidget().getPlot()._getItem("image") - - if item is None: - return - - if isinstance(item, ImageDataAggregated): - item.setAggregationMode(self.getWidget().getAggregationModeAction().getAggregationMode()) def getDataPriority(self, data, info): data = self.normalizeData(data) From bb290adb829d4aac983cf92156ff1ad14a4103ad Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 18 Nov 2024 16:54:52 +0100 Subject: [PATCH 3/4] simplify implementation by reusing the same item --- src/silx/gui/data/DataViews.py | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/silx/gui/data/DataViews.py b/src/silx/gui/data/DataViews.py index 5c8c5dc762..6acc9c5bce 100644 --- a/src/silx/gui/data/DataViews.py +++ b/src/silx/gui/data/DataViews.py @@ -1073,30 +1073,24 @@ def createWidget(self, parent): widget.toolBar().addAction(self.__aggregationModeAction) self.__aggregationModeAction.sigAggregationModeChanged.connect(self._aggregationModeChanged) + self.__imageItem = ImageDataAggregated() + self.__imageItem.setAggregationMode(self.__aggregationModeAction.getAggregationMode()) + self.__imageItem.setName("data") + self.__imageItem.setColormap(widget.getDefaultColormap()) + widget.addItem(self.__imageItem) + widget.setKeepDataAspectRatio(True) widget.getXAxis().setLabel("X") widget.getYAxis().setLabel("Y") maskToolsWidget = widget.getMaskToolsDockWidget().widget() maskToolsWidget.setItemMaskUpdated(True) return widget - - def getAggregationModeAction(self) -> AggregationModeAction: - """Action toggling the aggregation mode action - """ - return self.__aggregationModeAction def _aggregationModeChanged(self): - plot = self.getWidget() - item = plot._getItem("image") - - if item is None: - return - - aggregationMode = self.getAggregationModeAction().getAggregationMode() - item.setAggregationMode(aggregationMode) + self.__imageItem.setAggregationMode(self.__aggregationModeAction.getAggregationMode()) def clear(self): - self.getWidget().clear() + self.__imageItem.setData(numpy.zeros((0, 0), dtype=numpy.float32)) self.__resetZoomNextTime = True def normalizeData(self, data): @@ -1107,16 +1101,8 @@ def normalizeData(self, data): def setData(self, data): data = self.normalizeData(data) plot = self.getWidget() - imageItem = plot._getItem("image") - - if imageItem is None: - imageItem = ImageDataAggregated() - imageItem.setAggregationMode(self.getAggregationModeAction().getAggregationMode()) - imageItem.setName("data") - imageItem.setColormap(plot.getDefaultColormap()) - plot.addItem(imageItem) - - imageItem.setData(data=data) + + self.__imageItem.setData(data=data) if self.__resetZoomNextTime: plot.resetZoom() self.__resetZoomNextTime = False From e6868fe0e99971da5993594c9b5fc1ac059e34c0 Mon Sep 17 00:00:00 2001 From: Thomas VINCENT Date: Mon, 18 Nov 2024 16:55:26 +0100 Subject: [PATCH 4/4] Make the image active to enable mask and histogram --- src/silx/gui/data/DataViews.py | 1 + src/silx/gui/data/NXdataWidgets.py | 1 + 2 files changed, 2 insertions(+) diff --git a/src/silx/gui/data/DataViews.py b/src/silx/gui/data/DataViews.py index 6acc9c5bce..5107227965 100644 --- a/src/silx/gui/data/DataViews.py +++ b/src/silx/gui/data/DataViews.py @@ -1078,6 +1078,7 @@ def createWidget(self, parent): self.__imageItem.setName("data") self.__imageItem.setColormap(widget.getDefaultColormap()) widget.addItem(self.__imageItem) + widget.setActiveImage(self.__imageItem) widget.setKeepDataAspectRatio(True) widget.getXAxis().setLabel("X") diff --git a/src/silx/gui/data/NXdataWidgets.py b/src/silx/gui/data/NXdataWidgets.py index 28c2169e38..147bcfcac9 100644 --- a/src/silx/gui/data/NXdataWidgets.py +++ b/src/silx/gui/data/NXdataWidgets.py @@ -594,6 +594,7 @@ def _updateImage(self): imageItem.setColormap(self._plot.getDefaultColormap()) imageItem.setAggregationMode(self.getAggregationModeAction().getAggregationMode()) self._plot.addItem(imageItem) + self._plot.setActiveImage(imageItem) else: xaxisscale, yaxisscale = self._axis_scales