I have a PyQT GUI application progress_bar.py
with a single progressbar and an external module worker.py
with a process_files()
function which does some routine with a list of files and reports current progress using percent
variable.
What I want to do is to report the current progress of the worker.process_files
using QProgressBar.setValue()
method, but I have no idea how to implement it (callback function or something?)
Here are my modules:
progress_bar.py
import sys
from PyQt4 import QtGui
from worker import process_files
class Window(QtGui.QMainWindow):
def __init__(self):
super(Window, self).__init__()
self.setGeometry(100, 100, 300, 100)
self.progress = QtGui.QProgressBar(self)
self.progress.setGeometry(100, 50, 150, 20)
self.progress.setValue(0)
self.show()
app = QtGui.QApplication(sys.argv)
GUI = Window()
# process files and report progress using .setValue(percent)
process_files()
sys.exit(app.exec_())
worker.py
def process_files():
file_list = ['file1', 'file2', 'file3']
counter = 0
for file in file_list:
# do_stuff_with_the_file
counter += 1
percent = 100 * counter / len(file_list)
print percent
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…