From 857228e4f2f10cd3f5ecc770a1156d0e79d3085d Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 16 Jan 2014 17:49:57 +0100 Subject: [PATCH] Refactor commandline parsing --- qutebrowser/app.py | 2 +- qutebrowser/commands.py | 2 +- qutebrowser/widgets/statusbar.py | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index c4c03177c..c82b29c61 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -8,7 +8,7 @@ def main(): mw = MainWindow() cp = cmds.CommandParser() - mw.status.cmd.returnPressed.connect(lambda: cp.parse(mw.status.cmd.text())) + mw.status.cmd.got_cmd.connect(cp.parse) cmds.cmd_dict['openurl'].connect(mw.tabs.openurl) cmds.cmd_dict['tabopen'].connect(mw.tabs.tabopen) cmds.cmd_dict['quit'].connect(QApplication.closeAllWindows) # FIXME diff --git a/qutebrowser/commands.py b/qutebrowser/commands.py index a4a338304..673287b78 100644 --- a/qutebrowser/commands.py +++ b/qutebrowser/commands.py @@ -13,7 +13,7 @@ def register_all(): class CommandParser(QObject): def parse(self, test): - parts = text.lstrip(':').strip().split() + parts = text.strip().split() cmd = parts[0] args = parts[1:] obj = cmd_dict[cmd]() diff --git a/qutebrowser/widgets/statusbar.py b/qutebrowser/widgets/statusbar.py index 842da60aa..fc3d71214 100644 --- a/qutebrowser/widgets/statusbar.py +++ b/qutebrowser/widgets/statusbar.py @@ -31,7 +31,15 @@ class StatusText(QLabel): self.setStyleSheet("padding-right: 1px") class StatusCommand(QLineEdit): + got_cmd = pyqtSignal(str) + def __init__(self, parent): super().__init__(parent) self.setObjectName(self.__class__.__name__) self.setStyleSheet("border: 0px; padding-left: 1px") + self.returnPressed.connect(self.process_cmd) + + def process_cmd(self): + text = self.text().lstrip(':') + self.setText('') + self.got_cmd.emit(text)