Use object registry for messagebridge.
This commit is contained in:
parent
1d535ae300
commit
58be65f4f0
@ -58,7 +58,6 @@ class Application(QApplication):
|
||||
mainwindow: The MainWindow QWidget.
|
||||
config: The main ConfigManager
|
||||
cmd_history: The "cmd_history" LineConfigParser instance.
|
||||
messagebridge: The global MessageBridge instance.
|
||||
modeman: The global ModeManager instance.
|
||||
args: ArgumentParser instance.
|
||||
_commandrunner: The main CommandRunner instance.
|
||||
@ -98,7 +97,6 @@ class Application(QApplication):
|
||||
self._keyparsers = None
|
||||
self._crashdlg = None
|
||||
self._crashlogfile = None
|
||||
self.messagebridge = None
|
||||
self.modeman = None
|
||||
self.cmd_history = None
|
||||
self.config = None
|
||||
@ -266,7 +264,8 @@ class Application(QApplication):
|
||||
self.setOrganizationName("qutebrowser")
|
||||
self.setApplicationName("qutebrowser")
|
||||
self.setApplicationVersion(qutebrowser.__version__)
|
||||
self.messagebridge = message.MessageBridge(self)
|
||||
messagebridge = message.MessageBridge(self)
|
||||
self.registry['messagebridge'] = messagebridge
|
||||
rl_bridge = readline.ReadlineBridge()
|
||||
self.registry['rl_bridge'] = rl_bridge
|
||||
|
||||
@ -381,6 +380,7 @@ class Application(QApplication):
|
||||
cmd = self.mainwindow.status.cmd
|
||||
completer = self.mainwindow.completion.completer
|
||||
searchrunner = self.registry['searchrunner']
|
||||
messagebridge = self.registry['messagebridge']
|
||||
|
||||
# misc
|
||||
self.lastWindowClosed.connect(self.shutdown)
|
||||
@ -410,14 +410,13 @@ class Application(QApplication):
|
||||
kp[utypes.KeyMode.hint].on_hint_strings_updated)
|
||||
|
||||
# messages
|
||||
self.messagebridge.s_error.connect(status.disp_error)
|
||||
self.messagebridge.s_info.connect(status.disp_temp_text)
|
||||
self.messagebridge.s_set_text.connect(status.set_text)
|
||||
self.messagebridge.s_maybe_reset_text.connect(
|
||||
status.txt.maybe_reset_text)
|
||||
self.messagebridge.s_set_cmd_text.connect(cmd.set_cmd_text)
|
||||
self.messagebridge.s_question.connect(
|
||||
status.prompt.prompter.ask_question, Qt.DirectConnection)
|
||||
messagebridge.s_error.connect(status.disp_error)
|
||||
messagebridge.s_info.connect(status.disp_temp_text)
|
||||
messagebridge.s_set_text.connect(status.set_text)
|
||||
messagebridge.s_maybe_reset_text.connect(status.txt.maybe_reset_text)
|
||||
messagebridge.s_set_cmd_text.connect(cmd.set_cmd_text)
|
||||
messagebridge.s_question.connect(status.prompt.prompter.ask_question,
|
||||
Qt.DirectConnection)
|
||||
|
||||
# config
|
||||
self.config.style_changed.connect(style.get_stylesheet.cache_clear)
|
||||
|
@ -409,7 +409,7 @@ class DownloadManager(QObject):
|
||||
q.destroyed.connect(functools.partial(self.questions.remove, q))
|
||||
self.questions.append(q)
|
||||
download.cancelled.connect(q.abort)
|
||||
message.instance().ask(q, blocking=False)
|
||||
utils.get_object('message').ask(q, blocking=False)
|
||||
|
||||
@pyqtSlot(DownloadItem)
|
||||
def on_finished(self, download):
|
||||
|
@ -31,7 +31,7 @@ from qutebrowser.config import config
|
||||
from qutebrowser.keyinput import modeman
|
||||
from qutebrowser.browser import webelem
|
||||
from qutebrowser.commands import userscripts, cmdexc
|
||||
from qutebrowser.utils import usertypes, log, qtutils, message
|
||||
from qutebrowser.utils import usertypes, log, qtutils, message, utils
|
||||
|
||||
|
||||
ElemTuple = collections.namedtuple('ElemTuple', 'elem, label')
|
||||
@ -160,7 +160,7 @@ class HintManager(QObject):
|
||||
except webelem.IsNullError:
|
||||
pass
|
||||
text = self.HINT_TEXTS[self._context.target]
|
||||
message.instance().maybe_reset_text(text)
|
||||
utils.get_object('messagebridge').maybe_reset_text(text)
|
||||
self._context = None
|
||||
|
||||
def _hint_strings(self, elems):
|
||||
@ -541,7 +541,7 @@ class HintManager(QObject):
|
||||
self._context.frames = webelem.get_child_frames(mainframe)
|
||||
self._context.args = args
|
||||
self._init_elements(mainframe, group)
|
||||
message.instance().set_text(self.HINT_TEXTS[target])
|
||||
utils.get_object('messagebridge').set_text(self.HINT_TEXTS[target])
|
||||
self._connect_frame_signals()
|
||||
try:
|
||||
modeman.enter(usertypes.KeyMode.hint, 'HintManager.start')
|
||||
|
@ -21,12 +21,7 @@
|
||||
|
||||
from PyQt5.QtCore import pyqtSignal, QCoreApplication, QObject, QTimer
|
||||
|
||||
from qutebrowser.utils import usertypes, log
|
||||
|
||||
|
||||
def instance():
|
||||
"""Get the global messagebridge instance."""
|
||||
return QCoreApplication.instance().messagebridge
|
||||
from qutebrowser.utils import usertypes, log, utils
|
||||
|
||||
|
||||
def error(message, immediately=False):
|
||||
@ -35,7 +30,7 @@ def error(message, immediately=False):
|
||||
Args:
|
||||
See MessageBridge.error.
|
||||
"""
|
||||
instance().error(message, immediately)
|
||||
utils.get_object('messagebridge').error(message, immediately)
|
||||
|
||||
|
||||
def info(message, immediately=True):
|
||||
@ -44,12 +39,12 @@ def info(message, immediately=True):
|
||||
Args:
|
||||
See MessageBridge.info.
|
||||
"""
|
||||
instance().info(message, immediately)
|
||||
utils.get_object('messagebridge').info(message, immediately)
|
||||
|
||||
|
||||
def set_cmd_text(txt):
|
||||
"""Convienience function to Set the statusbar command line to a text."""
|
||||
instance().set_cmd_text(txt)
|
||||
utils.get_object('messagebridge').set_cmd_text(txt)
|
||||
|
||||
|
||||
def ask(message, mode, default=None):
|
||||
@ -67,7 +62,7 @@ def ask(message, mode, default=None):
|
||||
q.text = message
|
||||
q.mode = mode
|
||||
q.default = default
|
||||
instance().ask(q, blocking=True)
|
||||
utils.get_object('messagebridge').ask(q, blocking=True)
|
||||
q.deleteLater()
|
||||
return q.answer
|
||||
|
||||
@ -77,7 +72,7 @@ def alert(message):
|
||||
q = usertypes.Question()
|
||||
q.text = message
|
||||
q.mode = usertypes.PromptMode.alert
|
||||
instance().ask(q, blocking=True)
|
||||
utils.get_object('messagebridge').ask(q, blocking=True)
|
||||
q.deleteLater()
|
||||
|
||||
|
||||
@ -92,7 +87,7 @@ def ask_async(message, mode, handler, default=None):
|
||||
"""
|
||||
if not isinstance(mode, usertypes.PromptMode):
|
||||
raise TypeError("Mode {} is no PromptMode member!".format(mode))
|
||||
bridge = instance()
|
||||
bridge = utils.get_object('messagebridge')
|
||||
q = usertypes.Question(bridge)
|
||||
q.text = message
|
||||
q.mode = mode
|
||||
@ -111,7 +106,7 @@ def confirm_async(message, yes_action, no_action=None, default=None):
|
||||
no_action: Callable to be called when the user answered no.
|
||||
default: True/False to set a default value, or None.
|
||||
"""
|
||||
bridge = instance()
|
||||
bridge = utils.get_object('messagebridge')
|
||||
q = usertypes.Question(bridge)
|
||||
q.text = message
|
||||
q.mode = usertypes.PromptMode.yesno
|
||||
|
Loading…
Reference in New Issue
Block a user