From 9320c813f71004e085e424c315eea180c078e1e9 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 24 Apr 2014 21:28:24 +0200 Subject: [PATCH] Add set_cmd_text to MessageBridge --- qutebrowser/app.py | 4 +--- qutebrowser/browser/hints.py | 18 ++---------------- qutebrowser/keyinput/commandmode.py | 17 +++-------------- qutebrowser/utils/message.py | 6 ++++++ qutebrowser/widgets/tabbedbrowser.py | 18 ++++-------------- 5 files changed, 16 insertions(+), 47 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 5db5fd2bc..98289e274 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -259,10 +259,7 @@ class QuteBrowser(QApplication): # status bar modes.manager.entered.connect(status.on_mode_entered) modes.manager.left.connect(status.on_mode_left) - # FIXME what to do here? modes.manager.key_pressed.connect(status.on_key_pressed) - for obj in [kp["normal"], tabs]: - obj.set_cmd_text.connect(cmd.set_cmd_text) # commands cmd.got_cmd.connect(self.commandparser.run) @@ -282,6 +279,7 @@ class QuteBrowser(QApplication): message.bridge.error.connect(status.disp_error) message.bridge.info.connect(status.txt.set_temptext) message.bridge.text.connect(status.txt.set_normaltext) + message.bridge.set_cmd_text.connect(cmd.set_cmd_text) # config self.config.style_changed.connect(style.invalidate_caches) diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index 736a5b1d9..e0d2e5147 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -62,7 +62,6 @@ class HintManager(QObject): arg 0: URL to open as a string. arg 1: true if it should be opened in a new tab, else false. set_open_target: Set a new target to open the links in. - set_cmd_text: Emitted when the commandline text should be set. """ HINT_CSS = """ @@ -81,7 +80,6 @@ class HintManager(QObject): hint_strings_updated = pyqtSignal(list) mouse_event = pyqtSignal('QMouseEvent') set_open_target = pyqtSignal(str) - set_cmd_text = pyqtSignal(str) def __init__(self, parent=None): """Constructor. @@ -244,19 +242,6 @@ class HintManager(QObject): message.info('URL yanked to {}'.format('primary selection' if sel else 'clipboard')) - def _set_cmd_text(self, link, command): - """Fill the command line with an element link. - - Args: - link: The URL to open. - command: The command to use. - - Emit: - set_cmd_text: Always emitted. - """ - self.set_cmd_text.emit(':{} {}'.format(command, - urlutils.urlstring(link))) - def _resolve_link(self, elem): """Resolve a link and check if we want to keep it. @@ -368,7 +353,8 @@ class HintManager(QObject): 'cmd_tab': 'tabopen', 'cmd_bgtab': 'backtabopen', } - self._set_cmd_text(link, commands[self._target]) + message.set_cmd_text(':{} {}'.format(commands[self._target], + urlutils.urlstring(link))) if self._target != 'rapid': self.stop() diff --git a/qutebrowser/keyinput/commandmode.py b/qutebrowser/keyinput/commandmode.py index bd4a040b4..07b1bc728 100644 --- a/qutebrowser/keyinput/commandmode.py +++ b/qutebrowser/keyinput/commandmode.py @@ -25,6 +25,7 @@ import logging from PyQt5.QtCore import pyqtSignal +import qutebrowser.utils.message as message from qutebrowser.keyinput.keyparser import KeyChainParser from qutebrowser.commands.parsers import (CommandParser, ArgumentCountError, NoSuchCommandError) @@ -41,13 +42,8 @@ class CommandKeyParser(KeyChainParser): Attributes: commandparser: Commandparser instance. - - Signals: - set_cmd_text: Emitted when the statusbar should set a partial command. - arg: Text to set. """ - set_cmd_text = pyqtSignal(str) supports_count = True def __init__(self, parent=None): @@ -62,10 +58,6 @@ class CommandKeyParser(KeyChainParser): cmdstr: The command string. count: Optional command count. ignore_exc: Ignore exceptions. - - Emit: - set_cmd_text: If a partial command should be printed to the - statusbar. """ try: self.commandparser.run(cmdstr, count=count, ignore_exc=ignore_exc) @@ -74,7 +66,7 @@ class CommandKeyParser(KeyChainParser): except ArgumentCountError: logging.debug('Filling statusbar with partial command {}'.format( cmdstr)) - self.set_cmd_text.emit(':{} '.format(cmdstr)) + message.set_cmd_text(':{} '.format(cmdstr)) def _handle_single_key(self, e): """Override _handle_single_key to abort if the key is a startchar. @@ -82,15 +74,12 @@ class CommandKeyParser(KeyChainParser): Args: e: the KeyPressEvent from Qt. - Emit: - set_cmd_text: If the keystring should be shown in the statusbar. - Return: True if event has been handled, False otherwise. """ txt = e.text().strip() if not self._keystring and any(txt == c for c in STARTCHARS): - self.set_cmd_text.emit(txt) + message.set_cmd_text(txt) return True return super()._handle_single_key(e) diff --git a/qutebrowser/utils/message.py b/qutebrowser/utils/message.py index 4157114a6..293e5acb6 100644 --- a/qutebrowser/utils/message.py +++ b/qutebrowser/utils/message.py @@ -57,6 +57,11 @@ def clear(): bridge.text.emit('') +def set_cmd_text(text): + """Set the statusbar command line to a preset text.""" + bridge.set_cmd_text.emit(text) + + class MessageBridge(QObject): """Bridge for messages to be shown in the statusbar.""" @@ -64,3 +69,4 @@ class MessageBridge(QObject): error = pyqtSignal(str) info = pyqtSignal(str) text = pyqtSignal(str) + set_cmd_text = pyqtSignal(str) diff --git a/qutebrowser/widgets/tabbedbrowser.py b/qutebrowser/widgets/tabbedbrowser.py index 013d5429c..f8c926bca 100644 --- a/qutebrowser/widgets/tabbedbrowser.py +++ b/qutebrowser/widgets/tabbedbrowser.py @@ -84,7 +84,6 @@ class TabbedBrowser(TabWidget): cur_link_hovered = pyqtSignal(str, str, str) cur_scroll_perc_changed = pyqtSignal(int, int) hint_strings_updated = pyqtSignal(list) - set_cmd_text = pyqtSignal(str) shutdown_complete = pyqtSignal() quit = pyqtSignal() resized = pyqtSignal('QRect') @@ -137,7 +136,6 @@ class TabbedBrowser(TabWidget): tab.urlChanged.connect(self._filter.create(self.cur_url_changed)) # hintmanager tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated) - tab.hintmanager.set_cmd_text.connect(self.set_cmd_text) # misc tab.titleChanged.connect(self.on_title_changed) tab.open_tab.connect(self.tabopen) @@ -235,23 +233,15 @@ class TabbedBrowser(TabWidget): @cmdutils.register(instance='mainwindow.tabs', hide=True) def tabopencur(self): - """Set the statusbar to :tabopen and the current URL. - - Emit: - set_cmd_text prefilled with :tabopen $URL - """ + """Set the statusbar to :tabopen and the current URL.""" url = urlutils.urlstring(self.currentWidget().url()) - self.set_cmd_text.emit(':tabopen ' + url) + message.set_cmd_text(':tabopen ' + url) @cmdutils.register(instance='mainwindow.tabs', hide=True) def opencur(self): - """Set the statusbar to :open and the current URL. - - Emit: - set_cmd_text prefilled with :open $URL - """ + """Set the statusbar to :open and the current URL.""" url = urlutils.urlstring(self.currentWidget().url()) - self.set_cmd_text.emit(':open ' + url) + message.set_cmd_text(':open ' + url) @cmdutils.register(instance='mainwindow.tabs', name='undo') def undo_close(self):