From 277e26434ffd66cf1146a8dcea0e2e74be50c5b7 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Mon, 30 Nov 2015 19:53:40 +0800 Subject: [PATCH] gui/experiments: prevent comboboxes and spinboxes from stealing focus via mouse wheel --- artiq/gui/experiments.py | 6 +++--- artiq/gui/log.py | 14 ++------------ artiq/gui/scan.py | 6 ++++++ artiq/gui/tools.py | 29 +++++++++++++++++++++++++++++ 4 files changed, 40 insertions(+), 15 deletions(-) create mode 100644 artiq/gui/tools.py diff --git a/artiq/gui/experiments.py b/artiq/gui/experiments.py index 5ec6ce9a5..8a545720d 100644 --- a/artiq/gui/experiments.py +++ b/artiq/gui/experiments.py @@ -7,15 +7,13 @@ from quamash import QtGui, QtCore from pyqtgraph import dockarea +from artiq.gui.tools import log_level_to_name, disable_scroll_wheel from artiq.gui.scan import ScanController -from artiq.gui.log import log_level_to_name logger = logging.getLogger(__name__) -# TODO: disable mouse wheel on entry widget like QDoubleSpinBox and QComboBox -# (interferes with QTreeWidget scrolling) class _StringEntry(QtGui.QLineEdit): def __init__(self, argument): QtGui.QLineEdit.__init__(self) @@ -53,6 +51,7 @@ class _BooleanEntry(QtGui.QCheckBox): class _EnumerationEntry(QtGui.QComboBox): def __init__(self, argument): QtGui.QComboBox.__init__(self) + disable_scroll_wheel(self) choices = argument["desc"]["choices"] self.addItems(choices) idx = choices.index(argument["state"]) @@ -76,6 +75,7 @@ class _EnumerationEntry(QtGui.QComboBox): class _NumberEntry(QtGui.QDoubleSpinBox): def __init__(self, argument): QtGui.QDoubleSpinBox.__init__(self) + disable_scroll_wheel(self) procdesc = argument["desc"] scale = procdesc["scale"] self.setDecimals(procdesc["ndecimals"]) diff --git a/artiq/gui/log.py b/artiq/gui/log.py index 802864d26..d7b5a000e 100644 --- a/artiq/gui/log.py +++ b/artiq/gui/log.py @@ -6,24 +6,14 @@ from functools import partial from quamash import QtGui, QtCore from pyqtgraph import dockarea, LayoutWidget +from artiq.gui.tools import log_level_to_name + try: QSortFilterProxyModel = QtCore.QSortFilterProxyModel except AttributeError: QSortFilterProxyModel = QtGui.QSortFilterProxyModel -def log_level_to_name(level): - if level >= logging.CRITICAL: - return "CRITICAL" - if level >= logging.ERROR: - return "ERROR" - if level >= logging.WARNING: - return "WARNING" - if level >= logging.INFO: - return "INFO" - return "DEBUG" - - class Model(QtCore.QAbstractTableModel): def __init__(self, init): QtCore.QAbstractTableModel.__init__(self) diff --git a/artiq/gui/scan.py b/artiq/gui/scan.py index 8ef1bbffc..565fdd46b 100644 --- a/artiq/gui/scan.py +++ b/artiq/gui/scan.py @@ -4,6 +4,8 @@ from collections import OrderedDict from quamash import QtGui from pyqtgraph import LayoutWidget +from artiq.gui.tools import disable_scroll_wheel + logger = logging.getLogger(__name__) @@ -14,6 +16,7 @@ class _NoScan(LayoutWidget): scale = procdesc["scale"] self.value = QtGui.QDoubleSpinBox() + disable_scroll_wheel(self.value) self.value.setDecimals(procdesc["ndecimals"]) if procdesc["global_min"] is not None: self.value.setMinimum(procdesc["global_min"]/scale) @@ -58,16 +61,19 @@ class _Range(LayoutWidget): self.addWidget(QtGui.QLabel("Min:"), 0, 0) self.min = QtGui.QDoubleSpinBox() + disable_scroll_wheel(self.min) apply_properties(self.min) self.addWidget(self.min, 0, 1) self.addWidget(QtGui.QLabel("Max:"), 1, 0) self.max = QtGui.QDoubleSpinBox() + disable_scroll_wheel(self.max) apply_properties(self.max) self.addWidget(self.max, 1, 1) self.addWidget(QtGui.QLabel("#Points:"), 2, 0) self.npoints = QtGui.QSpinBox() + disable_scroll_wheel(self.npoints) self.npoints.setMinimum(2) self.npoints.setValue(10) self.addWidget(self.npoints, 2, 1) diff --git a/artiq/gui/tools.py b/artiq/gui/tools.py new file mode 100644 index 000000000..5fa701d81 --- /dev/null +++ b/artiq/gui/tools.py @@ -0,0 +1,29 @@ +import logging + +from quamash import QtCore + + +def log_level_to_name(level): + if level >= logging.CRITICAL: + return "CRITICAL" + if level >= logging.ERROR: + return "ERROR" + if level >= logging.WARNING: + return "WARNING" + if level >= logging.INFO: + return "INFO" + return "DEBUG" + + +class _WheelFilter(QtCore.QObject): + def eventFilter(self, obj, event): + if event.type() == QtCore.QEvent.Wheel: + event.ignore() + return True + else: + return False + + +def disable_scroll_wheel(widget): + widget.setFocusPolicy(QtCore.Qt.StrongFocus) + widget.installEventFilter(_WheelFilter(widget))