Use global HintManager
This commit is contained in:
parent
c8fd0937b0
commit
a76d68f564
@ -61,6 +61,7 @@ from qutebrowser.commands.managers import CommandManager, SearchManager
|
|||||||
from qutebrowser.config.iniparsers import ReadWriteConfigParser
|
from qutebrowser.config.iniparsers import ReadWriteConfigParser
|
||||||
from qutebrowser.config.lineparser import LineConfigParser
|
from qutebrowser.config.lineparser import LineConfigParser
|
||||||
from qutebrowser.browser.cookies import CookieJar
|
from qutebrowser.browser.cookies import CookieJar
|
||||||
|
from qutebrowser.browser.hints import HintManager
|
||||||
from qutebrowser.utils.message import MessageBridge
|
from qutebrowser.utils.message import MessageBridge
|
||||||
from qutebrowser.utils.appdirs import AppDirs
|
from qutebrowser.utils.appdirs import AppDirs
|
||||||
from qutebrowser.utils.misc import dotted_getattr
|
from qutebrowser.utils.misc import dotted_getattr
|
||||||
@ -87,6 +88,7 @@ class QuteBrowser(QApplication):
|
|||||||
modeman: The global ModeManager instance.
|
modeman: The global ModeManager instance.
|
||||||
networkmanager: The global NetworkManager instance.
|
networkmanager: The global NetworkManager instance.
|
||||||
cookiejar: The global CookieJar instance.
|
cookiejar: The global CookieJar instance.
|
||||||
|
hintmanager: The global HintManager instance.
|
||||||
_keyparsers: A mapping from modes to keyparsers.
|
_keyparsers: A mapping from modes to keyparsers.
|
||||||
_dirs: AppDirs instance for config/cache directories.
|
_dirs: AppDirs instance for config/cache directories.
|
||||||
_args: ArgumentParser instance.
|
_args: ArgumentParser instance.
|
||||||
@ -125,6 +127,7 @@ class QuteBrowser(QApplication):
|
|||||||
self.networkmanager = NetworkManager(self.cookiejar)
|
self.networkmanager = NetworkManager(self.cookiejar)
|
||||||
self.commandmanager = CommandManager()
|
self.commandmanager = CommandManager()
|
||||||
self.searchmanager = SearchManager()
|
self.searchmanager = SearchManager()
|
||||||
|
self.hintmanager = HintManager()
|
||||||
self._init_cmds()
|
self._init_cmds()
|
||||||
self.mainwindow = MainWindow()
|
self.mainwindow = MainWindow()
|
||||||
|
|
||||||
@ -313,10 +316,13 @@ class QuteBrowser(QApplication):
|
|||||||
kp['normal'].keystring_updated.connect(status.keystring.setText)
|
kp['normal'].keystring_updated.connect(status.keystring.setText)
|
||||||
|
|
||||||
# hints
|
# hints
|
||||||
kp['hint'].fire_hint.connect(tabs.cur.fire_hint)
|
kp['hint'].fire_hint.connect(self.hintmanager.fire)
|
||||||
kp['hint'].filter_hints.connect(tabs.cur.filter_hints)
|
kp['hint'].filter_hints.connect(self.hintmanager.filter_hints)
|
||||||
kp['hint'].keystring_updated.connect(tabs.cur.handle_hint_key)
|
kp['hint'].keystring_updated.connect(
|
||||||
tabs.hint_strings_updated.connect(kp['hint'].on_hint_strings_updated)
|
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
|
# messages
|
||||||
self.messagebridge.error.connect(status.disp_error)
|
self.messagebridge.error.connect(status.disp_error)
|
||||||
|
@ -241,27 +241,8 @@ class CurCommandDispatcher(QObject):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
message.error("Unknown hinting target {}!".format(targetstr))
|
message.error("Unknown hinting target {}!".format(targetstr))
|
||||||
return
|
return
|
||||||
widget.hintmanager.start(frame, widget.url(), group, target)
|
QApplication.instance().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)
|
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs.cur')
|
@cmdutils.register(instance='mainwindow.tabs.cur')
|
||||||
def prevpage(self):
|
def prevpage(self):
|
||||||
|
@ -30,6 +30,7 @@ import qutebrowser.keyinput.modeman as modeman
|
|||||||
import qutebrowser.utils.message as message
|
import qutebrowser.utils.message as message
|
||||||
import qutebrowser.utils.url as urlutils
|
import qutebrowser.utils.url as urlutils
|
||||||
import qutebrowser.utils.webelem as webelem
|
import qutebrowser.utils.webelem as webelem
|
||||||
|
import qutebrowser.commands.utils as cmdutils
|
||||||
from qutebrowser.utils.usertypes import enum
|
from qutebrowser.utils.usertypes import enum
|
||||||
|
|
||||||
|
|
||||||
@ -380,6 +381,7 @@ class HintManager(QObject):
|
|||||||
self.hint_strings_updated.emit(strings)
|
self.hint_strings_updated.emit(strings)
|
||||||
modeman.enter('hint')
|
modeman.enter('hint')
|
||||||
|
|
||||||
|
@pyqtSlot(str)
|
||||||
def handle_partial_key(self, keystr):
|
def handle_partial_key(self, keystr):
|
||||||
"""Handle a new partial keypress."""
|
"""Handle a new partial keypress."""
|
||||||
delete = []
|
delete = []
|
||||||
@ -395,6 +397,7 @@ class HintManager(QObject):
|
|||||||
for key in delete:
|
for key in delete:
|
||||||
del self._elems[key]
|
del self._elems[key]
|
||||||
|
|
||||||
|
@pyqtSlot(str)
|
||||||
def filter_hints(self, filterstr):
|
def filter_hints(self, filterstr):
|
||||||
"""Filter displayed hints according to a text."""
|
"""Filter displayed hints according to a text."""
|
||||||
delete = []
|
delete = []
|
||||||
@ -411,6 +414,7 @@ class HintManager(QObject):
|
|||||||
# unpacking gets us the first (and only) key in the dict.
|
# unpacking gets us the first (and only) key in the dict.
|
||||||
self.fire(*self._elems)
|
self.fire(*self._elems)
|
||||||
|
|
||||||
|
@pyqtSlot(str)
|
||||||
def fire(self, keystr, force=False):
|
def fire(self, keystr, force=False):
|
||||||
"""Fire a completed hint.
|
"""Fire a completed hint.
|
||||||
|
|
||||||
@ -451,6 +455,7 @@ class HintManager(QObject):
|
|||||||
if self._target != Target.rapid:
|
if self._target != Target.rapid:
|
||||||
modeman.leave('hint')
|
modeman.leave('hint')
|
||||||
|
|
||||||
|
@cmdutils.register(instance='hintmanager', hide=True)
|
||||||
def follow_hint(self):
|
def follow_hint(self):
|
||||||
"""Follow the currently selected hint."""
|
"""Follow the currently selected hint."""
|
||||||
if not self._to_follow:
|
if not self._to_follow:
|
||||||
@ -469,6 +474,7 @@ class HintManager(QObject):
|
|||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def on_mode_left(self, mode):
|
def on_mode_left(self, mode):
|
||||||
"""Stop hinting when hinting mode was left."""
|
"""Stop hinting when hinting mode was left."""
|
||||||
|
logging.warn("mode {} left".format(mode))
|
||||||
if mode != 'hint':
|
if mode != 'hint':
|
||||||
return
|
return
|
||||||
for elem in self._elems.values():
|
for elem in self._elems.values():
|
||||||
|
@ -66,8 +66,6 @@ class TabbedBrowser(TabWidget):
|
|||||||
cur_scroll_perc_changed: Scroll percentage of current tab changed.
|
cur_scroll_perc_changed: Scroll percentage of current tab changed.
|
||||||
arg 1: x-position in %.
|
arg 1: x-position in %.
|
||||||
arg 2: y-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.
|
shutdown_complete: The shuttdown is completed.
|
||||||
quit: The last tab was closed, quit application.
|
quit: The last tab was closed, quit application.
|
||||||
resized: Emitted when the browser window has resized, so the completion
|
resized: Emitted when the browser window has resized, so the completion
|
||||||
@ -82,7 +80,6 @@ class TabbedBrowser(TabWidget):
|
|||||||
cur_url_changed = pyqtSignal('QUrl')
|
cur_url_changed = pyqtSignal('QUrl')
|
||||||
cur_link_hovered = pyqtSignal(str, str, str)
|
cur_link_hovered = pyqtSignal(str, str, str)
|
||||||
cur_scroll_perc_changed = pyqtSignal(int, int)
|
cur_scroll_perc_changed = pyqtSignal(int, int)
|
||||||
hint_strings_updated = pyqtSignal(list)
|
|
||||||
shutdown_complete = pyqtSignal()
|
shutdown_complete = pyqtSignal()
|
||||||
quit = pyqtSignal()
|
quit = pyqtSignal()
|
||||||
resized = pyqtSignal('QRect')
|
resized = pyqtSignal('QRect')
|
||||||
@ -131,9 +128,6 @@ class TabbedBrowser(TabWidget):
|
|||||||
tab.scroll_pos_changed.connect(
|
tab.scroll_pos_changed.connect(
|
||||||
self._filter.create(self.cur_scroll_perc_changed))
|
self._filter.create(self.cur_scroll_perc_changed))
|
||||||
tab.urlChanged.connect(self._filter.create(self.cur_url_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
|
# misc
|
||||||
tab.titleChanged.connect(self.on_title_changed)
|
tab.titleChanged.connect(self.on_title_changed)
|
||||||
tab.open_tab.connect(self.tabopen)
|
tab.open_tab.connect(self.tabopen)
|
||||||
|
Loading…
Reference in New Issue
Block a user