Refresh keybinds when config changes
This commit is contained in:
parent
16afba032f
commit
7c64e8846a
@ -141,6 +141,7 @@ class QuteBrowser(QApplication):
|
||||
self.config.changed.connect(self.mainwindow.on_config_changed)
|
||||
self.config.changed.connect(config.cmd_history.on_config_changed)
|
||||
self.config.changed.connect(websettings.on_config_changed)
|
||||
self.config.changed.connect(self.keyparser.on_config_changed)
|
||||
|
||||
self.mainwindow.show()
|
||||
self._python_hacks()
|
||||
@ -199,7 +200,6 @@ class QuteBrowser(QApplication):
|
||||
else:
|
||||
func = cmd.handler.__name__
|
||||
logging.debug("Registered command: {} -> {}".format(key, func))
|
||||
self.keyparser.from_config_sect(config.config['keybind'])
|
||||
|
||||
def _process_init_args(self):
|
||||
"""Process initial positional args.
|
||||
|
@ -20,9 +20,10 @@
|
||||
import re
|
||||
import logging
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, Qt, QObject
|
||||
from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QObject
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
|
||||
import qutebrowser.config.config as config
|
||||
from qutebrowser.commands.parsers import (CommandParser, ArgumentCountError,
|
||||
NoSuchCommandError)
|
||||
|
||||
@ -60,6 +61,7 @@ class KeyParser(QObject):
|
||||
self._keystring = ''
|
||||
self._bindings = {}
|
||||
self._modifier_bindings = {}
|
||||
self.read_config()
|
||||
|
||||
def _handle_modifier_key(self, e):
|
||||
"""Handle a new keypress with modifiers.
|
||||
@ -228,15 +230,18 @@ class KeyParser(QObject):
|
||||
self.set_cmd_text.emit(':{} '.format(cmdstr))
|
||||
return
|
||||
|
||||
def from_config_sect(self, sect):
|
||||
"""Load keybindings from a ConfigParser section.
|
||||
@pyqtSlot(str, str, object)
|
||||
def on_config_changed(self, section, option, value):
|
||||
if section == 'keybind':
|
||||
self.read_config()
|
||||
|
||||
def read_config(self):
|
||||
"""Read the configuration.
|
||||
|
||||
Config format: key = command, e.g.:
|
||||
gg = scrollstart
|
||||
|
||||
Args:
|
||||
sect: The section to get the keybindings from.
|
||||
"""
|
||||
sect = config.config['keybind']
|
||||
if not sect.items():
|
||||
logging.warn("No keybindings defined!")
|
||||
for (key, cmd) in sect.items():
|
||||
|
Loading…
Reference in New Issue
Block a user