From a76d68f564aa7750e96ff1a79f14a6cf528325f1 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Mon, 5 May 2014 20:28:29 +0200 Subject: [PATCH] Use global HintManager --- qutebrowser/app.py | 14 ++++++++++---- qutebrowser/browser/curcommand.py | 23 ++--------------------- qutebrowser/browser/hints.py | 6 ++++++ qutebrowser/widgets/_tabbedbrowser.py | 6 ------ 4 files changed, 18 insertions(+), 31 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 563785a2c..5bc2b43db 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -61,6 +61,7 @@ from qutebrowser.commands.managers import CommandManager, SearchManager from qutebrowser.config.iniparsers import ReadWriteConfigParser from qutebrowser.config.lineparser import LineConfigParser from qutebrowser.browser.cookies import CookieJar +from qutebrowser.browser.hints import HintManager from qutebrowser.utils.message import MessageBridge from qutebrowser.utils.appdirs import AppDirs from qutebrowser.utils.misc import dotted_getattr @@ -87,6 +88,7 @@ class QuteBrowser(QApplication): modeman: The global ModeManager instance. networkmanager: The global NetworkManager instance. cookiejar: The global CookieJar instance. + hintmanager: The global HintManager instance. _keyparsers: A mapping from modes to keyparsers. _dirs: AppDirs instance for config/cache directories. _args: ArgumentParser instance. @@ -125,6 +127,7 @@ class QuteBrowser(QApplication): self.networkmanager = NetworkManager(self.cookiejar) self.commandmanager = CommandManager() self.searchmanager = SearchManager() + self.hintmanager = HintManager() self._init_cmds() self.mainwindow = MainWindow() @@ -313,10 +316,13 @@ class QuteBrowser(QApplication): kp['normal'].keystring_updated.connect(status.keystring.setText) # hints - kp['hint'].fire_hint.connect(tabs.cur.fire_hint) - kp['hint'].filter_hints.connect(tabs.cur.filter_hints) - kp['hint'].keystring_updated.connect(tabs.cur.handle_hint_key) - tabs.hint_strings_updated.connect(kp['hint'].on_hint_strings_updated) + kp['hint'].fire_hint.connect(self.hintmanager.fire) + kp['hint'].filter_hints.connect(self.hintmanager.filter_hints) + kp['hint'].keystring_updated.connect( + self.hintmanager.handle_partial_key) + self.hintmanager.hint_strings_updated.connect( + kp['hint'].on_hint_strings_updated) + self.hintmanager.openurl.connect(tabs.cur.openurl_slot) # messages self.messagebridge.error.connect(status.disp_error) diff --git a/qutebrowser/browser/curcommand.py b/qutebrowser/browser/curcommand.py index 0afdb216d..01e5ca1bb 100644 --- a/qutebrowser/browser/curcommand.py +++ b/qutebrowser/browser/curcommand.py @@ -241,27 +241,8 @@ class CurCommandDispatcher(QObject): except AttributeError: message.error("Unknown hinting target {}!".format(targetstr)) return - widget.hintmanager.start(frame, widget.url(), group, target) - - @cmdutils.register(instance='mainwindow.tabs.cur', hide=True) - def follow_hint(self): - """Follow the currently selected hint.""" - self._tabs.currentWidget().hintmanager.follow_hint() - - @pyqtSlot(str) - def handle_hint_key(self, keystr): - """Handle a new hint keypress.""" - self._tabs.currentWidget().hintmanager.handle_partial_key(keystr) - - @pyqtSlot(str) - def fire_hint(self, keystr): - """Fire a completed hint.""" - self._tabs.currentWidget().hintmanager.fire(keystr) - - @pyqtSlot(str) - def filter_hints(self, filterstr): - """Filter displayed hints.""" - self._tabs.currentWidget().hintmanager.filter_hints(filterstr) + QApplication.instance().hintmanager.start(frame, widget.url(), group, + target) @cmdutils.register(instance='mainwindow.tabs.cur') def prevpage(self): diff --git a/qutebrowser/browser/hints.py b/qutebrowser/browser/hints.py index dde970263..d0f5b6a93 100644 --- a/qutebrowser/browser/hints.py +++ b/qutebrowser/browser/hints.py @@ -30,6 +30,7 @@ import qutebrowser.keyinput.modeman as modeman import qutebrowser.utils.message as message import qutebrowser.utils.url as urlutils import qutebrowser.utils.webelem as webelem +import qutebrowser.commands.utils as cmdutils from qutebrowser.utils.usertypes import enum @@ -380,6 +381,7 @@ class HintManager(QObject): self.hint_strings_updated.emit(strings) modeman.enter('hint') + @pyqtSlot(str) def handle_partial_key(self, keystr): """Handle a new partial keypress.""" delete = [] @@ -395,6 +397,7 @@ class HintManager(QObject): for key in delete: del self._elems[key] + @pyqtSlot(str) def filter_hints(self, filterstr): """Filter displayed hints according to a text.""" delete = [] @@ -411,6 +414,7 @@ class HintManager(QObject): # unpacking gets us the first (and only) key in the dict. self.fire(*self._elems) + @pyqtSlot(str) def fire(self, keystr, force=False): """Fire a completed hint. @@ -451,6 +455,7 @@ class HintManager(QObject): if self._target != Target.rapid: modeman.leave('hint') + @cmdutils.register(instance='hintmanager', hide=True) def follow_hint(self): """Follow the currently selected hint.""" if not self._to_follow: @@ -469,6 +474,7 @@ class HintManager(QObject): @pyqtSlot(str) def on_mode_left(self, mode): """Stop hinting when hinting mode was left.""" + logging.warn("mode {} left".format(mode)) if mode != 'hint': return for elem in self._elems.values(): diff --git a/qutebrowser/widgets/_tabbedbrowser.py b/qutebrowser/widgets/_tabbedbrowser.py index 6c9ab7cf4..5e3311a4e 100644 --- a/qutebrowser/widgets/_tabbedbrowser.py +++ b/qutebrowser/widgets/_tabbedbrowser.py @@ -66,8 +66,6 @@ class TabbedBrowser(TabWidget): cur_scroll_perc_changed: Scroll percentage of current tab changed. arg 1: x-position in %. arg 2: y-position in %. - hint_strings_updated: Hint strings were updated. - arg: A list of hint strings. shutdown_complete: The shuttdown is completed. quit: The last tab was closed, quit application. resized: Emitted when the browser window has resized, so the completion @@ -82,7 +80,6 @@ class TabbedBrowser(TabWidget): cur_url_changed = pyqtSignal('QUrl') cur_link_hovered = pyqtSignal(str, str, str) cur_scroll_perc_changed = pyqtSignal(int, int) - hint_strings_updated = pyqtSignal(list) shutdown_complete = pyqtSignal() quit = pyqtSignal() resized = pyqtSignal('QRect') @@ -131,9 +128,6 @@ class TabbedBrowser(TabWidget): tab.scroll_pos_changed.connect( self._filter.create(self.cur_scroll_perc_changed)) tab.urlChanged.connect(self._filter.create(self.cur_url_changed)) - # hintmanager - tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated) - tab.hintmanager.openurl.connect(self.cur.openurl_slot) # misc tab.titleChanged.connect(self.on_title_changed) tab.open_tab.connect(self.tabopen)