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.hide_cmd.connect(self._hide_cmd_widget)
self._hide_cmd_widget()
self.prompt.show_prompt.connect(self._show_prompt_widget)
self.prompt.hide_prompt.connect(self._hide_prompt_widget)
prompter = objreg.get('prompter')
prompter.show_prompt.connect(self._show_prompt_widget)
prompter.hide_prompt.connect(self._hide_prompt_widget)
self._hide_prompt_widget()
self.keystring = keystring.KeyString()

View File

@ -44,15 +44,8 @@ class Prompt(QWidget):
txt: The TextBase instance (QLabel) used to display the prompt text.
lineedit: The MinimalLineEdit instance (QLineEdit) used for the input.
_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):
super().__init__(parent)
objreg.register('prompt', self)
@ -66,7 +59,7 @@ class Prompt(QWidget):
self.lineedit = PromptLineEdit()
self._hbox.addWidget(self.lineedit)
prompter_obj = prompter.Prompter()
prompter_obj = prompter.Prompter(self)
objreg.register('prompter', prompter_obj)
def __repr__(self):

View File

@ -21,7 +21,7 @@
import collections
from PyQt5.QtCore import pyqtSlot, QTimer
from PyQt5.QtCore import pyqtSlot, pyqtSignal, QTimer, QObject
from PyQt5.QtWidgets import QLineEdit
from qutebrowser.keyinput import modeman
@ -34,7 +34,7 @@ PromptContext = collections.namedtuple('PromptContext',
'echo_mode', 'input_visible'])
class Prompter:
class Prompter(QObject):
"""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.
_loops: A list of local EventLoops to spin in when blocking.
_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._loops = []
self._queue = collections.deque()
@ -106,7 +114,7 @@ class Prompter:
log.statusbar.debug("Restoring context {}".format(ctx))
prompt = objreg.get('prompt')
if ctx is None:
prompt.hide_prompt.emit()
self.hide_prompt.emit()
self._busy = False
return False
self._question = ctx.question
@ -114,7 +122,7 @@ class Prompter:
prompt.lineedit.setText(ctx.input_text)
prompt.lineedit.setEchoMode(ctx.echo_mode)
prompt.lineedit.setVisible(ctx.input_visible)
prompt.show_prompt.emit()
self.show_prompt.emit()
return True
def _display_question(self):
@ -156,7 +164,7 @@ class Prompter:
else:
raise ValueError("Invalid prompt mode!")
prompt.lineedit.setFocus()
prompt.show_prompt.emit()
self.show_prompt.emit()
self._busy = True
return mode
@ -185,7 +193,7 @@ class Prompter:
prompt.txt.setText('')
prompt.lineedit.clear()
prompt.lineedit.setEchoMode(QLineEdit.Normal)
prompt.hide_prompt.emit()
self.hide_prompt.emit()
self._busy = False
if self._question.answer is None and not self._question.is_aborted:
self._question.cancel()