diff --git a/artiq/browser/experiments.py b/artiq/browser/experiments.py index 23a271eb9..c34ea5832 100644 --- a/artiq/browser/experiments.py +++ b/artiq/browser/experiments.py @@ -10,22 +10,14 @@ import h5py from sipyco import pyon from artiq import __artiq_dir__ as artiq_dir -from artiq.gui.tools import LayoutWidget, log_level_to_name, get_open_file_name +from artiq.gui.tools import (LayoutWidget, WheelFilter, + log_level_to_name, get_open_file_name) from artiq.gui.entries import procdesc_to_entry from artiq.master.worker import Worker, log_worker_exception logger = logging.getLogger(__name__) -class _WheelFilter(QtCore.QObject): - def eventFilter(self, obj, event): - if (event.type() == QtCore.QEvent.Wheel and - event.modifiers() != QtCore.Qt.NoModifier): - event.ignore() - return True - return False - - class _ArgumentEditor(QtWidgets.QTreeWidget): def __init__(self, dock): QtWidgets.QTreeWidget.__init__(self) @@ -46,7 +38,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget): self.setStyleSheet("QTreeWidget {background: " + self.palette().midlight().color().name() + " ;}") - self.viewport().installEventFilter(_WheelFilter(self.viewport())) + self.viewport().installEventFilter(WheelFilter(self.viewport(), True)) self._groups = dict() self._arg_to_widgets = dict() diff --git a/artiq/dashboard/experiments.py b/artiq/dashboard/experiments.py index 254dd05ab..74c3496a9 100644 --- a/artiq/dashboard/experiments.py +++ b/artiq/dashboard/experiments.py @@ -11,7 +11,8 @@ from sipyco import pyon from artiq.gui.entries import procdesc_to_entry, ScanEntry from artiq.gui.fuzzy_select import FuzzySelectWidget -from artiq.gui.tools import LayoutWidget, log_level_to_name, get_open_file_name +from artiq.gui.tools import (LayoutWidget, WheelFilter, + log_level_to_name, get_open_file_name) logger = logging.getLogger(__name__) @@ -23,15 +24,6 @@ logger = logging.getLogger(__name__) # 2. file:@ -class _WheelFilter(QtCore.QObject): - def eventFilter(self, obj, event): - if (event.type() == QtCore.QEvent.Wheel and - event.modifiers() != QtCore.Qt.NoModifier): - event.ignore() - return True - return False - - class _ArgumentEditor(QtWidgets.QTreeWidget): def __init__(self, manager, dock, expurl): self.manager = manager @@ -55,7 +47,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget): self.setStyleSheet("QTreeWidget {background: " + self.palette().midlight().color().name() + " ;}") - self.viewport().installEventFilter(_WheelFilter(self.viewport())) + self.viewport().installEventFilter(WheelFilter(self.viewport(), True)) self._groups = dict() self._arg_to_widgets = dict() diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py index bc681bb77..441da9b81 100644 --- a/artiq/gui/tools.py +++ b/artiq/gui/tools.py @@ -16,10 +16,16 @@ def log_level_to_name(level): return "DEBUG" -class _WheelFilter(QtCore.QObject): +class WheelFilter(QtCore.QObject): + def __init__(self, parent, ignore_with_modifier=False): + super().__init__(parent) + self.ignore_with_modifier = ignore_with_modifier + def eventFilter(self, obj, event): - if (event.type() == QtCore.QEvent.Wheel and - event.modifiers() == QtCore.Qt.NoModifier): + if event.type() != QtCore.QEvent.Wheel: + return False + has_modifier = event.modifiers() != QtCore.Qt.NoModifier + if has_modifier == self.ignore_with_modifier: event.ignore() return True return False @@ -27,7 +33,7 @@ class _WheelFilter(QtCore.QObject): def disable_scroll_wheel(widget): widget.setFocusPolicy(QtCore.Qt.StrongFocus) - widget.installEventFilter(_WheelFilter(widget)) + widget.installEventFilter(WheelFilter(widget)) class QDockWidgetCloseDetect(QtWidgets.QDockWidget):