From 2d47eaf8c7cc754323a8a9a7d9a3bd83ada4f3cd Mon Sep 17 00:00:00 2001 From: Sergey Yaroslavtsev Date: Mon, 27 Apr 2026 21:44:12 +0200 Subject: [PATCH] switch to last slice on autorefresh for 3D images --- src/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py | 9 +++++++-- src/PyMca5/PyMcaGui/pymca/PyMcaImageWindow.py | 10 ++++++++++ src/PyMca5/PyMcaGui/pymca/PyMcaMain.py | 2 +- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py b/src/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py index 4229eeede..0d7adfe15 100644 --- a/src/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py +++ b/src/PyMca5/PyMcaGui/io/hdf5/QNexusWidget.py @@ -514,7 +514,7 @@ def dataSourceDestroyed(weakrefReference): if hasattr(self.hdf5Widget, "expandToDepth"): self.hdf5Widget.expandToDepth(0) - def _autoRefreshDatasets(self, source=None): + def _autoRefreshDatasets(self, source=None, moveToLastSlice=True): """ Auto-refresh: re-read datasets and re-plot without re-building the tree. The tree remains fully interactive (click, select, expand). @@ -552,7 +552,10 @@ def _autoRefreshDatasets(self, source=None): # Replot with the cached entry list (always REPLACE). _, selType = self._lastAction.split() - ddict = {'action': 'REPLACE %s' % selType} + ddict = { + 'action': 'REPLACE %s' % selType, + 'refreshtolastslice': moveToLastSlice, + } self.buttonsSlot(ddict, emit=True, entryList=self._autoRefreshEntries) @@ -1176,6 +1179,7 @@ def buttonsSlot(self, ddict, emit=True, entryList=None): sel['selection']['LabelNames'] = cntSelection['aliaslist'] #sel['selection']['aliaslist'] = cntSelection['aliaslist'] sel['selection']['selectiontype'] = selectionType + sel['refreshtolastslice'] = ddict.get('refreshtolastslice', False) if selectionType.upper() == "SCAN": if cntSelection['cntlist'][yCnt].startswith("/"): actualDatasetPath = posixpath.join(entry, @@ -1355,6 +1359,7 @@ def buttonsSlot(self, ddict, emit=True, entryList=None): sel['selection']['cntlist'] = cntSelection['cntlist'] sel['selection']['LabelNames'] = cntSelection['aliaslist'] sel['selection']['selectiontype'] = selectionType + sel['refreshtolastslice'] = ddict.get('refreshtolastslice', False) sel['selection']['plot_yaxis'] = 'right' if selectionType.upper() == "SCAN": sel['scanselection'] = True diff --git a/src/PyMca5/PyMcaGui/pymca/PyMcaImageWindow.py b/src/PyMca5/PyMcaGui/pymca/PyMcaImageWindow.py index 3ad485758..b8d9cc0a6 100644 --- a/src/PyMca5/PyMcaGui/pymca/PyMcaImageWindow.py +++ b/src/PyMca5/PyMcaGui/pymca/PyMcaImageWindow.py @@ -251,9 +251,19 @@ def _addSelection(self, selectionlist): self.slider.setValue(0) self.slider.show() self.setName(legend+" 0") + if sel.get("refreshtolastslice", False) and self._nImages > 1: + self._showLastImageSlice() if self._plotEnabled: self.plotImage(True) + def _showLastImageSlice(self): + if USE_BROWSER: + # Reuse the existing method from FrameBrowser. + self.slider._browser._lastClicked() + else: + # simply set slider to last number possible. + self.slider.setValue(self._nImages - 1) + def _getAxesLabelsFromSelection(self, selection): labels = [] if "x" in selection: diff --git a/src/PyMca5/PyMcaGui/pymca/PyMcaMain.py b/src/PyMca5/PyMcaGui/pymca/PyMcaMain.py index d62b3b33a..531bf8f11 100644 --- a/src/PyMca5/PyMcaGui/pymca/PyMcaMain.py +++ b/src/PyMca5/PyMcaGui/pymca/PyMcaMain.py @@ -446,7 +446,7 @@ def _dispatcherAddSelectionSlot(self, dictOrList): self.imageWindowDict[legend]._addSelection(ddict) return elif self._is2DSelection(ddict): - _logger.info("2D selection") + _logger.debug("2D selection") if self.imageWindowCorrelator is None: self.imageWindowCorrelator = RGBCorrelator.RGBCorrelator() #toadd = True