diff --git a/src/silx/gui/data/DataViews.py b/src/silx/gui/data/DataViews.py index f04add1e7c..5107227965 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" @@ -1074,30 +1073,25 @@ 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.setActiveImage(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): @@ -1108,16 +1102,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 @@ -1336,7 +1322,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 +1812,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 +1848,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) 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 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.