Use multiple eventloops
This commit is contained in:
parent
2b9f337758
commit
49fd9951ed
@ -34,7 +34,7 @@ class Prompt(QWidget):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
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.
|
||||||
loop: A local EventLoop to spin in exec_.
|
loops: A list of local EventLoops to spin into in exec_.
|
||||||
_hbox: The QHBoxLayout used to display the text and prompt.
|
_hbox: The QHBoxLayout used to display the text and prompt.
|
||||||
_txt: The TextBase instance (QLabel) used to display the prompt text.
|
_txt: The TextBase instance (QLabel) used to display the prompt text.
|
||||||
_input: The MinimalLineEdit instance (QLineEdit) used for the input.
|
_input: The MinimalLineEdit instance (QLineEdit) used for the input.
|
||||||
@ -51,7 +51,7 @@ class Prompt(QWidget):
|
|||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self.question = None
|
self.question = None
|
||||||
self.loop = EventLoop()
|
self.loops = []
|
||||||
|
|
||||||
self._hbox = QHBoxLayout(self)
|
self._hbox = QHBoxLayout(self)
|
||||||
self._hbox.setContentsMargins(0, 0, 0, 0)
|
self._hbox.setContentsMargins(0, 0, 0, 0)
|
||||||
@ -194,8 +194,11 @@ class Prompt(QWidget):
|
|||||||
Return:
|
Return:
|
||||||
The answer to the question. No, it's not always 42.
|
The answer to the question. No, it's not always 42.
|
||||||
"""
|
"""
|
||||||
self.question.answered.connect(self.loop.quit)
|
loop = EventLoop()
|
||||||
self.question.cancelled.connect(self.loop.quit)
|
self.loops.append(loop)
|
||||||
self.question.aborted.connect(self.loop.quit)
|
loop.destroyed.connect(lambda: self.loops.remove(loop))
|
||||||
self.loop.exec_()
|
self.question.answered.connect(loop.quit)
|
||||||
|
self.question.cancelled.connect(loop.quit)
|
||||||
|
self.question.aborted.connect(loop.quit)
|
||||||
|
loop.exec_()
|
||||||
return self.question.answer
|
return self.question.answer
|
||||||
|
Loading…
Reference in New Issue
Block a user