PyQt ProgressBar: Update progress from other threads

Categories: Python; Tagged with: ; @ May 14th, 2015 23:40

Issue 1: UI is no responding when the progress is running


Create new thread to perform the progress:
http://stackoverflow.com/questions/6783194/background-thread-with-qthread-in-pyqt

Issue 2: QThread: Destroyed while thread is still running

Try to keep a reference:
http://stackoverflow.com/questions/8359469/python-threading-thread-scopes-and-garbage-collection

Issue 3: QWidget::repaint: Recursive repaint detected


Use single to update progress:
http://stackoverflow.com/questions/9682376/progress-bar-with-pyqt

 

Example: UploadThread:

class UploadTaskQtThread(QtCore.QThread):
    tick = QtCore.pyqtSignal(int, name="upload_changed")

    def __init__(self, client, local_path, remote_path):
        QtCore.QThread.__init__(self)
        self.client = client
        self.local_path = local_path
        self.remote_path = remote_path
        
    def on_progress(self, progress):
        self.tick.emit(progress * 100)
        
    def run(self):
        self.client.upload_file(self.local_path, self.remote_path, self.on_progress)

Client:

    def upload(self, local_file_path, remote_path):
        self.upload_thread = UploadTaskQtThread(client, local_file_path, remote_path)
        self.upload_thread.start()
        self.upload_thread.tick.connect(ui.progressBar.setValue)

<->



// Proudly powered by Apache, PHP, MySQL, WordPress, Bootstrap, etc,.