Add a qenum_key debug method
This commit is contained in:
parent
59c8d6f9d1
commit
b905b44b07
@ -250,14 +250,14 @@ class ModeManager(QObject):
|
|||||||
# We already handled this same event at some point earlier, so
|
# We already handled this same event at some point earlier, so
|
||||||
# we're not interested in it anymore.
|
# we're not interested in it anymore.
|
||||||
logger.debug("Ignoring event {} for {}".format(
|
logger.debug("Ignoring event {} for {}".format(
|
||||||
debug.EVENTS[typ], obj.__class__.__name__))
|
debug.qenum_key(QEvent, typ), obj.__class__.__name__))
|
||||||
return False
|
return False
|
||||||
if QCoreApplication.instance().activeWindow() is not self.mainwindow:
|
if QCoreApplication.instance().activeWindow() is not self.mainwindow:
|
||||||
# Some other window (print dialog, etc.) is focused so we pass
|
# Some other window (print dialog, etc.) is focused so we pass
|
||||||
# the event through.
|
# the event through.
|
||||||
return False
|
return False
|
||||||
logger.debug("Got event {} for {} in mode {}".format(
|
logger.debug("Got event {} for {} in mode {}".format(
|
||||||
debug.EVENTS[typ], obj.__class__.__name__, self.mode))
|
debug.qenum_key(QEvent, typ), obj.__class__.__name__, self.mode))
|
||||||
|
|
||||||
if typ == QEvent.KeyPress:
|
if typ == QEvent.KeyPress:
|
||||||
return self._eventFilter_keypress(event)
|
return self._eventFilter_keypress(event)
|
||||||
|
@ -33,9 +33,6 @@ except ImportError:
|
|||||||
|
|
||||||
import qutebrowser.commands.utils as cmdutils
|
import qutebrowser.commands.utils as cmdutils
|
||||||
|
|
||||||
EVENTS = {n: x for x, n in vars(QEvent).items()
|
|
||||||
if isinstance(n, QEvent.Type)}
|
|
||||||
|
|
||||||
|
|
||||||
def log_events(klass):
|
def log_events(klass):
|
||||||
"""Class decorator to log Qt events."""
|
"""Class decorator to log Qt events."""
|
||||||
@ -45,7 +42,7 @@ def log_events(klass):
|
|||||||
def new_event(self, e, *args, **kwargs):
|
def new_event(self, e, *args, **kwargs):
|
||||||
"""Wrapper for event() which logs events."""
|
"""Wrapper for event() which logs events."""
|
||||||
logger.debug("Event in {}: {}".format(klass.__name__,
|
logger.debug("Event in {}: {}".format(klass.__name__,
|
||||||
EVENTS[e.type()]))
|
qenum_key(QEvent, e.type())))
|
||||||
return old_event(self, e, *args, **kwargs)
|
return old_event(self, e, *args, **kwargs)
|
||||||
|
|
||||||
klass.event = new_event
|
klass.event = new_event
|
||||||
@ -87,3 +84,27 @@ def trace_lines(do_trace):
|
|||||||
sys.settrace(trace)
|
sys.settrace(trace)
|
||||||
else:
|
else:
|
||||||
sys.settrace(None)
|
sys.settrace(None)
|
||||||
|
|
||||||
|
|
||||||
|
def qenum_key(base, value):
|
||||||
|
"""Convert a Qt Enum value to its key as a string.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
base: The object the enum is in, e.g. QFrame.
|
||||||
|
value: The value to get.
|
||||||
|
|
||||||
|
Return:
|
||||||
|
The key associated with the value as a string, or None.
|
||||||
|
"""
|
||||||
|
klass = value.__class__
|
||||||
|
try:
|
||||||
|
idx = klass.staticMetaObject.indexOfEnumerator(klass.__name__)
|
||||||
|
except AttributeError:
|
||||||
|
idx = -1
|
||||||
|
if idx != -1:
|
||||||
|
return klass.staticMetaObject.enumerator(idx).valueToKey(value)
|
||||||
|
else:
|
||||||
|
for name, obj in vars(base).items():
|
||||||
|
if isinstance(obj, klass) and obj == value:
|
||||||
|
return name
|
||||||
|
return None
|
||||||
|
Loading…
Reference in New Issue
Block a user