diff --git a/cura/PrinterOutput/UploadMaterialsJob.py b/cura/PrinterOutput/UploadMaterialsJob.py index d000d1ba2d..b082b47cbb 100644 --- a/cura/PrinterOutput/UploadMaterialsJob.py +++ b/cura/PrinterOutput/UploadMaterialsJob.py @@ -18,7 +18,7 @@ from UM.Signal import Signal from UM.TaskManagement.HttpRequestManager import HttpRequestManager # To call the API. from UM.TaskManagement.HttpRequestScope import JsonDecoratorScope -from typing import Dict, Optional, TYPE_CHECKING +from typing import Any, Dict, Optional, TYPE_CHECKING if TYPE_CHECKING: from PyQt5.QtNetwork import QNetworkReply from cura.UltimakerCloud.CloudMaterialSync import CloudMaterialSync @@ -42,7 +42,7 @@ class UploadMaterialsJob(Job): UPLOAD_CONFIRM_URL = UltimakerCloudConstants.CuraCloudAPIRoot + "/connect/v1/clusters/{cluster_id}/printers/{cluster_printer_id}/action/confirm_material_upload" class Result(enum.IntEnum): - SUCCCESS = 0 + SUCCESS = 0 FAILED = 1 def __init__(self, material_sync: "CloudMaterialSync"): @@ -51,8 +51,8 @@ class UploadMaterialsJob(Job): self._scope = JsonDecoratorScope(UltimakerCloudScope(cura.CuraApplication.CuraApplication.getInstance())) # type: JsonDecoratorScope self._archive_filename = None # type: Optional[str] self._archive_remote_id = None # type: Optional[str] # ID that the server gives to this archive. Used to communicate about the archive to the server. - self._printer_sync_status = {} - self._printer_metadata = {} + self._printer_sync_status = {} # type: Dict[str, str] + self._printer_metadata = {} # type: Dict[str, Any] self.processProgressChanged.connect(self._onProcessProgressChanged) uploadCompleted = Signal() @@ -113,7 +113,8 @@ class UploadMaterialsJob(Job): upload_url = response_data["upload_url"] self._archive_remote_id = response_data["material_profile_id"] - file_data = open(self._archive_filename, "rb").read() + with open(self._archive_filename, "rb") as f: + file_data = f.read() http = HttpRequestManager.getInstance() http.put( url = upload_url, diff --git a/cura/UltimakerCloud/CloudMaterialSync.py b/cura/UltimakerCloud/CloudMaterialSync.py index 99282d7eb1..3a9402c36e 100644 --- a/cura/UltimakerCloud/CloudMaterialSync.py +++ b/cura/UltimakerCloud/CloudMaterialSync.py @@ -27,8 +27,8 @@ class CloudMaterialSync(QObject): self.sync_all_dialog = None # type: Optional[QObject] self._export_upload_status = "idle" self._checkIfNewMaterialsWereInstalled() - self._export_progress = 0 - self._printer_status = {} + self._export_progress = 0.0 + self._printer_status = {} # type: Dict[str, str] def _checkIfNewMaterialsWereInstalled(self) -> None: """ @@ -161,6 +161,8 @@ class CloudMaterialSync(QObject): self.setPrinterStatus(printers_status) def exportUploadCompleted(self, job_result: UploadMaterialsJob.Result, job_error: Optional[Exception]): + if not self.sync_all_dialog: # Shouldn't get triggered before the dialog is open, but better to check anyway. + return if job_result == UploadMaterialsJob.Result.FAILED: if isinstance(job_error, UploadMaterialsError): self.sync_all_dialog.setProperty("syncStatusText", catalog.i18nc("@text", "Error sending materials to the Digital Factory:") + " " + str(job_error)) diff --git a/cura/UltimakerCloud/UltimakerCloudScope.py b/cura/UltimakerCloud/UltimakerCloudScope.py index c8ac35f893..bbcc8e2aa9 100644 --- a/cura/UltimakerCloud/UltimakerCloudScope.py +++ b/cura/UltimakerCloud/UltimakerCloudScope.py @@ -5,11 +5,11 @@ from PyQt5.QtNetwork import QNetworkRequest from UM.Logger import Logger from UM.TaskManagement.HttpRequestScope import DefaultUserAgentScope -from cura.API import Account from typing import TYPE_CHECKING if TYPE_CHECKING: from cura.CuraApplication import CuraApplication + from cura.API.Account import Account class UltimakerCloudScope(DefaultUserAgentScope):