-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
59 lines (47 loc) · 1.76 KB
/
app.py
File metadata and controls
59 lines (47 loc) · 1.76 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from PySide6.QtWidgets import QApplication, QMainWindow
from ui.ui_untitled import Ui_MainWindow
import asyncio, PySide6.QtAsyncio as QtAsyncio, time
from PySide6.QtCore import Qt
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.number = 0
self.ui.label.setText("Push the button")
self.task = None # 비동기 제어를 위한 변수 초기화
def countUp(self):
self.number += 1
self.ui.label.setText(str(self.number))
def heavyCountUp(self):
for _ in range(100):
self.countUp()
time.sleep(0.01)
async def asyncHeavyCountUp(self):
for _ in range(100):
self.countUp()
await asyncio.sleep(0.01)
def clickBtn(self):
# 기존 작업 실행 여부 확인하기
if self.task is not None and not self.task.done():
try:
self.task.cancel()
except asyncio.CancelledError:
pass
finally:
self.task = None
self.number = 0
# chkBox 상태 확인하기
# if self.ui.chkAsync.checkState() == Qt.CheckState.Checked:
if self.ui.chkAsync.isChecked():
self.task = asyncio.create_task(self.asyncHeavyCountUp())
# self.ui.chkAsync.setCheckState(Qt.CheckState.PartiallyChecked) # isChecked 에 포함됨
self.ui.chkAsync.setChecked(False) # 체크박스 상태 초기화
else:
self.heavyCountUp()
if __name__ == "__main__":
app = QApplication()
window = MainWindow()
window.ui.btnClick.clicked.connect(window.clickBtn)
window.show()
QtAsyncio.run()