Move show_prompt/hide_prompt signals from prompt to prompter.

This commit is contained in:
Florian Bruhin 2014-09-30 07:37:31 +02:00
parent b958d07869
commit f5a4d3a184
3 changed files with 19 additions and 17 deletions

View File

@ -152,8 +152,9 @@ class StatusBar(QWidget):
self._cmd.show_cmd.connect(self._show_cmd_widget) self._cmd.show_cmd.connect(self._show_cmd_widget)
self._cmd.hide_cmd.connect(self._hide_cmd_widget) self._cmd.hide_cmd.connect(self._hide_cmd_widget)
self._hide_cmd_widget() self._hide_cmd_widget()
self.prompt.show_prompt.connect(self._show_prompt_widget) prompter = objreg.get('prompter')
self.prompt.hide_prompt.connect(self._hide_prompt_widget) prompter.show_prompt.connect(self._show_prompt_widget)
prompter.hide_prompt.connect(self._hide_prompt_widget)
self._hide_prompt_widget() self._hide_prompt_widget()
self.keystring = keystring.KeyString() self.keystring = keystring.KeyString()

View File

@ -44,15 +44,8 @@ class Prompt(QWidget):
txt: The TextBase instance (QLabel) used to display the prompt text. txt: The TextBase instance (QLabel) used to display the prompt text.
lineedit: The MinimalLineEdit instance (QLineEdit) used for the input. lineedit: The MinimalLineEdit instance (QLineEdit) used for the input.
_hbox: The QHBoxLayout used to display the text and prompt. _hbox: The QHBoxLayout used to display the text and prompt.
Signals:
show_prompt: Emitted when the prompt widget wants to be shown.
hide_prompt: Emitted when the prompt widget wants to be hidden.
""" """
show_prompt = pyqtSignal()
hide_prompt = pyqtSignal()
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent) super().__init__(parent)
objreg.register('prompt', self) objreg.register('prompt', self)
@ -66,7 +59,7 @@ class Prompt(QWidget):
self.lineedit = PromptLineEdit() self.lineedit = PromptLineEdit()
self._hbox.addWidget(self.lineedit) self._hbox.addWidget(self.lineedit)
prompter_obj = prompter.Prompter() prompter_obj = prompter.Prompter(self)
objreg.register('prompter', prompter_obj) objreg.register('prompter', prompter_obj)
def __repr__(self): def __repr__(self):

View File

@ -21,7 +21,7 @@
import collections import collections
from PyQt5.QtCore import pyqtSlot, QTimer from PyQt5.QtCore import pyqtSlot, pyqtSignal, QTimer, QObject
from PyQt5.QtWidgets import QLineEdit from PyQt5.QtWidgets import QLineEdit
from qutebrowser.keyinput import modeman from qutebrowser.keyinput import modeman
@ -34,7 +34,7 @@ PromptContext = collections.namedtuple('PromptContext',
'echo_mode', 'input_visible']) 'echo_mode', 'input_visible'])
class Prompter: class Prompter(QObject):
"""Manager for questions to be shown in the statusbar. """Manager for questions to be shown in the statusbar.
@ -60,9 +60,17 @@ class Prompter:
_question: A Question object with the question to be asked to the user. _question: A Question object with the question to be asked to the user.
_loops: A list of local EventLoops to spin in when blocking. _loops: A list of local EventLoops to spin in when blocking.
_queue: A deque of waiting questions. _queue: A deque of waiting questions.
Signals:
show_prompt: Emitted when the prompt widget should be shown.
hide_prompt: Emitted when the prompt widget should be hidden.
""" """
def __init__(self): show_prompt = pyqtSignal()
hide_prompt = pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent)
self._question = None self._question = None
self._loops = [] self._loops = []
self._queue = collections.deque() self._queue = collections.deque()
@ -106,7 +114,7 @@ class Prompter:
log.statusbar.debug("Restoring context {}".format(ctx)) log.statusbar.debug("Restoring context {}".format(ctx))
prompt = objreg.get('prompt') prompt = objreg.get('prompt')
if ctx is None: if ctx is None:
prompt.hide_prompt.emit() self.hide_prompt.emit()
self._busy = False self._busy = False
return False return False
self._question = ctx.question self._question = ctx.question
@ -114,7 +122,7 @@ class Prompter:
prompt.lineedit.setText(ctx.input_text) prompt.lineedit.setText(ctx.input_text)
prompt.lineedit.setEchoMode(ctx.echo_mode) prompt.lineedit.setEchoMode(ctx.echo_mode)
prompt.lineedit.setVisible(ctx.input_visible) prompt.lineedit.setVisible(ctx.input_visible)
prompt.show_prompt.emit() self.show_prompt.emit()
return True return True
def _display_question(self): def _display_question(self):
@ -156,7 +164,7 @@ class Prompter:
else: else:
raise ValueError("Invalid prompt mode!") raise ValueError("Invalid prompt mode!")
prompt.lineedit.setFocus() prompt.lineedit.setFocus()
prompt.show_prompt.emit() self.show_prompt.emit()
self._busy = True self._busy = True
return mode return mode
@ -185,7 +193,7 @@ class Prompter:
prompt.txt.setText('') prompt.txt.setText('')
prompt.lineedit.clear() prompt.lineedit.clear()
prompt.lineedit.setEchoMode(QLineEdit.Normal) prompt.lineedit.setEchoMode(QLineEdit.Normal)
prompt.hide_prompt.emit() self.hide_prompt.emit()
self._busy = False self._busy = False
if self._question.answer is None and not self._question.is_aborted: if self._question.answer is None and not self._question.is_aborted:
self._question.cancel() self._question.cancel()