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)
|
||||
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()
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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.
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user