mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 11:18:27 +08:00
gui: remove copies of _WheelFilter and refactor with parameter
This commit is contained in:
parent
0e8fa8933f
commit
13271cea64
@ -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()
|
||||
|
@ -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 name>@<file 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, 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()
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user