Update on a separate thread
offlate/ui/editor.py
329 | 329 | self.projectManagerWindow.new() | |
330 | 330 | ||
331 | 331 | def send(self): | |
332 | - | self.actionLabel.setText(self.tr("Uploading {}...").format(self.tabs.currentWidget().project.name)) | |
332 | + | self.setLabels(self.tr("Uploading {}...").format(self.tabs.currentWidget().project.name)) | |
333 | 333 | worker = UploadRunnable(self.tabs.currentWidget()) | |
334 | 334 | worker.signals.finished.connect(self.sent) | |
335 | 335 | self.threadpool.start(worker) | |
336 | 336 | ||
337 | 337 | def sent(self, name): | |
338 | - | self.actionLabel.setText(self.tr("Upload of {} finished!").format(name)) | |
338 | + | self.setLabels(self.tr("Finished uploading {}!").format(name)) | |
339 | 339 | ||
340 | 340 | def update(self): | |
341 | - | self.tabs.currentWidget().update() | |
341 | + | self.setLabels(self.tr("Updating {}...").format(self.tabs.currentWidget().project.name)) | |
342 | + | self.setProgresses(0) | |
343 | + | worker = UpdateRunnable(self.tabs.currentWidget()) | |
344 | + | worker.signals.finished.connect(self.updated) | |
345 | + | worker.signals.progress.connect(self.reportProgress) | |
346 | + | self.threadpool.start(worker) | |
347 | + | ||
348 | + | def updated(self, name): | |
342 | 349 | self.manager.update() | |
343 | 350 | self.manager.writeProjects() | |
351 | + | self.setProgresses(0, False) | |
352 | + | self.setLabels(self.tr("Finished updating {}!").format(name)) | |
353 | + | ||
354 | + | def reportProgress(self, name, progress): | |
355 | + | self.setProgresses(progress) | |
356 | + | ||
357 | + | def setLabels(self, value): | |
358 | + | self.actionLabel.setText(value) | |
359 | + | self.projectManagerWindow.projectManagerWidget.actionLabel.setText(value) | |
360 | + | ||
361 | + | def setProgresses(self, progress, enable=True): | |
362 | + | self.actionProgress.setEnabled(enable) | |
363 | + | self.actionProgress.setValue(progress) | |
364 | + | self.projectManagerWindow.projectManagerWidget.actionProgress.setEnabled(enable) | |
365 | + | self.projectManagerWindow.projectManagerWidget.actionProgress.setValue(progress) | |
344 | 366 | ||
345 | 367 | def closeProject(self): | |
346 | 368 | self.tabs.removeTab(self.tabs.currentIndex()) | |
… | |||
490 | 512 | def run(self): | |
491 | 513 | self.widget.send() | |
492 | 514 | self.signals.finished.emit(self.widget.project.name) | |
515 | + | ||
516 | + | class UpdateRunnable(QRunnable, RunnableCallback): | |
517 | + | def __init__(self, widget): | |
518 | + | super().__init__() | |
519 | + | self.widget = widget | |
520 | + | self.signals = RunnableSignals() | |
521 | + | ||
522 | + | def run(self): | |
523 | + | self.widget.update() | |
524 | + | self.signals.finished.emit(self.widget.project.name) |