From 6311deb6b0620972d58adc8b3b164a8c90466176 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 24 Apr 2014 18:31:01 +0200 Subject: [PATCH] Read unbound-keys setting only once --- TODO | 1 - qutebrowser/app.py | 2 +- qutebrowser/utils/modemanager.py | 16 +++++++++++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/TODO b/TODO index da196003d..b9c514f5c 100644 --- a/TODO +++ b/TODO @@ -3,7 +3,6 @@ keyparser foo - Create a SimpleKeyParser and inherit KeyParser from that. - Handle keybind to get out of insert mode (e.g. esc) -- Read unbound-keys setting only once - Add more element-selection-detection code (with options?) based on: -> javascript: http://stackoverflow.com/a/2848120/2085149 -> microFocusChanged and check active element via: diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 333a2178a..f78de1f4f 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -284,7 +284,7 @@ class QuteBrowser(QApplication): # config self.config.style_changed.connect(style.invalidate_caches) for obj in [tabs, completion, self.mainwindow, config.cmd_history, - websettings, kp["normal"]]: + websettings, kp["normal"], modemanager.manager]: self.config.changed.connect(obj.on_config_changed) # statusbar diff --git a/qutebrowser/utils/modemanager.py b/qutebrowser/utils/modemanager.py index 75a16486a..6174f7b8a 100644 --- a/qutebrowser/utils/modemanager.py +++ b/qutebrowser/utils/modemanager.py @@ -23,7 +23,7 @@ Module attributes: import logging -from PyQt5.QtCore import pyqtSignal, QObject, QEvent +from PyQt5.QtCore import pyqtSignal, pyqtSlot, QObject, QEvent import qutebrowser.config.config as config @@ -72,13 +72,14 @@ class ModeManager(QObject): _handlers: A dictionary of modes and their handlers. _mode_stack: A list of the modes we're currently in, with the active one on the right. + _forward_unbound_keys: If we should forward unbound keys. Signals: entered: Emitted when a mode is entered. arg: Name of the entered mode. left: Emitted when a mode is left. arg: Name of the left mode. - key_pressed; A key was pressed. + key_pressed: A key was pressed. """ entered = pyqtSignal(str) @@ -90,6 +91,8 @@ class ModeManager(QObject): self._handlers = {} self.passthrough = [] self._mode_stack = [] + self._forward_unbound_keys = config.get('general', + 'forward_unbound_keys') @property def mode(self): @@ -147,6 +150,13 @@ class ModeManager(QObject): logging.debug("New mode stack: {}".format(self._mode_stack)) self.left.emit(mode) + @pyqtSlot(str, str) + def on_config_changed(self, section, option): + """Update local setting when config changed.""" + if (section, option) == ('general', 'forward_unbound_keys'): + self._forward_unbound_keys = config.get('general', + 'forward_unbound_keys') + def eventFilter(self, _obj, evt): """Filter all events based on the currently set mode. @@ -179,7 +189,7 @@ class ModeManager(QObject): handled = False if handled: return True - elif config.get('general', 'forward_unbound_keys'): + elif self._forward_unbound_keys: return False else: return True