mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 07:27:29 -06:00
Expose printer status updates via progress update signal
This way we can ask the printer status from QML even if it's updated via a job on a different thread and different class and all that. Contributes to issue CURA-8609.
This commit is contained in:
parent
8607eb5cff
commit
0fa6f650f6
2 changed files with 28 additions and 5 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QUrl
|
||||
from PyQt5.QtGui import QDesktopServices
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
from typing import Dict, Optional, TYPE_CHECKING
|
||||
import zipfile # To export all materials in a .zip archive.
|
||||
|
||||
import cura.CuraApplication # Imported like this to prevent circular imports.
|
||||
|
@ -28,6 +28,7 @@ class CloudMaterialSync(QObject):
|
|||
self._export_upload_status = "idle"
|
||||
self._checkIfNewMaterialsWereInstalled()
|
||||
self._export_progress = 0
|
||||
self._printer_status = {}
|
||||
|
||||
def _checkIfNewMaterialsWereInstalled(self) -> None:
|
||||
"""
|
||||
|
@ -151,10 +152,14 @@ class CloudMaterialSync(QObject):
|
|||
self._export_upload_status = "uploading"
|
||||
self.exportUploadStatusChanged.emit()
|
||||
job = UploadMaterialsJob(self)
|
||||
job.uploadProgressChanged.connect(self.setExportProgress)
|
||||
job.uploadProgressChanged.connect(self._onUploadProgressChanged)
|
||||
job.uploadCompleted.connect(self.exportUploadCompleted)
|
||||
job.start()
|
||||
|
||||
def _onUploadProgressChanged(self, progress: float, printers_status: Dict[str, str]):
|
||||
self.setExportProgress(progress)
|
||||
self.setPrinterStatus(printers_status)
|
||||
|
||||
def exportUploadCompleted(self, job_result: UploadMaterialsJob.Result, job_error: Optional[Exception]):
|
||||
if job_result == UploadMaterialsJob.Result.FAILED:
|
||||
if isinstance(job_error, UploadMaterialsError):
|
||||
|
@ -174,4 +179,14 @@ class CloudMaterialSync(QObject):
|
|||
|
||||
@pyqtProperty(float, fset = setExportProgress, notify = exportProgressChanged)
|
||||
def exportProgress(self) -> float:
|
||||
return self._export_progress
|
||||
return self._export_progress
|
||||
|
||||
printerStatusChanged = pyqtSignal()
|
||||
|
||||
def setPrinterStatus(self, new_status: Dict[str, str]) -> None:
|
||||
self._printer_status = new_status
|
||||
self.printerStatusChanged.emit()
|
||||
|
||||
@pyqtProperty("QVariantMap", fset = setPrinterStatus, notify = printerStatusChanged)
|
||||
def printerStatus(self) -> Dict[str, str]:
|
||||
return self._printer_status
|
Loading…
Add table
Add a link
Reference in a new issue