Skip to content

Commit

Permalink
Merge pull request #3 from t20100/pr4174
Browse files Browse the repository at this point in the history
Update for PR silx-kit#4174
  • Loading branch information
EdgarGF93 authored Nov 26, 2024
2 parents 6f074c1 + e6868fe commit b4b2529
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 43 deletions.
47 changes: 13 additions & 34 deletions src/silx/gui/data/DataViews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/silx/gui/data/NXdataWidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 1 addition & 9 deletions src/silx/gui/plot/StackView.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit b4b2529

Please sign in to comment.