Add log_events decorator
This commit is contained in:
parent
48d0215a98
commit
46f1a2a0d0
1
TODO
1
TODO
@ -60,7 +60,6 @@ keybind should have completion for commands/arguments
|
||||
Hiding scrollbars
|
||||
Ctrl+A/X to increase/decrease last number in URL
|
||||
command completion gets hidden when doing a new ValueList value
|
||||
log_events class decorator
|
||||
logging contexts
|
||||
|
||||
Qt Bugs
|
||||
|
@ -18,8 +18,10 @@
|
||||
"""Utilities used for debugging."""
|
||||
|
||||
import sys
|
||||
import logging
|
||||
from functools import wraps
|
||||
|
||||
from PyQt5.QtCore import pyqtRemoveInputHook
|
||||
from PyQt5.QtCore import pyqtRemoveInputHook, QEvent
|
||||
|
||||
try:
|
||||
# pylint: disable=import-error
|
||||
@ -29,6 +31,24 @@ except ImportError:
|
||||
|
||||
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):
|
||||
"""Class decorator to log Qt events."""
|
||||
old_event = klass.event
|
||||
|
||||
@wraps(old_event)
|
||||
def new_event(self, e, *args, **kwargs):
|
||||
"""Wrapper for event() which logs events."""
|
||||
logging.debug("Event in {}: {}".format(klass.__name__,
|
||||
EVENTS[e.type()]))
|
||||
return old_event(self, e, *args, **kwargs)
|
||||
|
||||
klass.event = new_event
|
||||
return klass
|
||||
|
||||
|
||||
@cmdutils.register(name='settrace', hide=True)
|
||||
def set_trace():
|
||||
|
Loading…
Reference in New Issue
Block a user