mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Simplify checking if cloud or network printer, small fixes
This commit is contained in:
parent
0edeb11a78
commit
2f92f6ef50
@ -150,6 +150,11 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice):
|
|||||||
request.setHeader(QNetworkRequest.UserAgentHeader, self._user_agent)
|
request.setHeader(QNetworkRequest.UserAgentHeader, self._user_agent)
|
||||||
return request
|
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:
|
def _createFormPart(self, content_header: str, data: bytes, content_type: Optional[str] = None) -> QHttpPart:
|
||||||
part = QHttpPart()
|
part = QHttpPart()
|
||||||
|
|
||||||
|
@ -533,14 +533,14 @@ class MachineManager(QObject):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = printerConnectedStatusChanged)
|
@pyqtProperty(bool, notify = printerConnectedStatusChanged)
|
||||||
def activeMachineHasCloudConnection(self) -> bool:
|
def activeMachineHasActiveNetworkConnection(self) -> bool:
|
||||||
# A cloud connection is only available if the active output device actually is a cloud connected device.
|
# A network connection is only available if any output device is actually a network connected device.
|
||||||
# We cannot simply use the connection_type metadata entry as that's always set to 'NetworkConnection'
|
return any(d.connectionType == ConnectionType.NetworkConnection for d in self._printer_output_devices)
|
||||||
# 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]
|
@pyqtProperty(bool, notify = printerConnectedStatusChanged)
|
||||||
if not output_device:
|
def activeMachineHasActiveCloudConnection(self) -> bool:
|
||||||
return False
|
# A cloud connection is only available if any output device actually is a cloud connected device.
|
||||||
return output_device.connectionType == ConnectionType.CloudConnection
|
return any(d.connectionType == ConnectionType.CloudConnection for d in self._printer_output_devices)
|
||||||
|
|
||||||
def activeMachineNetworkKey(self) -> str:
|
def activeMachineNetworkKey(self) -> str:
|
||||||
if self._global_container_stack:
|
if self._global_container_stack:
|
||||||
|
@ -246,7 +246,8 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
if self._printers and not self._active_printer:
|
if self._printers and not self._active_printer:
|
||||||
self.setActivePrinter(self._printers[0])
|
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.
|
## Updates the local list of print jobs with the list received from the cloud.
|
||||||
# \param jobs: The print jobs 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.
|
## Updates the printer assignment for the given print job model.
|
||||||
def _updateAssignedPrinter(self, model: UM3PrintJobOutputModel, printer_uuid: str) -> None:
|
def _updateAssignedPrinter(self, model: UM3PrintJobOutputModel, printer_uuid: str) -> None:
|
||||||
printer = next((p for p in self._printers if printer_uuid == p.key), None)
|
printer = next((p for p in self._printers if printer_uuid == p.key), None)
|
||||||
|
|
||||||
if not printer:
|
if not printer:
|
||||||
return Logger.log("w", "Missing printer %s for job %s in %s", model.assignedPrinter, model.key,
|
Logger.log("w", "Missing printer %s for job %s in %s", model.assignedPrinter, model.key,
|
||||||
[p.key for p in self._printers])
|
[p.key for p in self._printers])
|
||||||
|
return
|
||||||
|
|
||||||
printer.updateActivePrintJob(model)
|
printer.updateActivePrintJob(model)
|
||||||
model.updateAssignedPrinter(printer)
|
model.updateAssignedPrinter(printer)
|
||||||
@ -329,11 +330,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
def _onUploadError(self, message = None) -> None:
|
def _onUploadError(self, message = None) -> None:
|
||||||
self._progress.hide()
|
self._progress.hide()
|
||||||
self._uploaded_print_job = None
|
self._uploaded_print_job = None
|
||||||
Message(
|
Message(text = message or T.UPLOAD_ERROR, title = T.ERROR, lifetime = 10).show()
|
||||||
text = message or T.UPLOAD_ERROR,
|
|
||||||
title = T.ERROR,
|
|
||||||
lifetime = 10
|
|
||||||
).show()
|
|
||||||
self.writeError.emit()
|
self.writeError.emit()
|
||||||
|
|
||||||
## Shows a message when the upload has succeeded
|
## Shows a message when the upload has succeeded
|
||||||
@ -341,11 +338,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
def _onPrintRequested(self, response: CloudPrintResponse) -> None:
|
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)
|
Logger.log("d", "The cluster will be printing this print job with the ID %s", response.cluster_job_id)
|
||||||
self._progress.hide()
|
self._progress.hide()
|
||||||
Message(
|
Message(text = T.UPLOAD_SUCCESS_TEXT, title = T.UPLOAD_SUCCESS_TITLE, lifetime = 5).show()
|
||||||
text = T.UPLOAD_SUCCESS_TEXT,
|
|
||||||
title = T.UPLOAD_SUCCESS_TITLE,
|
|
||||||
lifetime = 5
|
|
||||||
).show()
|
|
||||||
self.writeFinished.emit()
|
self.writeFinished.emit()
|
||||||
|
|
||||||
## Gets the remote printers.
|
## Gets the remote printers.
|
||||||
|
@ -389,10 +389,8 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
|||||||
|
|
||||||
## Called when the connection to the cluster changes.
|
## Called when the connection to the cluster changes.
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
# TODO: uncomment this once cloud implementation works for testing
|
super().connect()
|
||||||
# super().connect()
|
self.sendMaterialProfiles()
|
||||||
# self.sendMaterialProfiles()
|
|
||||||
pass
|
|
||||||
|
|
||||||
def _onGetPreviewImageFinished(self, reply: QNetworkReply) -> None:
|
def _onGetPreviewImageFinished(self, reply: QNetworkReply) -> None:
|
||||||
reply_url = reply.url().toString()
|
reply_url = reply.url().toString()
|
||||||
|
@ -12,9 +12,9 @@ Cura.ExpandablePopup
|
|||||||
id: machineSelector
|
id: machineSelector
|
||||||
|
|
||||||
property var outputDevice: Cura.MachineManager.printerOutputDevices.length >= 1 ? Cura.MachineManager.printerOutputDevices[0] : null
|
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 isPrinterConnected: Cura.MachineManager.printerConnected
|
||||||
|
property bool isNetworkPrinter: Cura.MachineManager.activeMachineHasActiveNetworkConnection
|
||||||
|
property bool isCloudPrinter: Cura.MachineManager.activeMachineHasActiveCloudConnection
|
||||||
|
|
||||||
contentPadding: UM.Theme.getSize("default_lining").width
|
contentPadding: UM.Theme.getSize("default_lining").width
|
||||||
contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
|
contentAlignment: Cura.ExpandablePopup.ContentAlignment.AlignLeft
|
||||||
|
Loading…
x
Reference in New Issue
Block a user