-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasync_test.py
38 lines (26 loc) · 975 Bytes
/
async_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import PySide6.QtAsyncio as QtAsyncio
from promisio import promisify
from qtstrap import *
class ChoiceDialog(AwaitableDialog):
def __init__(self, parent):
super().__init__(parent=parent, modal=True)
with CVBoxLayout(self) as layout:
layout.add(QPushButton('one', clicked=lambda: self.submit('one')))
layout.add(QPushButton('two', clicked=lambda: self.submit('two')))
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
button = QPushButton(text='pick one')
button.clicked(self.ask_question)
with CVBoxLayout(self) as layout:
layout.add(button)
self.label = layout.add(QLabel())
self.show()
@promisify
async def ask_question(self):
result = await ChoiceDialog(self)
self.label.setText(result)
if __name__ == '__main__':
app = QApplication()
window = MainWindow()
QtAsyncio.run(handle_sigint=True)