This commit is contained in:
Florian Bruhin 2014-06-25 21:23:22 +02:00
parent 09641d96f3
commit 37ccac39d6
4 changed files with 29 additions and 36 deletions

View File

@ -93,6 +93,15 @@ class BaseKeyParser(QObject):
self.__class__.__name__, self._supports_count, self.__class__.__name__, self._supports_count,
self._supports_chains) self._supports_chains)
def _debug_log(self, message):
"""Log a message to the debug log if logging is active.
Args:
message: The message to log.
"""
if self.do_log:
logger.debug(message)
def _normalize_keystr(self, keystr): def _normalize_keystr(self, keystr):
"""Normalize a keystring like Ctrl-Q to a keystring like Ctrl+Q. """Normalize a keystring like Ctrl-Q to a keystring like Ctrl+Q.
@ -144,9 +153,7 @@ class BaseKeyParser(QObject):
try: try:
cmdstr = self.special_bindings[modstr + keystr] cmdstr = self.special_bindings[modstr + keystr]
except KeyError: except KeyError:
if self.do_log: self._debug_log("No binding found for {}.".format(modstr + keystr))
logger.debug("No binding found for {}.".format(
modstr + keystr))
return False return False
self.execute(cmdstr, self.Type.special) self.execute(cmdstr, self.Type.special)
return True return True
@ -181,20 +188,17 @@ class BaseKeyParser(QObject):
""" """
txt = e.text() txt = e.text()
key = e.key() key = e.key()
if self.do_log: self._debug_log("Got key: {} / text: '{}'".format(key, txt))
logger.debug("Got key: {} / text: '{}'".format(key, txt))
if key == Qt.Key_Escape: if key == Qt.Key_Escape:
if self.do_log: self._debug_log("Escape pressed, discarding '{}'.".format(
logger.debug("Escape pressed, discarding '{}'.".format(
self._keystring)) self._keystring))
self._keystring = '' self._keystring = ''
return return
if (not txt) or txt not in (string.ascii_letters + string.digits + if (not txt) or txt not in (string.ascii_letters + string.digits +
string.punctuation): string.punctuation):
if self.do_log: self._debug_log("Ignoring, no text char")
logger.debug("Ignoring, no text char")
return False return False
self._stop_delayed_exec() self._stop_delayed_exec()
@ -209,23 +213,19 @@ class BaseKeyParser(QObject):
match, binding = self._match_key(cmd_input) match, binding = self._match_key(cmd_input)
if match == self.Match.definitive: if match == self.Match.definitive:
if self.do_log: self._debug_log("Definitive match for '{}'.".format(
logger.debug("Definitive match for '{}'.".format(
self._keystring)) self._keystring))
self._keystring = '' self._keystring = ''
self.execute(binding, self.Type.chain, count) self.execute(binding, self.Type.chain, count)
elif match == self.Match.ambiguous: elif match == self.Match.ambiguous:
if self.do_log: self._debug_log("Ambigious match for '{}'.".format(
logger.debug("Ambigious match for '{}'.".format(
self._keystring)) self._keystring))
self._handle_ambiguous_match(binding, count) self._handle_ambiguous_match(binding, count)
elif match == self.Match.partial: elif match == self.Match.partial:
if self.do_log: self._debug_log("No match for '{}' (added {})".format(
logger.debug("No match for '{}' (added {})".format(
self._keystring, txt)) self._keystring, txt))
elif match == self.Match.none: elif match == self.Match.none:
if self.do_log: self._debug_log("Giving up with '{}', no matches".format(
logger.debug("Giving up with '{}', no matches".format(
self._keystring)) self._keystring))
self._keystring = '' self._keystring = ''
return False return False
@ -285,8 +285,7 @@ class BaseKeyParser(QObject):
binding: The command-string to execute. binding: The command-string to execute.
count: The count to pass. count: The count to pass.
""" """
if self.do_log: self._debug_log("Ambiguous match for '{}'".format(self._keystring))
logger.debug("Ambiguous match for '{}'".format(self._keystring))
time = config.get('input', 'timeout') time = config.get('input', 'timeout')
if time == 0: if time == 0:
# execute immediately # execute immediately
@ -294,8 +293,7 @@ class BaseKeyParser(QObject):
self.execute(binding, self.Type.chain, count) self.execute(binding, self.Type.chain, count)
else: else:
# execute in `time' ms # execute in `time' ms
if self.do_log: self._debug_log("Scheduling execution of {} in {}ms".format(
logger.debug("Scheduling execution of {} in {}ms".format(
binding, time)) binding, time))
self._timer = Timer(self, 'ambigious_match') self._timer = Timer(self, 'ambigious_match')
self._timer.setSingleShot(True) self._timer.setSingleShot(True)
@ -313,8 +311,7 @@ class BaseKeyParser(QObject):
Emit: Emit:
keystring_updated to do a delayed update. keystring_updated to do a delayed update.
""" """
if self.do_log: self._debug_log("Executing delayed command now!")
logger.debug("Executing delayed command now!")
self._timer = None self._timer = None
self._keystring = '' self._keystring = ''
self.keystring_updated.emit(self._keystring) self.keystring_updated.emit(self._keystring)

View File

@ -25,7 +25,6 @@ import qutebrowser.utils.message as message
from qutebrowser.commands.managers import CommandManager from qutebrowser.commands.managers import CommandManager
from qutebrowser.commands.exceptions import ( from qutebrowser.commands.exceptions import (
ArgumentCountError, CommandMetaError, CommandError) ArgumentCountError, CommandMetaError, CommandError)
from qutebrowser.utils.log import keyboard as logger
class CommandKeyParser(BaseKeyParser): class CommandKeyParser(BaseKeyParser):
@ -51,9 +50,8 @@ class CommandKeyParser(BaseKeyParser):
try: try:
self.commandmanager.run(cmdstr, count=count) self.commandmanager.run(cmdstr, count=count)
except ArgumentCountError: except ArgumentCountError:
if self.do_log: self._debug_log("Filling statusbar with partial command {}".format(
logger.debug("Filling statusbar with partial command " cmdstr))
"{}".format(cmdstr))
message.set_cmd_text(':{} '.format(cmdstr)) message.set_cmd_text(':{} '.format(cmdstr))
except (CommandMetaError, CommandError) as e: except (CommandMetaError, CommandError) as e:
message.error(e) message.error(e)

View File

@ -29,7 +29,6 @@ from PyQt5.QtWidgets import QApplication
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.commands.utils as cmdutils import qutebrowser.commands.utils as cmdutils
import qutebrowser.utils.debug as debug
from qutebrowser.utils.log import modes as logger from qutebrowser.utils.log import modes as logger

View File

@ -20,8 +20,7 @@
"""Our own QNetworkAccessManager.""" """Our own QNetworkAccessManager."""
from PyQt5.QtCore import pyqtSlot from PyQt5.QtCore import pyqtSlot
from PyQt5.QtNetwork import (QNetworkAccessManager, QNetworkReply, from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkReply
QNetworkRequest)
try: try:
from PyQt5.QtNetwork import QSslSocket from PyQt5.QtNetwork import QSslSocket