diff --git a/src/aare/gui/widgets/wheel_value_guard.py b/src/aare/gui/widgets/wheel_value_guard.py index b4975fc9..7697de8e 100644 --- a/src/aare/gui/widgets/wheel_value_guard.py +++ b/src/aare/gui/widgets/wheel_value_guard.py @@ -46,3 +46,37 @@ class WheelValueGuard(QObject): QApplication.sendEvent(area.viewport(), relayed) return True return super().eventFilter(obj, event) + + +if __name__ == "__main__": + # ponytail: smallest check that fails if the guard logic breaks + import os + + os.environ.setdefault("QT_QPA_PLATFORM", "offscreen") + from PySide6.QtCore import QPoint, QPointF + + app = QApplication([]) + guard = WheelValueGuard() + app.installEventFilter(guard) + slider = QSlider(Qt.Orientation.Horizontal) + slider.setRange(0, 100) + slider.setValue(50) + slider.show() + + def wheel(buttons): + return QWheelEvent( + QPointF(5, 5), + QPointF(5, 5), + QPoint(0, 0), + QPoint(0, 120), + buttons, + Qt.KeyboardModifier.NoModifier, + Qt.ScrollPhase.NoScrollPhase, + False, + ) + + QApplication.sendEvent(slider, wheel(Qt.MouseButton.NoButton)) + assert slider.value() == 50, "bare wheel must not adjust the slider" + QApplication.sendEvent(slider, wheel(Qt.MouseButton.RightButton)) + assert slider.value() != 50, "right-button + wheel must adjust the slider" + print("gude")