-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
59 lines (47 loc) · 1.46 KB
/
code.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# Ayda Alinasab , Mohammad Sohrabi
import sys
from PyQt5.QtWidgets import QApplication, QDialog, QProgressBar, QPushButton
from PyQt5.QtCore import QThread, pyqtSignal
# x = int(input("> "))
x = 10000
class MyThread(QThread):
counter = pyqtSignal(int)
def run(self):
n1, n2 = 0, 1
if x <= 0:
print("Please enter a positive integer")
elif x == 1:
print("Fibonacci sequence upto", x, ":")
print(n1)
else:
file = open("fibs.txt", "w")
for j in range(x):
file.write(f"{n1}\n")
self.counter.emit(j)
nth = n1 + n2
n1 = n2
n2 = nth
class Actions(QDialog):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Progress Bar')
self.pbar = QProgressBar(self)
self.pbar.setGeometry(30, 40, 200, 25)
self.pbar.setMaximum(x-1)
self.btn = QPushButton('Start', self)
self.btn.move(40, 80)
self.btn.clicked.connect(self.doAction)
self.setGeometry(300, 300, 280, 170)
self.show()
def doAction(self):
self.calc = MyThread()
self.calc.counter.connect(self.onChanged)
self.calc.start()
def onChanged(self, value):
self.pbar.setValue(value)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = Actions()
sys.exit(app.exec_())