forked from M-Labs/artiq
gui/experiments: prevent comboboxes and spinboxes from stealing focus via mouse wheel
This commit is contained in:
parent
cabcdb3784
commit
277e26434f
|
@ -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"])
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
Loading…
Reference in New Issue