From 006822334ca3a1f9f24db63024e349fd1df428d8 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 16 Apr 2020 12:18:49 +0200 Subject: [PATCH 1/2] Fetch preview image from cloud for monitor page. part of CURA-7147 --- .../src/Models/Http/ClusterPrintJobStatus.py | 5 ++++- .../src/Models/UM3PrintJobOutputModel.py | 17 +++++++++++++++-- .../UltimakerNetworkedPrinterOutputDevice.py | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/plugins/UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py b/plugins/UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py index 9794da1bbb..be1768918f 100644 --- a/plugins/UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py +++ b/plugins/UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Ultimaker B.V. +# Copyright (c) 2020 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. from typing import List, Optional, Union, Dict, Any @@ -44,6 +44,7 @@ class ClusterPrintJobStatus(BaseModel): # \param compatible_machine_families: Family names of machines suitable for this print job # \param impediments_to_printing: A list of reasons that prevent this job from being printed on the associated # printer + # \param preview_url: URL to the preview image (same as wou;d've been included in the ufp). def __init__(self, created_at: str, force: bool, machine_variant: str, name: str, started: bool, status: str, time_total: int, uuid: str, configuration: List[Union[Dict[str, Any], ClusterPrintCoreConfiguration]], @@ -57,6 +58,7 @@ class ClusterPrintJobStatus(BaseModel): build_plate: Union[Dict[str, Any], ClusterBuildPlate] = None, compatible_machine_families: List[str] = None, impediments_to_printing: List[Union[Dict[str, Any], ClusterPrintJobImpediment]] = None, + preview_url = None, **kwargs) -> None: self.assigned_to = assigned_to self.configuration = self.parseModels(ClusterPrintCoreConfiguration, configuration) @@ -76,6 +78,7 @@ class ClusterPrintJobStatus(BaseModel): self.uuid = uuid self.deleted_at = deleted_at self.printed_on_uuid = printed_on_uuid + self.preview_url = preview_url self.configuration_changes_required = self.parseModels(ClusterPrintJobConfigurationChange, configuration_changes_required) \ diff --git a/plugins/UM3NetworkPrinting/src/Models/UM3PrintJobOutputModel.py b/plugins/UM3NetworkPrinting/src/Models/UM3PrintJobOutputModel.py index bfde233a35..b063a2bf5b 100644 --- a/plugins/UM3NetworkPrinting/src/Models/UM3PrintJobOutputModel.py +++ b/plugins/UM3NetworkPrinting/src/Models/UM3PrintJobOutputModel.py @@ -1,10 +1,13 @@ -# Copyright (c) 2019 Ultimaker B.V. +# Copyright (c) 2020 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from typing import List +from typing import List, Optional from PyQt5.QtCore import pyqtProperty, pyqtSignal from PyQt5.QtGui import QImage +from PyQt5.QtNetwork import QNetworkReply, QNetworkRequest +from UM.Logger import Logger +from UM.TaskManagement.HttpRequestManager import HttpRequestManager from cura.PrinterOutput.Models.PrintJobOutputModel import PrintJobOutputModel from cura.PrinterOutput.PrinterOutputController import PrinterOutputController @@ -32,3 +35,13 @@ class UM3PrintJobOutputModel(PrintJobOutputModel): image = QImage() image.loadFromData(data) self.updatePreviewImage(image) + + def loadPreviewImageFromUrl(self, url: str) -> None: + HttpRequestManager.getInstance().get(url=url, callback=self._onImageLoaded, error_callback=self._onImageLoaded) + + def _onImageLoaded(self, reply: QNetworkReply, error: Optional["QNetworkReply.NetworkError"] = None) -> None: + if not HttpRequestManager.replyIndicatesSuccess(reply, error): + Logger.warning("Requesting preview image failed, response code {0} while trying to connect to {1}".format( + reply.attribute(QNetworkRequest.HttpStatusCodeAttribute), reply.url())) + return + self.updatePreviewImageData(reply.readAll()) diff --git a/plugins/UM3NetworkPrinting/src/UltimakerNetworkedPrinterOutputDevice.py b/plugins/UM3NetworkPrinting/src/UltimakerNetworkedPrinterOutputDevice.py index 73b5b456f9..7eed52a9dc 100644 --- a/plugins/UM3NetworkPrinting/src/UltimakerNetworkedPrinterOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/UltimakerNetworkedPrinterOutputDevice.py @@ -1,4 +1,4 @@ -# Copyright (c) 2019 Ultimaker B.V. +# Copyright (c) 2020 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. import os from time import time @@ -330,6 +330,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice): self._updateAssignedPrinter(model, remote_job.printer_uuid) if remote_job.assigned_to: self._updateAssignedPrinter(model, remote_job.assigned_to) + if remote_job.preview_url: + model.loadPreviewImageFromUrl(remote_job.preview_url) return model ## Updates the printer assignment for the given print job model. From ac5213d2325d953e8ddc47d47c96c76688687a85 Mon Sep 17 00:00:00 2001 From: Remco Burema Date: Thu, 16 Apr 2020 12:59:36 +0200 Subject: [PATCH 2/2] Fix typing. part of CURA-7147 --- .../UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py b/plugins/UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py index be1768918f..22fb9bb37a 100644 --- a/plugins/UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py +++ b/plugins/UM3NetworkPrinting/src/Models/Http/ClusterPrintJobStatus.py @@ -58,7 +58,7 @@ class ClusterPrintJobStatus(BaseModel): build_plate: Union[Dict[str, Any], ClusterBuildPlate] = None, compatible_machine_families: List[str] = None, impediments_to_printing: List[Union[Dict[str, Any], ClusterPrintJobImpediment]] = None, - preview_url = None, + preview_url: Optional[str] = None, **kwargs) -> None: self.assigned_to = assigned_to self.configuration = self.parseModels(ClusterPrintCoreConfiguration, configuration)