forked from M-Labs/artiq
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 sipyco import pyon
|
||||||
|
|
||||||
from artiq import __artiq_dir__ as artiq_dir
|
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.gui.entries import procdesc_to_entry
|
||||||
from artiq.master.worker import Worker, log_worker_exception
|
from artiq.master.worker import Worker, log_worker_exception
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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):
|
class _ArgumentEditor(QtWidgets.QTreeWidget):
|
||||||
def __init__(self, dock):
|
def __init__(self, dock):
|
||||||
QtWidgets.QTreeWidget.__init__(self)
|
QtWidgets.QTreeWidget.__init__(self)
|
||||||
|
@ -46,7 +38,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
|
||||||
self.setStyleSheet("QTreeWidget {background: " +
|
self.setStyleSheet("QTreeWidget {background: " +
|
||||||
self.palette().midlight().color().name() + " ;}")
|
self.palette().midlight().color().name() + " ;}")
|
||||||
|
|
||||||
self.viewport().installEventFilter(_WheelFilter(self.viewport()))
|
self.viewport().installEventFilter(WheelFilter(self.viewport(), True))
|
||||||
|
|
||||||
self._groups = dict()
|
self._groups = dict()
|
||||||
self._arg_to_widgets = 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.entries import procdesc_to_entry, ScanEntry
|
||||||
from artiq.gui.fuzzy_select import FuzzySelectWidget
|
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__)
|
logger = logging.getLogger(__name__)
|
||||||
|
@ -23,15 +24,6 @@ logger = logging.getLogger(__name__)
|
||||||
# 2. file:<class name>@<file 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):
|
class _ArgumentEditor(QtWidgets.QTreeWidget):
|
||||||
def __init__(self, manager, dock, expurl):
|
def __init__(self, manager, dock, expurl):
|
||||||
self.manager = manager
|
self.manager = manager
|
||||||
|
@ -55,7 +47,7 @@ class _ArgumentEditor(QtWidgets.QTreeWidget):
|
||||||
self.setStyleSheet("QTreeWidget {background: " +
|
self.setStyleSheet("QTreeWidget {background: " +
|
||||||
self.palette().midlight().color().name() + " ;}")
|
self.palette().midlight().color().name() + " ;}")
|
||||||
|
|
||||||
self.viewport().installEventFilter(_WheelFilter(self.viewport()))
|
self.viewport().installEventFilter(WheelFilter(self.viewport(), True))
|
||||||
|
|
||||||
self._groups = dict()
|
self._groups = dict()
|
||||||
self._arg_to_widgets = dict()
|
self._arg_to_widgets = dict()
|
||||||
|
|
|
@ -16,10 +16,16 @@ def log_level_to_name(level):
|
||||||
return "DEBUG"
|
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):
|
def eventFilter(self, obj, event):
|
||||||
if (event.type() == QtCore.QEvent.Wheel and
|
if event.type() != QtCore.QEvent.Wheel:
|
||||||
event.modifiers() == QtCore.Qt.NoModifier):
|
return False
|
||||||
|
has_modifier = event.modifiers() != QtCore.Qt.NoModifier
|
||||||
|
if has_modifier == self.ignore_with_modifier:
|
||||||
event.ignore()
|
event.ignore()
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
@ -27,7 +33,7 @@ class _WheelFilter(QtCore.QObject):
|
||||||
|
|
||||||
def disable_scroll_wheel(widget):
|
def disable_scroll_wheel(widget):
|
||||||
widget.setFocusPolicy(QtCore.Qt.StrongFocus)
|
widget.setFocusPolicy(QtCore.Qt.StrongFocus)
|
||||||
widget.installEventFilter(_WheelFilter(widget))
|
widget.installEventFilter(WheelFilter(widget))
|
||||||
|
|
||||||
|
|
||||||
class QDockWidgetCloseDetect(QtWidgets.QDockWidget):
|
class QDockWidgetCloseDetect(QtWidgets.QDockWidget):
|
||||||
|
|
Loading…
Reference in New Issue