Created
June 15, 2019 14:35
-
-
Save vivekjoshy/6ab0074b56b07775b4f61eb43b9679f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from PyQt5.QtCore import QThread, pyqtSignal | |
from PyQt5.QtWidgets import (QApplication, QDialog, | |
QProgressBar, QPushButton) | |
TIME_LIMIT = 100 | |
class External(QThread): | |
""" | |
Runs a counter thread. | |
""" | |
countChanged = pyqtSignal(int) | |
def run(self): | |
count = 0 | |
while count < TIME_LIMIT: | |
count +=1 | |
time.sleep(1) | |
self.countChanged.emit(count) | |
class Actions(QDialog): | |
""" | |
Simple dialog that consists of a Progress Bar and a Button. | |
Clicking on the button results in the start of a timer and | |
updates the progress bar. | |
""" | |
def __init__(self): | |
super().__init__() | |
self.initUI() | |
def initUI(self): | |
self.setWindowTitle('Progress Bar') | |
self.progress = QProgressBar(self) | |
self.progress.setGeometry(0, 0, 300, 25) | |
self.progress.setMaximum(100) | |
self.button = QPushButton('Start', self) | |
self.button.move(0, 30) | |
self.show() | |
self.button.clicked.connect(self.onButtonClick) | |
def onButtonClick(self): | |
self.calc = External() | |
self.calc.countChanged.connect(self.onCountChanged) | |
self.calc.start() | |
def onCountChanged(self, value): | |
self.progress.setValue(value) | |
if __name__ == "__main__": | |
app = QApplication(sys.argv) | |
window = Actions() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment