From fdd11476203b8e26e4ede17e1a8821ea8317c3f5 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 27 Oct 2016 22:16:26 +0200 Subject: [PATCH] Revert "Global prompt container" This reverts commit c23beee6502776dd19c0955b311e8dfb9f1c77ae. --- qutebrowser/app.py | 6 +++--- qutebrowser/mainwindow/mainwindow.py | 8 ++++++-- qutebrowser/mainwindow/prompt.py | 21 ++++++++++----------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/qutebrowser/app.py b/qutebrowser/app.py index 0f4b45b0e..cdce0be6d 100644 --- a/qutebrowser/app.py +++ b/qutebrowser/app.py @@ -372,6 +372,9 @@ def _init_modules(args, crash_handler): crash_handler: The CrashHandler instance. """ # pylint: disable=too-many-statements + log.init.debug("Initializing prompts...") + prompt.init() + log.init.debug("Initializing save manager...") save_manager = savemanager.SaveManager(qApp) objreg.register('save-manager', save_manager) @@ -388,9 +391,6 @@ def _init_modules(args, crash_handler): config.init(qApp) save_manager.init_autosave() - log.init.debug("Initializing prompts...") - prompt.init() - log.init.debug("Initializing web history...") history.init(qApp) diff --git a/qutebrowser/mainwindow/mainwindow.py b/qutebrowser/mainwindow/mainwindow.py index f06c926b8..490529180 100644 --- a/qutebrowser/mainwindow/mainwindow.py +++ b/qutebrowser/mainwindow/mainwindow.py @@ -183,9 +183,13 @@ class MainWindow(QWidget): self._messageview = messageview.MessageView(parent=self) self._add_overlay(self._messageview, self._messageview.update_geometry) - self._add_overlay(prompt.prompt_container, - prompt.prompt_container.update_geometry, + self._prompt_container = prompt.PromptContainer(self.win_id, self) + self._add_overlay(self._prompt_container, + self._prompt_container.update_geometry, centered=True, padding=10) + objreg.register('prompt-container', self._prompt_container, + scope='window', window=self.win_id) + self._prompt_container.hide() log.init.debug("Initializing modes...") modeman.init(self.win_id, self) diff --git a/qutebrowser/mainwindow/prompt.py b/qutebrowser/mainwindow/prompt.py index 1b91bb0c6..6c21bb69a 100644 --- a/qutebrowser/mainwindow/prompt.py +++ b/qutebrowser/mainwindow/prompt.py @@ -292,6 +292,7 @@ class PromptContainer(QWidget): Attributes: _layout: The layout used to show prompts in. + _win_id: The window ID this object is associated with. Signals: update_geometry: Emitted when the geometry should be updated. @@ -317,10 +318,11 @@ class PromptContainer(QWidget): """ update_geometry = pyqtSignal() - def __init__(self, parent=None): + def __init__(self, win_id, parent=None): super().__init__(parent) self._layout = QVBoxLayout(self) self._layout.setContentsMargins(10, 10, 10, 10) + self._win_id = win_id self.setObjectName('PromptContainer') self.setAttribute(Qt.WA_StyledBackground, True) @@ -330,7 +332,7 @@ class PromptContainer(QWidget): prompt_queue.show_prompt.connect(self._on_show_prompt) def __repr__(self): - return utils.get_repr(self) + return utils.get_repr(self, win_id=self._win_id) @pyqtSlot(object) def _on_show_prompt(self, prompt): @@ -349,11 +351,10 @@ class PromptContainer(QWidget): self.hide() return - # FIXME no win-id - # prompt.question.aborted.connect( - # lambda: modeman.maybe_leave(self._win_id, prompt.KEY_MODE, - # 'aborted')) - # modeman.enter(self._win_id, prompt.KEY_MODE, 'question asked') + prompt.question.aborted.connect( + lambda: modeman.maybe_leave(self._win_id, prompt.KEY_MODE, + 'aborted')) + modeman.enter(self._win_id, prompt.KEY_MODE, 'question asked') self.setSizePolicy(prompt.sizePolicy()) self._layout.addWidget(prompt) @@ -365,8 +366,7 @@ class PromptContainer(QWidget): @pyqtSlot(usertypes.KeyMode) def _on_prompt_done(self, key_mode): """Leave the prompt mode in this window if a question was answered.""" - # FIXME no win-id - #modeman.maybe_leave(self._win_id, key_mode, ':prompt-accept') + modeman.maybe_leave(self._win_id, key_mode, ':prompt-accept') class LineEdit(QLineEdit): @@ -752,9 +752,8 @@ class AlertPrompt(_BasePrompt): def init(): - global prompt_queue, prompt_container + global prompt_queue prompt_queue = PromptQueue() - prompt_container = PromptContainer() objreg.register('prompt-queue', prompt_queue) # for commands message.global_bridge.ask_question.connect( prompt_queue.ask_question, Qt.DirectConnection)