From 0a40159aa80355e9b20c5ee701f16d04e89976ff Mon Sep 17 00:00:00 2001 From: ruyer Date: Wed, 17 Jun 2026 17:21:58 +0200 Subject: [PATCH] [PlotWidget] Allow directive zoom with shortcut ALT and SHIFT like h5web --- src/silx/gui/plot/PlotInteraction.py | 20 +++++++++++++++----- src/silx/gui/plot/backends/BackendOpenGL.py | 2 +- src/silx/gui/plot/tools/menus.py | 6 +++--- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/silx/gui/plot/PlotInteraction.py b/src/silx/gui/plot/PlotInteraction.py index ef8d203c29..e2648d955a 100644 --- a/src/silx/gui/plot/PlotInteraction.py +++ b/src/silx/gui/plot/PlotInteraction.py @@ -1867,18 +1867,28 @@ def _onWheel(self, x: float, y: float, angle: float): if not self.isZoomOnWheelEnabled(): return + if angle == 0: + return plotWidget = self.parent() if plotWidget is None: return # All axes are enabled if keep aspect ratio is on - enabledAxes = ( - EnabledAxes() - if plotWidget.isKeepDataAspectRatio() - else self.getZoomEnabledAxes() - ) + if plotWidget.isKeepDataAspectRatio(): + enabledAxes = EnabledAxes() + else: + modifiers = qt.QApplication.keyboardModifiers() + shiftPressed = modifiers & qt.Qt.ShiftModifier + altPressed = modifiers & qt.Qt.AltModifier + if shiftPressed or altPressed: + enabledAxes = EnabledAxes( + xaxis=altPressed, yaxis=shiftPressed, y2axis=shiftPressed + ) + else: + enabledAxes = self.getZoomEnabledAxes() if enabledAxes.isDisabled(): return scale = 1.1 if angle > 0 else 1.0 / 1.1 + applyZoomToPlot(plotWidget, scale, (x, y), enabledAxes) diff --git a/src/silx/gui/plot/backends/BackendOpenGL.py b/src/silx/gui/plot/backends/BackendOpenGL.py index f080746a66..4fdb11a7b9 100755 --- a/src/silx/gui/plot/backends/BackendOpenGL.py +++ b/src/silx/gui/plot/backends/BackendOpenGL.py @@ -323,7 +323,7 @@ def mouseReleaseEvent(self, event): event.accept() def wheelEvent(self, event): - delta = event.angleDelta().y() + delta = event.angleDelta().x() + event.angleDelta().y() angleInDegrees = delta / 8.0 x, y = qt.getMouseEventPosition(event) self._plot.onMouseWheel(x, y, angleInDegrees) diff --git a/src/silx/gui/plot/tools/menus.py b/src/silx/gui/plot/tools/menus.py index ca8a1ba31f..6373f7040d 100644 --- a/src/silx/gui/plot/tools/menus.py +++ b/src/silx/gui/plot/tools/menus.py @@ -52,9 +52,9 @@ def __init__(self, plot: PlotWidget, parent: qt.QWidget | None = None): self.__plotRef = weakref.ref(plot) self.addSection("Enabled axes") - self.__xAxisAction = qt.QAction("X axis", parent=self) - self.__yAxisAction = qt.QAction("Y left axis", parent=self) - self.__y2AxisAction = qt.QAction("Y right axis", parent=self) + self.__xAxisAction = qt.QAction("X axis (alt)", parent=self) + self.__yAxisAction = qt.QAction("Y left axis (shift)", parent=self) + self.__y2AxisAction = qt.QAction("Y right axis (shift)", parent=self) for action in (self.__xAxisAction, self.__yAxisAction, self.__y2AxisAction): action.setCheckable(True)