From 95691e1e11ae503bcdbdb7461f1bc455bc2152ef Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 24 Apr 2014 06:59:39 +0200 Subject: [PATCH] Show passthrough modes in statusbar --- qutebrowser/app.py | 2 ++ qutebrowser/utils/modemanager.py | 10 +++++----- qutebrowser/widgets/statusbar.py | 12 ++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 7ed4d4661..55c999ece 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -255,6 +255,8 @@ class QuteBrowser(QApplication): tabs.currentChanged.connect(self.mainwindow.update_inspector) # status bar + modemanager.manager.entered.connect(status.on_mode_entered) + modemanager.manager.leaved.connect(status.on_mode_left) # FIXME what to do here? tabs.keypress.connect(status.keypress) for obj in [kp["normal"], tabs]: diff --git a/qutebrowser/utils/modemanager.py b/qutebrowser/utils/modemanager.py index 64fdc67c7..ab3e66a5b 100644 --- a/qutebrowser/utils/modemanager.py +++ b/qutebrowser/utils/modemanager.py @@ -57,11 +57,11 @@ class ModeManager(QObject): """Manager for keyboard modes. Attributes: + mode: The current mode (readonly property). + passthrough: A list of modes in which to pass through events. _handlers: A dictionary of modes and their handlers. - _passthrough: A list of modes in which to pass through events. _mode_stack: A list of the modes we're currently in, with the active one on the right. - mode: The current mode (readonly property). Signals: entered: Emitted when a mode is entered. @@ -76,7 +76,7 @@ class ModeManager(QObject): def __init__(self, parent=None): super().__init__(parent) self._handlers = {} - self._passthrough = [] + self.passthrough = [] self._mode_stack = [] @property @@ -97,7 +97,7 @@ class ModeManager(QObject): """ self._handlers[mode] = handler if passthrough: - self._passthrough.append(mode) + self.passthrough.append(mode) def enter(self, mode): """Enter a new mode. @@ -140,7 +140,7 @@ class ModeManager(QObject): if typ not in [QEvent.KeyPress, QEvent.KeyRelease]: # We're not interested in non-key-events so we pass them through. return False - elif self.mode in self._passthrough: + elif self.mode in self.passthrough: # We're currently in a passthrough mode so we pass everything # through.*and* let the passthrough keyhandler know. # FIXME what if we leave the passthrough mode right here? diff --git a/qutebrowser/widgets/statusbar.py b/qutebrowser/widgets/statusbar.py index c2c6a311d..755030450 100644 --- a/qutebrowser/widgets/statusbar.py +++ b/qutebrowser/widgets/statusbar.py @@ -170,6 +170,18 @@ class StatusBar(QWidget): self.txt.set_temptext('') self.clear_error() + @pyqtSlot(str) + def on_mode_entered(self, mode): + """Mark certain modes in the commandline.""" + if mode in modemanager.manager.passthrough: + self.txt.normaltext = "-- {} MODE --".format(mode.upper()) + + @pyqtSlot(str) + def on_mode_left(self, mode): + """Clear marked mode.""" + if mode in modemanager.manager.passthrough: + self.txt.normaltext = "" + def resizeEvent(self, e): """Extend resizeEvent of QWidget to emit a resized signal afterwards.