From 2f92f6ef50faba4b8c3875481b60e446bc6bc83b Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Thu, 20 Dec 2018 13:45:59 +0100 Subject: [PATCH] Simplify checking if cloud or network printer, small fixes --- .../NetworkedPrinterOutputDevice.py | 5 +++++ cura/Settings/MachineManager.py | 16 +++++++------- .../src/Cloud/CloudOutputDevice.py | 21 +++++++------------ .../src/ClusterUM3OutputDevice.py | 6 ++---- .../qml/PrinterSelector/MachineSelector.qml | 4 ++-- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py index d0a0b5076a..3dcc43dd00 100644 --- a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py +++ b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py @@ -150,6 +150,11 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): request.setHeader(QNetworkRequest.UserAgentHeader, self._user_agent) return request + ## This method was only available privately before, but it was actually called from SendMaterialJob.py. + # We now have a public equivalent as well. We did not remove the private one as plugins might be using that. + def createFormPart(self, content_header: str, data: bytes, content_type: Optional[str] = None) -> QHttpPart: + return self._createFormPart(content_header, data, content_type) + def _createFormPart(self, content_header: str, data: bytes, content_type: Optional[str] = None) -> QHttpPart: part = QHttpPart() diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 8d42ee59a2..66ee7f9543 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -533,14 +533,14 @@ class MachineManager(QObject): return False @pyqtProperty(bool, notify = printerConnectedStatusChanged) - def activeMachineHasCloudConnection(self) -> bool: - # A cloud connection is only available if the active output device actually is a cloud connected device. - # We cannot simply use the connection_type metadata entry as that's always set to 'NetworkConnection' - # if there was a network connection during setup, which is always the case. - output_device = next(iter(self._printer_output_devices), None) # type: Optional[PrinterOutputDevice] - if not output_device: - return False - return output_device.connectionType == ConnectionType.CloudConnection + def activeMachineHasActiveNetworkConnection(self) -> bool: + # A network connection is only available if any output device is actually a network connected device. + return any(d.connectionType == ConnectionType.NetworkConnection for d in self._printer_output_devices) + + @pyqtProperty(bool, notify = printerConnectedStatusChanged) + def activeMachineHasActiveCloudConnection(self) -> bool: + # A cloud connection is only available if any output device actually is a cloud connected device. + return any(d.connectionType == ConnectionType.CloudConnection for d in self._printer_output_devices) def activeMachineNetworkKey(self) -> str: if self._global_container_stack: diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py index c436418f5e..093aa05ea9 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py @@ -246,7 +246,8 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): if self._printers and not self._active_printer: self.setActivePrinter(self._printers[0]) - self.printersChanged.emit() # TODO: Make this more efficient by not updating every request + if added_printers or removed_printers or updated_printers: + self.printersChanged.emit() ## Updates the local list of print jobs with the list received from the cloud. # \param jobs: The print jobs received from the cloud. @@ -302,10 +303,10 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): ## Updates the printer assignment for the given print job model. def _updateAssignedPrinter(self, model: UM3PrintJobOutputModel, printer_uuid: str) -> None: printer = next((p for p in self._printers if printer_uuid == p.key), None) - if not printer: - return Logger.log("w", "Missing printer %s for job %s in %s", model.assignedPrinter, model.key, - [p.key for p in self._printers]) + Logger.log("w", "Missing printer %s for job %s in %s", model.assignedPrinter, model.key, + [p.key for p in self._printers]) + return printer.updateActivePrintJob(model) model.updateAssignedPrinter(printer) @@ -329,11 +330,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): def _onUploadError(self, message = None) -> None: self._progress.hide() self._uploaded_print_job = None - Message( - text = message or T.UPLOAD_ERROR, - title = T.ERROR, - lifetime = 10 - ).show() + Message(text = message or T.UPLOAD_ERROR, title = T.ERROR, lifetime = 10).show() self.writeError.emit() ## Shows a message when the upload has succeeded @@ -341,11 +338,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice): def _onPrintRequested(self, response: CloudPrintResponse) -> None: Logger.log("d", "The cluster will be printing this print job with the ID %s", response.cluster_job_id) self._progress.hide() - Message( - text = T.UPLOAD_SUCCESS_TEXT, - title = T.UPLOAD_SUCCESS_TITLE, - lifetime = 5 - ).show() + Message(text = T.UPLOAD_SUCCESS_TEXT, title = T.UPLOAD_SUCCESS_TITLE, lifetime = 5).show() self.writeFinished.emit() ## Gets the remote printers. diff --git a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py index a9a002aed7..75fd1e0f9e 100644 --- a/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py +++ b/plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py @@ -389,10 +389,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice): ## Called when the connection to the cluster changes. def connect(self) -> None: - # TODO: uncomment this once cloud implementation works for testing - # super().connect() - # self.sendMaterialProfiles() - pass + super().connect() + self.sendMaterialProfiles() def _onGetPreviewImageFinished(self, reply: QNetworkReply) -> None: reply_url = reply.url().toString() diff --git a/resources/qml/PrinterSelector/MachineSelector.qml b/resources/qml/PrinterSelector/MachineSelector.qml index bb8934f620..64cf3e6005 100644 --- a/resources/qml/PrinterSelector/MachineSelector.qml +++ b/resources/qml/PrinterSelector/MachineSelector.qml @@ -12,9 +12,9 @@ Cura.ExpandablePopup id: machineSelector property var outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null - property bool isNetworkPrinter: Cura.MachineManager.activeMachineHasRemoteConnection - property bool isCloudPrinter: Cura.MachineManager.activeMachineHasCloudConnection property bool isPrinterConnected: Cura.MachineManager.printerConnected + property bool isNetworkPrinter: Cura.MachineManager.activeMachineHasActiveNetworkConnection + property bool isCloudPrinter: Cura.MachineManager.activeMachineHasActiveCloudConnection contentPadding: UM.Theme.getSize("default_lining").width contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft