From 0cd73af691ff08d76eb1dd33f5bb45e9be2c250a Mon Sep 17 00:00:00 2001 From: jakanakae-envangel Date: Thu, 8 Mar 2018 18:06:54 +0100 Subject: keyinput: Merge keyparser into modeparsers --- qutebrowser/keyinput/keyparser.py | 74 ------------------------------------- qutebrowser/keyinput/modeman.py | 10 ++--- qutebrowser/keyinput/modeparsers.py | 62 +++++++++++++++++++++++++++---- 3 files changed, 60 insertions(+), 86 deletions(-) delete mode 100644 qutebrowser/keyinput/keyparser.py diff --git a/qutebrowser/keyinput/keyparser.py b/qutebrowser/keyinput/keyparser.py deleted file mode 100644 index 0ce123bfc..000000000 --- a/qutebrowser/keyinput/keyparser.py +++ /dev/null @@ -1,74 +0,0 @@ -# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et: - -# Copyright 2014-2018 Florian Bruhin (The Compiler) -# -# This file is part of qutebrowser. -# -# qutebrowser is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# qutebrowser is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with qutebrowser. If not, see . - -"""Advanced keyparsers.""" - -import traceback - -from qutebrowser.keyinput.basekeyparser import BaseKeyParser -from qutebrowser.utils import message, utils -from qutebrowser.commands import runners, cmdexc - - -class CommandKeyParser(BaseKeyParser): - - """KeyChainParser for command bindings. - - Attributes: - _commandrunner: CommandRunner instance. - """ - - def __init__(self, win_id, parent=None, supports_count=None): - super().__init__(win_id, parent, supports_count) - self._commandrunner = runners.CommandRunner(win_id) - - def execute(self, cmdstr, count=None): - try: - self._commandrunner.run(cmdstr, count) - except cmdexc.Error as e: - message.error(str(e), stack=traceback.format_exc()) - - -class PassthroughKeyParser(CommandKeyParser): - - """KeyChainParser which passes through normal keys. - - Used for insert/passthrough modes. - - Attributes: - _mode: The mode this keyparser is for. - """ - - do_log = False - passthrough = True - - def __init__(self, win_id, mode, parent=None): - """Constructor. - - Args: - mode: The mode this keyparser is for. - parent: Qt parent. - warn: Whether to warn if an ignored key was bound. - """ - super().__init__(win_id, parent) - self._read_config(mode) - self._mode = mode - - def __repr__(self): - return utils.get_repr(self, mode=self._mode) diff --git a/qutebrowser/keyinput/modeman.py b/qutebrowser/keyinput/modeman.py index 168efde5b..49a0bf68f 100644 --- a/qutebrowser/keyinput/modeman.py +++ b/qutebrowser/keyinput/modeman.py @@ -25,7 +25,7 @@ import attr from PyQt5.QtCore import pyqtSlot, pyqtSignal, Qt, QObject, QEvent from PyQt5.QtWidgets import QApplication -from qutebrowser.keyinput import modeparsers, keyparser +from qutebrowser.keyinput import modeparsers from qutebrowser.config import config from qutebrowser.commands import cmdexc, cmdutils from qutebrowser.utils import usertypes, log, objreg, utils @@ -67,11 +67,11 @@ def init(win_id, parent): keyparsers = { KM.normal: modeparsers.NormalKeyParser(win_id, modeman), KM.hint: modeparsers.HintKeyParser(win_id, modeman), - KM.insert: keyparser.PassthroughKeyParser(win_id, 'insert', modeman), - KM.passthrough: keyparser.PassthroughKeyParser(win_id, 'passthrough', + KM.insert: modeparsers.PassthroughKeyParser(win_id, 'insert', modeman), + KM.passthrough: modeparsers.PassthroughKeyParser(win_id, 'passthrough', modeman), - KM.command: keyparser.PassthroughKeyParser(win_id, 'command', modeman), - KM.prompt: keyparser.PassthroughKeyParser(win_id, 'prompt', modeman), + KM.command: modeparsers.PassthroughKeyParser(win_id, 'command', modeman), + KM.prompt: modeparsers.PassthroughKeyParser(win_id, 'prompt', modeman), KM.yesno: modeparsers.PromptKeyParser(win_id, modeman), KM.caret: modeparsers.CaretKeyParser(win_id, modeman), KM.set_mark: modeparsers.RegisterKeyParser(win_id, KM.set_mark, diff --git a/qutebrowser/keyinput/modeparsers.py b/qutebrowser/keyinput/modeparsers.py index ce4cb71fa..1f76138e0 100644 --- a/qutebrowser/keyinput/modeparsers.py +++ b/qutebrowser/keyinput/modeparsers.py @@ -29,9 +29,9 @@ import enum from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtGui import QKeySequence -from qutebrowser.commands import cmdexc +from qutebrowser.commands import runners, cmdexc from qutebrowser.config import config -from qutebrowser.keyinput import keyparser, keyutils +from qutebrowser.keyinput import basekeyparser, keyutils from qutebrowser.utils import usertypes, log, message, objreg, utils @@ -39,7 +39,26 @@ STARTCHARS = ":/?" LastPress = enum.Enum('LastPress', ['none', 'filtertext', 'keystring']) -class NormalKeyParser(keyparser.CommandKeyParser): +class CommandKeyParser(basekeyparser.BaseKeyParser): + + """KeyChainParser for command bindings. + + Attributes: + _commandrunner: CommandRunner instance. + """ + + def __init__(self, win_id, parent=None, supports_count=None): + super().__init__(win_id, parent, supports_count) + self._commandrunner = runners.CommandRunner(win_id) + + def execute(self, cmdstr, count=None): + try: + self._commandrunner.run(cmdstr, count) + except cmdexc.Error as e: + message.error(str(e), stack=traceback.format_exc()) + + +class NormalKeyParser(CommandKeyParser): """KeyParser for normal mode with added STARTCHARS detection and more. @@ -127,7 +146,36 @@ class NormalKeyParser(keyparser.CommandKeyParser): pass -class PromptKeyParser(keyparser.CommandKeyParser): +class PassthroughKeyParser(CommandKeyParser): + + """KeyChainParser which passes through normal keys. + + Used for insert/passthrough modes. + + Attributes: + _mode: The mode this keyparser is for. + """ + + do_log = False + passthrough = True + + def __init__(self, win_id, mode, parent=None): + """Constructor. + + Args: + mode: The mode this keyparser is for. + parent: Qt parent. + warn: Whether to warn if an ignored key was bound. + """ + super().__init__(win_id, parent) + self._read_config(mode) + self._mode = mode + + def __repr__(self): + return utils.get_repr(self, mode=self._mode) + + +class PromptKeyParser(CommandKeyParser): """KeyParser for yes/no prompts.""" @@ -139,7 +187,7 @@ class PromptKeyParser(keyparser.CommandKeyParser): return utils.get_repr(self) -class HintKeyParser(keyparser.CommandKeyParser): +class HintKeyParser(CommandKeyParser): """KeyChainParser for hints. @@ -249,7 +297,7 @@ class HintKeyParser(keyparser.CommandKeyParser): hintmanager.handle_partial_key(keystr) -class CaretKeyParser(keyparser.CommandKeyParser): +class CaretKeyParser(CommandKeyParser): """KeyParser for caret mode.""" @@ -260,7 +308,7 @@ class CaretKeyParser(keyparser.CommandKeyParser): self._read_config('caret') -class RegisterKeyParser(keyparser.CommandKeyParser): +class RegisterKeyParser(CommandKeyParser): """KeyParser for modes that record a register key. -- cgit v1.2.3-54-g00ecf