Make new key config work (readonly)
This commit is contained in:
parent
64183b5a26
commit
6f03f08111
@ -37,7 +37,7 @@ from PyQt5.QtCore import (pyqtSlot, QTimer, QEventLoop, Qt, QStandardPaths,
|
||||
import qutebrowser
|
||||
from qutebrowser.commands import userscripts, runners, cmdutils
|
||||
from qutebrowser.config import (style, config, websettings, iniparsers,
|
||||
lineparser, configtypes)
|
||||
lineparser, configtypes, keyconfparser)
|
||||
from qutebrowser.network import qutescheme, proxy
|
||||
from qutebrowser.browser import quickmarks, cookies, downloads, cache
|
||||
from qutebrowser.widgets import mainwindow, console, crash
|
||||
@ -190,6 +190,19 @@ class Application(QApplication):
|
||||
msgbox.exec_()
|
||||
# We didn't really initialize much so far, so we just quit hard.
|
||||
sys.exit(1)
|
||||
try:
|
||||
self.keyconfig = keyconfparser.KeyConfigParser(confdir, 'keys')
|
||||
except keyconfparser.KeyConfigError as e:
|
||||
log.init.exception(e)
|
||||
errstr = "Error while reading key config:\n"
|
||||
if hasattr(e, 'lineno'):
|
||||
errstr += "In line {}: ".format(e.lineno)
|
||||
errstr += str(e)
|
||||
msgbox = QMessageBox(QMessageBox.Critical,
|
||||
"Error while reading key config!", errstr)
|
||||
msgbox.exec_()
|
||||
# We didn't really initialize much so far, so we just quit hard.
|
||||
sys.exit(1)
|
||||
self.stateconfig = iniparsers.ReadWriteConfigParser(confdir, 'state')
|
||||
self.cmd_history = lineparser.LineConfigParser(
|
||||
confdir, 'cmd_history', ('completion', 'history-length'))
|
||||
@ -202,14 +215,13 @@ class Application(QApplication):
|
||||
utypes.KeyMode.hint:
|
||||
modeparsers.HintKeyParser(self),
|
||||
utypes.KeyMode.insert:
|
||||
keyparser.PassthroughKeyParser('keybind.insert', self),
|
||||
keyparser.PassthroughKeyParser('insert', self),
|
||||
utypes.KeyMode.passthrough:
|
||||
keyparser.PassthroughKeyParser('keybind.passthrough', self),
|
||||
keyparser.PassthroughKeyParser('passthrough', self),
|
||||
utypes.KeyMode.command:
|
||||
keyparser.PassthroughKeyParser('keybind.command', self),
|
||||
keyparser.PassthroughKeyParser('command', self),
|
||||
utypes.KeyMode.prompt:
|
||||
keyparser.PassthroughKeyParser('keybind.prompt', self,
|
||||
warn=False),
|
||||
keyparser.PassthroughKeyParser('prompt', self, warn=False),
|
||||
utypes.KeyMode.yesno:
|
||||
modeparsers.PromptKeyParser(self),
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import re
|
||||
import string
|
||||
import functools
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QObject
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QObject, QCoreApplication
|
||||
|
||||
from qutebrowser.config import config
|
||||
from qutebrowser.utils import usertypes, log, utils
|
||||
@ -57,7 +57,7 @@ class BaseKeyParser(QObject):
|
||||
keychains in a section which does not support them.
|
||||
_keystring: The currently entered key sequence
|
||||
_timer: Timer for delayed execution.
|
||||
_confsectname: The name of the configsection.
|
||||
_modename: The name of the input mode associated with this keyparser.
|
||||
_supports_count: Whether count is supported
|
||||
_supports_chains: Whether keychains are supported
|
||||
|
||||
@ -77,7 +77,7 @@ class BaseKeyParser(QObject):
|
||||
supports_chains=False):
|
||||
super().__init__(parent)
|
||||
self._timer = None
|
||||
self._confsectname = None
|
||||
self._modename = None
|
||||
self._keystring = ''
|
||||
if supports_count is None:
|
||||
supports_count = supports_chains
|
||||
@ -303,28 +303,26 @@ class BaseKeyParser(QObject):
|
||||
self.keystring_updated.emit(self._keystring)
|
||||
return handled
|
||||
|
||||
def read_config(self, sectname=None):
|
||||
def read_config(self, modename=None):
|
||||
"""Read the configuration.
|
||||
|
||||
Config format: key = command, e.g.:
|
||||
<Ctrl+Q> = quit
|
||||
|
||||
Args:
|
||||
sectname: Name of the section to read.
|
||||
modename: Name of the mode to use.
|
||||
"""
|
||||
if sectname is None:
|
||||
if self._confsectname is None:
|
||||
raise ValueError("read_config called with no section, but "
|
||||
if modename is None:
|
||||
if self._modename is None:
|
||||
raise ValueError("read_config called with no mode given, but "
|
||||
"None defined so far!")
|
||||
sectname = self._confsectname
|
||||
modename = self._modename
|
||||
else:
|
||||
self._confsectname = sectname
|
||||
self._modename = modename
|
||||
self.bindings = {}
|
||||
self.special_bindings = {}
|
||||
sect = config.section(sectname)
|
||||
if not sect.items():
|
||||
log.keyboard.warning("No keybindings defined!")
|
||||
for (key, cmd) in sect.items():
|
||||
keyconfparser = QCoreApplication.instance().keyconfig
|
||||
for (key, cmd) in keyconfparser.get_bindings_for(modename).items():
|
||||
if not cmd:
|
||||
continue
|
||||
elif key.startswith('<') and key.endswith('>'):
|
||||
@ -334,8 +332,8 @@ class BaseKeyParser(QObject):
|
||||
self.bindings[key] = cmd
|
||||
elif self.warn_on_keychains:
|
||||
log.keyboard.warning(
|
||||
"Ignoring keychain '{}' in section '{}' because "
|
||||
"keychains are not supported there.".format(key, sectname))
|
||||
"Ignoring keychain '{}' in mode '{}' because "
|
||||
"keychains are not supported there.".format(key, modename))
|
||||
|
||||
def execute(self, cmdstr, keytype, count=None):
|
||||
"""Handle a completed keychain.
|
||||
@ -350,8 +348,8 @@ class BaseKeyParser(QObject):
|
||||
@pyqtSlot(str, str)
|
||||
def on_config_changed(self, section, _option):
|
||||
"""Re-read the config if a keybinding was changed."""
|
||||
if self._confsectname is None:
|
||||
if self._modename is None:
|
||||
raise AttributeError("on_config_changed called but no section "
|
||||
"defined!")
|
||||
if section == self._confsectname:
|
||||
if section == self._modename:
|
||||
self.read_config()
|
||||
|
@ -51,25 +51,25 @@ class PassthroughKeyParser(CommandKeyParser):
|
||||
Used for insert/passthrough modes.
|
||||
|
||||
Attributes:
|
||||
_confsect: The config section to use.
|
||||
_mode: The mode this keyparser is for.
|
||||
"""
|
||||
|
||||
do_log = False
|
||||
|
||||
def __init__(self, confsect, parent=None, warn=True):
|
||||
def __init__(self, mode, parent=None, warn=True):
|
||||
"""Constructor.
|
||||
|
||||
Args:
|
||||
confsect: The config section to use.
|
||||
mode: The mode this keyparser is for.
|
||||
parent: Qt parent.
|
||||
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
|
||||
self.read_config(mode)
|
||||
self._mode = mode
|
||||
|
||||
def __repr__(self):
|
||||
return '<{} confsect={}, warn={})'.format(
|
||||
self.__class__.__name__, self._confsect, self.warn_on_keychains)
|
||||
return '<{} mode={}, warn={})'.format(
|
||||
self.__class__.__name__, self._mode, self.warn_on_keychains)
|
||||
|
@ -41,7 +41,7 @@ class NormalKeyParser(keyparser.CommandKeyParser):
|
||||
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent, supports_count=True, supports_chains=True)
|
||||
self.read_config('keybind')
|
||||
self.read_config('normal')
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}>'.format(self.__class__.__name__)
|
||||
@ -69,8 +69,8 @@ class PromptKeyParser(keyparser.CommandKeyParser):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent, supports_count=False, supports_chains=True)
|
||||
# We don't want an extra section for this in the config, so we just
|
||||
# abuse the keybind.prompt section.
|
||||
self.read_config('keybind.prompt')
|
||||
# abuse the prompt section.
|
||||
self.read_config('prompt')
|
||||
|
||||
def __repr__(self):
|
||||
return '<{}>'.format(self.__class__.__name__)
|
||||
@ -98,7 +98,7 @@ class HintKeyParser(keyparser.CommandKeyParser):
|
||||
super().__init__(parent, supports_count=False, supports_chains=True)
|
||||
self._filtertext = ''
|
||||
self._last_press = LastPress.none
|
||||
self.read_config('keybind.hint')
|
||||
self.read_config('hint')
|
||||
|
||||
def _handle_special_key(self, e):
|
||||
"""Override _handle_special_key to handle string filtering.
|
||||
|
Loading…
Reference in New Issue
Block a user