From b14f3f63c594afb8d39a50f0a235b442959c8db6 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Fri, 17 Jan 2014 12:00:13 +0100 Subject: [PATCH] Fix empty command handling --- qutebrowser/app.py | 4 ++-- qutebrowser/commands/commands.py | 5 ----- qutebrowser/keys.py | 16 ++++++++++++++-- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 1e2e01410..119651ca3 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -9,7 +9,7 @@ def main(): mw = MainWindow() cp = cmdutils.CommandParser() - kp = KeyParser() + kp = KeyParser(mw) kp.set_cmd_text.connect(mw.status.cmd.set_cmd) mw.status.cmd.got_cmd.connect(cp.parse) mw.status.cmd.got_cmd.connect(mw.setFocus) @@ -23,7 +23,7 @@ def main(): cmds['tabclose'].signal.connect(mw.tabs.close_act) cmds['tabprev'].signal.connect(mw.tabs.switch_prev) cmds['tabnext'].signal.connect(mw.tabs.switch_next) - kp.from_cmd_dict(cmds, mw) + kp.from_cmd_dict(cmds) mw.show() sys.exit(app.exec_()) diff --git a/qutebrowser/commands/commands.py b/qutebrowser/commands/commands.py index 2b8b00310..d2aafdfd2 100644 --- a/qutebrowser/commands/commands.py +++ b/qutebrowser/commands/commands.py @@ -1,11 +1,6 @@ from PyQt5.QtCore import pyqtSignal from qutebrowser.commands.utils import Command -class Empty(Command): - nargs = 0 - name = '' - key = ':' - class Open(Command): nargs = 1 key = 'o' diff --git a/qutebrowser/keys.py b/qutebrowser/keys.py index 061cf5260..11377eed2 100644 --- a/qutebrowser/keys.py +++ b/qutebrowser/keys.py @@ -3,14 +3,23 @@ from PyQt5.QtWidgets import QShortcut from PyQt5.QtGui import QKeySequence class KeyParser(QObject): + keyparent = None set_cmd_text = pyqtSignal(str) id_to_cmd = {} - def from_cmd_dict(self, d, parent): + def __init__(self, keyparent): + super().__init__() + self.keyparent = keyparent + sc = QShortcut(keyparent) + sc.setKey(QKeySequence(':')) + sc.setContext(Qt.WidgetWithChildrenShortcut) + sc.activated.connect(self.handle_empty) + + def from_cmd_dict(self, d): for cmd in d.values(): if cmd.key is not None: print('reg: {} -> {}'.format(cmd.name, cmd.key)) - sc = QShortcut(parent) + sc = QShortcut(self.keyparent) sc.setKey(QKeySequence(cmd.key)) sc.setContext(Qt.WidgetWithChildrenShortcut) sc.activated.connect(self.handle) @@ -22,3 +31,6 @@ class KeyParser(QObject): self.set_cmd_text.emit(':{} '.format(cmd.name)) else: cmd.run() + + def handle_empty(self): + self.set_cmd_text.emit(':')