Make sure progress UI updates occur on main thread

This commit is contained in:
Brett Williams
2023-11-16 06:13:12 -06:00
parent 0e0eba7b22
commit 6dc8db2d8c

View File

@@ -5,7 +5,7 @@ import socket
import threading
import psutil
from PyQt6.QtCore import QThread, pyqtSignal, Qt
from PyQt6.QtCore import QThread, pyqtSignal, Qt, pyqtSlot
from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel, QLineEdit, QPushButton, QFileDialog, QSpinBox, QComboBox,
QGroupBox, QCheckBox, QProgressBar, QPlainTextEdit, QDoubleSpinBox, QMessageBox, QListWidget, QListWidgetItem
@@ -402,14 +402,23 @@ class NewRenderJobForm(QWidget):
# submit job in background thread
self.worker_thread = SubmitWorker(window=self)
self.worker_thread.update_ui_signal.connect(self.update_submit_progress)
self.worker_thread.message_signal.connect(self.after_job_submission)
self.worker_thread.start()
@pyqtSlot(str, str)
def update_submit_progress(self, hostname, percent):
# Update the UI here. This slot will be executed in the main thread
self.submit_progress_label.setText(f"Transferring to {hostname} - {percent}%")
self.submit_progress.setMaximum(100)
self.submit_progress.setValue(int(percent))
class SubmitWorker(QThread):
"""Worker class called to submit all the jobs to the server and update the UI accordingly"""
message_signal = pyqtSignal(Response)
update_ui_signal = pyqtSignal(str, str)
def __init__(self, window):
super().__init__()
@@ -421,10 +430,7 @@ class SubmitWorker(QThread):
def callback(monitor):
percent = f"{monitor.bytes_read / encoder_len * 100:.0f}"
self.window.submit_progress_label.setText(f"Transferring to {hostname} - {percent}%")
self.window.submit_progress.setMaximum(100)
self.window.submit_progress.setValue(int(percent))
self.update_ui_signal.emit(hostname, percent)
return callback
hostname = self.window.server_input.currentText()