Reduce logging from modemanager
This commit is contained in:
parent
210fdf9569
commit
158301d3df
@ -50,6 +50,8 @@ class BaseKeyParser(QObject):
|
||||
chain: execute() was called via a chain-like keybinding
|
||||
special: execute() was called via a special keybinding
|
||||
|
||||
do_log: Whether to log keypresses or not.
|
||||
|
||||
Attributes:
|
||||
bindings: Bound keybindings
|
||||
special_bindings: Bound special bindings (<Foo>).
|
||||
@ -67,6 +69,7 @@ class BaseKeyParser(QObject):
|
||||
"""
|
||||
|
||||
keystring_updated = pyqtSignal(str)
|
||||
do_log = True
|
||||
|
||||
Match = enum('partial', 'definitive', 'ambiguous', 'none')
|
||||
Type = enum('chain', 'special')
|
||||
@ -141,7 +144,9 @@ class BaseKeyParser(QObject):
|
||||
try:
|
||||
cmdstr = self.special_bindings[modstr + keystr]
|
||||
except KeyError:
|
||||
logger.debug("No binding found for {}.".format(modstr + keystr))
|
||||
if self.do_log:
|
||||
logger.debug("No binding found for {}.".format(
|
||||
modstr + keystr))
|
||||
return False
|
||||
self.execute(cmdstr, self.Type.special)
|
||||
return True
|
||||
@ -176,17 +181,20 @@ class BaseKeyParser(QObject):
|
||||
"""
|
||||
txt = e.text()
|
||||
key = e.key()
|
||||
logger.debug("Got key: {} / text: '{}'".format(key, txt))
|
||||
if self.do_log:
|
||||
logger.debug("Got key: {} / text: '{}'".format(key, txt))
|
||||
|
||||
if key == Qt.Key_Escape:
|
||||
logger.debug("Escape pressed, discarding '{}'.".format(
|
||||
self._keystring))
|
||||
if self.do_log:
|
||||
logger.debug("Escape pressed, discarding '{}'.".format(
|
||||
self._keystring))
|
||||
self._keystring = ''
|
||||
return
|
||||
|
||||
if (not txt) or txt not in (string.ascii_letters + string.digits +
|
||||
string.punctuation):
|
||||
logger.debug("Ignoring, no text char")
|
||||
if self.do_log:
|
||||
logger.debug("Ignoring, no text char")
|
||||
return False
|
||||
|
||||
self._stop_delayed_exec()
|
||||
@ -201,18 +209,24 @@ class BaseKeyParser(QObject):
|
||||
match, binding = self._match_key(cmd_input)
|
||||
|
||||
if match == self.Match.definitive:
|
||||
logger.debug("Definitive match for '{}'.".format(self._keystring))
|
||||
if self.do_log:
|
||||
logger.debug("Definitive match for '{}'.".format(
|
||||
self._keystring))
|
||||
self._keystring = ''
|
||||
self.execute(binding, self.Type.chain, count)
|
||||
elif match == self.Match.ambiguous:
|
||||
logger.debug("Ambigious match for '{}'.".format(self._keystring))
|
||||
if self.do_log:
|
||||
logger.debug("Ambigious match for '{}'.".format(
|
||||
self._keystring))
|
||||
self._handle_ambiguous_match(binding, count)
|
||||
elif match == self.Match.partial:
|
||||
logger.debug("No match for '{}' (added {})".format(
|
||||
self._keystring, txt))
|
||||
if self.do_log:
|
||||
logger.debug("No match for '{}' (added {})".format(
|
||||
self._keystring, txt))
|
||||
elif match == self.Match.none:
|
||||
logger.debug("Giving up with '{}', no matches".format(
|
||||
self._keystring))
|
||||
if self.do_log:
|
||||
logger.debug("Giving up with '{}', no matches".format(
|
||||
self._keystring))
|
||||
self._keystring = ''
|
||||
return False
|
||||
return True
|
||||
@ -259,7 +273,8 @@ class BaseKeyParser(QObject):
|
||||
def _stop_delayed_exec(self):
|
||||
"""Stop a delayed execution if any is running."""
|
||||
if self._timer is not None:
|
||||
logger.debug("Stopping delayed execution.")
|
||||
if self.do_log:
|
||||
logger.debug("Stopping delayed execution.")
|
||||
self._timer.stop()
|
||||
self._timer = None
|
||||
|
||||
@ -270,7 +285,8 @@ class BaseKeyParser(QObject):
|
||||
binding: The command-string to execute.
|
||||
count: The count to pass.
|
||||
"""
|
||||
logger.debug("Ambiguous match for '{}'".format(self._keystring))
|
||||
if self.do_log:
|
||||
logger.debug("Ambiguous match for '{}'".format(self._keystring))
|
||||
time = config.get('input', 'timeout')
|
||||
if time == 0:
|
||||
# execute immediately
|
||||
@ -278,8 +294,9 @@ class BaseKeyParser(QObject):
|
||||
self.execute(binding, self.Type.chain, count)
|
||||
else:
|
||||
# execute in `time' ms
|
||||
logger.debug("Scheduling execution of {} in {}ms".format(binding,
|
||||
time))
|
||||
if self.do_log:
|
||||
logger.debug("Scheduling execution of {} in {}ms".format(
|
||||
binding, time))
|
||||
self._timer = Timer(self, 'ambigious_match')
|
||||
self._timer.setSingleShot(True)
|
||||
self._timer.setInterval(time)
|
||||
@ -296,7 +313,8 @@ class BaseKeyParser(QObject):
|
||||
Emit:
|
||||
keystring_updated to do a delayed update.
|
||||
"""
|
||||
logger.debug("Executing delayed command now!")
|
||||
if self.do_log:
|
||||
logger.debug("Executing delayed command now!")
|
||||
self._timer = None
|
||||
self._keystring = ''
|
||||
self.keystring_updated.emit(self._keystring)
|
||||
|
@ -51,8 +51,9 @@ class CommandKeyParser(BaseKeyParser):
|
||||
try:
|
||||
self.commandmanager.run(cmdstr, count=count)
|
||||
except ArgumentCountError:
|
||||
logger.debug("Filling statusbar with partial command {}".format(
|
||||
cmdstr))
|
||||
if self.do_log:
|
||||
logger.debug("Filling statusbar with partial command "
|
||||
"{}".format(cmdstr))
|
||||
message.set_cmd_text(':{} '.format(cmdstr))
|
||||
except (CommandMetaError, CommandError) as e:
|
||||
message.error(e)
|
||||
@ -71,6 +72,8 @@ class PassthroughKeyParser(CommandKeyParser):
|
||||
_confsect: The config section to use.
|
||||
"""
|
||||
|
||||
do_log = False
|
||||
|
||||
def __init__(self, confsect, parent=None, warn=True):
|
||||
"""Constructor.
|
||||
|
||||
@ -80,6 +83,7 @@ class PassthroughKeyParser(CommandKeyParser):
|
||||
warn: Whether to warn if an ignored key was bound.
|
||||
"""
|
||||
super().__init__(parent, supports_chains=False)
|
||||
self.log = False
|
||||
self.warn_on_keychains = warn
|
||||
self.read_config(confsect)
|
||||
self._confsect = confsect
|
||||
|
@ -124,10 +124,12 @@ class ModeManager(QObject):
|
||||
True if event should be filtered, False otherwise.
|
||||
"""
|
||||
handler = self._handlers[self.mode]
|
||||
logger.debug("calling handler {}".format(handler.__qualname__))
|
||||
if self.mode != 'insert':
|
||||
logger.debug("got keypress in mode {} - calling handler {}".format(
|
||||
self.mode, handler.__qualname__))
|
||||
handled = handler(event) if handler is not None else False
|
||||
|
||||
is_non_alnum = event.modifiers() or not event.text().strip()
|
||||
is_non_alnum = bool(event.modifiers()) or not event.text().strip()
|
||||
|
||||
if handled:
|
||||
filter_this = True
|
||||
@ -141,11 +143,12 @@ class ModeManager(QObject):
|
||||
if not filter_this:
|
||||
self._releaseevents_to_pass.append(event)
|
||||
|
||||
logger.debug("handled: {}, forward-unbound-keys: {}, passthrough: {}, "
|
||||
"is_non_alnum: {} --> filter: {}".format(
|
||||
handled, self._forward_unbound_keys,
|
||||
self.mode in self.passthrough, is_non_alnum,
|
||||
filter_this))
|
||||
if self.mode != 'insert':
|
||||
logger.debug("handled: {}, forward-unbound-keys: {}, passthrough: "
|
||||
"{}, is_non_alnum: {} --> filter: {}".format(
|
||||
handled, self._forward_unbound_keys,
|
||||
self.mode in self.passthrough, is_non_alnum,
|
||||
filter_this))
|
||||
return filter_this
|
||||
|
||||
def _eventFilter_keyrelease(self, event):
|
||||
@ -165,7 +168,8 @@ class ModeManager(QObject):
|
||||
filter_this = False
|
||||
else:
|
||||
filter_this = True
|
||||
logger.debug("filter: {}".format(filter_this))
|
||||
if self.mode != 'insert':
|
||||
logger.debug("filter: {}".format(filter_this))
|
||||
return filter_this
|
||||
|
||||
def register(self, mode, handler, passthrough=False):
|
||||
@ -258,15 +262,11 @@ class ModeManager(QObject):
|
||||
if not isinstance(obj, QWindow):
|
||||
# We already handled this same event at some point earlier, so
|
||||
# we're not interested in it anymore.
|
||||
logger.debug("Ignoring event {} for {}".format(
|
||||
debug.qenum_key(QEvent, typ), obj.__class__.__name__))
|
||||
return False
|
||||
if QApplication.instance().activeWindow() is not self.mainwindow:
|
||||
# Some other window (print dialog, etc.) is focused so we pass
|
||||
# the event through.
|
||||
return False
|
||||
logger.debug("Got event {} for {} in mode {}".format(
|
||||
debug.qenum_key(QEvent, typ), obj.__class__.__name__, self.mode))
|
||||
|
||||
if typ == QEvent.KeyPress:
|
||||
return self._eventFilter_keypress(event)
|
||||
|
Loading…
Reference in New Issue
Block a user