Merge branch 'CURA-7147_preview_img_for_cloud' of github.com:Ultimaker/Cura into 4.6

This commit is contained in:
Jaime van Kessel 2020-04-16 15:11:20 +02:00
commit 2da965e46e
No known key found for this signature in database
GPG Key ID: 3710727397403C91
3 changed files with 22 additions and 4 deletions

View File

@ -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. # Cura is released under the terms of the LGPLv3 or higher.
from typing import List, Optional, Union, Dict, Any 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 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 # \param impediments_to_printing: A list of reasons that prevent this job from being printed on the associated
# printer # 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, def __init__(self, created_at: str, force: bool, machine_variant: str, name: str, started: bool, status: str,
time_total: int, uuid: str, time_total: int, uuid: str,
configuration: List[Union[Dict[str, Any], ClusterPrintCoreConfiguration]], configuration: List[Union[Dict[str, Any], ClusterPrintCoreConfiguration]],
@ -57,6 +58,7 @@ class ClusterPrintJobStatus(BaseModel):
build_plate: Union[Dict[str, Any], ClusterBuildPlate] = None, build_plate: Union[Dict[str, Any], ClusterBuildPlate] = None,
compatible_machine_families: List[str] = None, compatible_machine_families: List[str] = None,
impediments_to_printing: List[Union[Dict[str, Any], ClusterPrintJobImpediment]] = None, impediments_to_printing: List[Union[Dict[str, Any], ClusterPrintJobImpediment]] = None,
preview_url: Optional[str] = None,
**kwargs) -> None: **kwargs) -> None:
self.assigned_to = assigned_to self.assigned_to = assigned_to
self.configuration = self.parseModels(ClusterPrintCoreConfiguration, configuration) self.configuration = self.parseModels(ClusterPrintCoreConfiguration, configuration)
@ -76,6 +78,7 @@ class ClusterPrintJobStatus(BaseModel):
self.uuid = uuid self.uuid = uuid
self.deleted_at = deleted_at self.deleted_at = deleted_at
self.printed_on_uuid = printed_on_uuid self.printed_on_uuid = printed_on_uuid
self.preview_url = preview_url
self.configuration_changes_required = self.parseModels(ClusterPrintJobConfigurationChange, self.configuration_changes_required = self.parseModels(ClusterPrintJobConfigurationChange,
configuration_changes_required) \ configuration_changes_required) \

View File

@ -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. # 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.QtCore import pyqtProperty, pyqtSignal
from PyQt5.QtGui import QImage 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.Models.PrintJobOutputModel import PrintJobOutputModel
from cura.PrinterOutput.PrinterOutputController import PrinterOutputController from cura.PrinterOutput.PrinterOutputController import PrinterOutputController
@ -32,3 +35,13 @@ class UM3PrintJobOutputModel(PrintJobOutputModel):
image = QImage() image = QImage()
image.loadFromData(data) image.loadFromData(data)
self.updatePreviewImage(image) 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())

View File

@ -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. # Cura is released under the terms of the LGPLv3 or higher.
import os import os
from time import time from time import time
@ -330,6 +330,8 @@ class UltimakerNetworkedPrinterOutputDevice(NetworkedPrinterOutputDevice):
self._updateAssignedPrinter(model, remote_job.printer_uuid) self._updateAssignedPrinter(model, remote_job.printer_uuid)
if remote_job.assigned_to: if remote_job.assigned_to:
self._updateAssignedPrinter(model, remote_job.assigned_to) self._updateAssignedPrinter(model, remote_job.assigned_to)
if remote_job.preview_url:
model.loadPreviewImageFromUrl(remote_job.preview_url)
return model return model
## Updates the printer assignment for the given print job model. ## Updates the printer assignment for the given print job model.