mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Fixed all codestyle and nitpicks from review
This commit is contained in:
parent
e465bd771a
commit
3c10cca0de
7 changed files with 39 additions and 38 deletions
|
@ -95,7 +95,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
self._finished_jobs = set() # type: Set[str]
|
self._finished_jobs = set() # type: Set[str]
|
||||||
|
|
||||||
# Reference to the uploaded print job / mesh
|
# Reference to the uploaded print job / mesh
|
||||||
self._mesh = None # type: Optional[bytes]
|
self._tool_path = None # type: Optional[bytes]
|
||||||
self._uploaded_print_job = None # type: Optional[CloudPrintJobResponse]
|
self._uploaded_print_job = None # type: Optional[CloudPrintJobResponse]
|
||||||
|
|
||||||
## Connects this device.
|
## Connects this device.
|
||||||
|
@ -112,7 +112,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
|
|
||||||
## Resets the print job that was uploaded to force a new upload, runs whenever the user re-slices.
|
## Resets the print job that was uploaded to force a new upload, runs whenever the user re-slices.
|
||||||
def _onBackendStateChange(self, _: BackendState) -> None:
|
def _onBackendStateChange(self, _: BackendState) -> None:
|
||||||
self._mesh = None
|
self._tool_path = None
|
||||||
self._uploaded_print_job = None
|
self._uploaded_print_job = None
|
||||||
|
|
||||||
## Gets the cluster response from which this device was created.
|
## Gets the cluster response from which this device was created.
|
||||||
|
@ -133,7 +133,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
|
|
||||||
## Set all the interface elements and texts for this output device.
|
## Set all the interface elements and texts for this output device.
|
||||||
def _setInterfaceElements(self) -> None:
|
def _setInterfaceElements(self) -> None:
|
||||||
self.setPriority(2) # make sure we end up below the local networking and above 'save to file'
|
self.setPriority(2) # Make sure we end up below the local networking and above 'save to file'
|
||||||
self.setName(self._id)
|
self.setName(self._id)
|
||||||
self.setShortDescription(I18N_CATALOG.i18nc("@action:button", "Print via Cloud"))
|
self.setShortDescription(I18N_CATALOG.i18nc("@action:button", "Print via Cloud"))
|
||||||
self.setDescription(I18N_CATALOG.i18nc("@properties:tooltip", "Print via Cloud"))
|
self.setDescription(I18N_CATALOG.i18nc("@properties:tooltip", "Print via Cloud"))
|
||||||
|
@ -154,8 +154,8 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
return
|
return
|
||||||
|
|
||||||
if self._uploaded_print_job:
|
if self._uploaded_print_job:
|
||||||
# the mesh didn't change, let's not upload it again
|
# The mesh didn't change, let's not upload it again
|
||||||
self._api.requestPrint(self.key, self._uploaded_print_job.job_id, self._onPrintRequested)
|
self._api.requestPrint(self.key, self._uploaded_print_job.job_id, self._onPrintUploadCompleted)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Indicate we have started sending a job.
|
# Indicate we have started sending a job.
|
||||||
|
@ -168,7 +168,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
|
|
||||||
mesh = mesh_format.getBytes(nodes)
|
mesh = mesh_format.getBytes(nodes)
|
||||||
|
|
||||||
self._mesh = mesh
|
self._tool_path = mesh
|
||||||
request = CloudPrintJobUploadRequest(
|
request = CloudPrintJobUploadRequest(
|
||||||
job_name = file_name or mesh_format.file_extension,
|
job_name = file_name or mesh_format.file_extension,
|
||||||
file_size = len(mesh),
|
file_size = len(mesh),
|
||||||
|
@ -180,7 +180,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
super()._update()
|
super()._update()
|
||||||
if self._last_request_time and time() - self._last_request_time < self.CHECK_CLUSTER_INTERVAL:
|
if self._last_request_time and time() - self._last_request_time < self.CHECK_CLUSTER_INTERVAL:
|
||||||
return # avoid calling the cloud too often
|
return # Avoid calling the cloud too often
|
||||||
|
|
||||||
Logger.log("d", "Updating: %s - %s >= %s", time(), self._last_request_time, self.CHECK_CLUSTER_INTERVAL)
|
Logger.log("d", "Updating: %s - %s >= %s", time(), self._last_request_time, self.CHECK_CLUSTER_INTERVAL)
|
||||||
if self._account.isLoggedIn:
|
if self._account.isLoggedIn:
|
||||||
|
@ -226,7 +226,7 @@ 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])
|
||||||
|
|
||||||
if added_printers or removed_printers or updated_printers:
|
if added_printers or removed_printers:
|
||||||
self.printersChanged.emit()
|
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.
|
||||||
|
@ -253,7 +253,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
|
|
||||||
# We only have to update when jobs are added or removed
|
# We only have to update when jobs are added or removed
|
||||||
# updated jobs push their changes via their output model
|
# updated jobs push their changes via their output model
|
||||||
if added_jobs or removed_jobs or updated_jobs:
|
if added_jobs or removed_jobs:
|
||||||
self.printJobsChanged.emit()
|
self.printJobsChanged.emit()
|
||||||
|
|
||||||
## Registers a new print job received via the cloud API.
|
## Registers a new print job received via the cloud API.
|
||||||
|
@ -268,6 +268,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
## Handles the event of a change in a print job state
|
## Handles the event of a change in a print job state
|
||||||
def _onPrintJobStateChanged(self) -> None:
|
def _onPrintJobStateChanged(self) -> None:
|
||||||
user_name = self._getUserName()
|
user_name = self._getUserName()
|
||||||
|
# TODO: confirm that notifications in Cura are still required
|
||||||
for job in self._print_jobs:
|
for job in self._print_jobs:
|
||||||
if job.state == "wait_cleanup" and job.key not in self._finished_jobs and job.owner == user_name:
|
if job.state == "wait_cleanup" and job.key not in self._finished_jobs and job.owner == user_name:
|
||||||
self._finished_jobs.add(job.key)
|
self._finished_jobs.add(job.key)
|
||||||
|
@ -282,9 +283,6 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
)),
|
)),
|
||||||
).show()
|
).show()
|
||||||
|
|
||||||
# Ensure UI gets updated
|
|
||||||
self.printJobsChanged.emit()
|
|
||||||
|
|
||||||
## 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)
|
||||||
|
@ -301,18 +299,18 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
def _onPrintJobCreated(self, job_response: CloudPrintJobResponse) -> None:
|
def _onPrintJobCreated(self, job_response: CloudPrintJobResponse) -> None:
|
||||||
self._progress.show()
|
self._progress.show()
|
||||||
self._uploaded_print_job = job_response
|
self._uploaded_print_job = job_response
|
||||||
mesh = cast(bytes, self._mesh)
|
tool_path = cast(bytes, self._tool_path)
|
||||||
self._api.uploadToolPath(job_response, mesh, self._onPrintJobUploaded, self._progress.update, self._onUploadError)
|
self._api.uploadToolPath(job_response, tool_path, self._onPrintJobUploaded, self._progress.update, self._onUploadError)
|
||||||
|
|
||||||
## Requests the print to be sent to the printer when we finished uploading the mesh.
|
## Requests the print to be sent to the printer when we finished uploading the mesh.
|
||||||
def _onPrintJobUploaded(self) -> None:
|
def _onPrintJobUploaded(self) -> None:
|
||||||
self._progress.update(100)
|
self._progress.update(100)
|
||||||
print_job = cast(CloudPrintJobResponse, self._uploaded_print_job)
|
print_job = cast(CloudPrintJobResponse, self._uploaded_print_job)
|
||||||
self._api.requestPrint(self.key, print_job.job_id, self._onPrintRequested)
|
self._api.requestPrint(self.key, print_job.job_id, self._onPrintUploadCompleted)
|
||||||
|
|
||||||
## Displays the given message if uploading the mesh has failed
|
## Displays the given message if uploading the mesh has failed
|
||||||
# \param message: The message to display.
|
# \param message: The message to display.
|
||||||
def _onUploadError(self, message = None) -> None:
|
def _onUploadError(self, message: str = None) -> None:
|
||||||
self._progress.hide()
|
self._progress.hide()
|
||||||
self._uploaded_print_job = None
|
self._uploaded_print_job = None
|
||||||
Message(
|
Message(
|
||||||
|
@ -324,7 +322,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
|
||||||
|
|
||||||
## Shows a message when the upload has succeeded
|
## Shows a message when the upload has succeeded
|
||||||
# \param response: The response from the cloud API.
|
# \param response: The response from the cloud API.
|
||||||
def _onPrintRequested(self, response: CloudPrintResponse) -> None:
|
def _onPrintUploadCompleted(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(
|
||||||
|
|
|
@ -41,7 +41,7 @@ class CloudOutputDeviceManager:
|
||||||
self._account = application.getCuraAPI().account # type: Account
|
self._account = application.getCuraAPI().account # type: Account
|
||||||
self._api = CloudApiClient(self._account, self._onApiError)
|
self._api = CloudApiClient(self._account, self._onApiError)
|
||||||
|
|
||||||
# create a timer to update the remote cluster list
|
# Create a timer to update the remote cluster list
|
||||||
self._update_timer = QTimer(application)
|
self._update_timer = QTimer(application)
|
||||||
self._update_timer.setInterval(int(self.CHECK_CLUSTER_INTERVAL * 1000))
|
self._update_timer.setInterval(int(self.CHECK_CLUSTER_INTERVAL * 1000))
|
||||||
self._update_timer.setSingleShot(False)
|
self._update_timer.setSingleShot(False)
|
||||||
|
@ -99,7 +99,6 @@ class CloudOutputDeviceManager:
|
||||||
def _connectToActiveMachine(self) -> None:
|
def _connectToActiveMachine(self) -> None:
|
||||||
active_machine = CuraApplication.getInstance().getGlobalContainerStack()
|
active_machine = CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
if not active_machine:
|
if not active_machine:
|
||||||
Logger.log("d", "no active machine")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
# Remove all output devices that we have registered.
|
# Remove all output devices that we have registered.
|
||||||
|
@ -143,8 +142,7 @@ class CloudOutputDeviceManager:
|
||||||
message = Message(
|
message = Message(
|
||||||
text = text,
|
text = text,
|
||||||
title = self.I18N_CATALOG.i18nc("@info:title", "Error"),
|
title = self.I18N_CATALOG.i18nc("@info:title", "Error"),
|
||||||
lifetime = 10,
|
lifetime = 10
|
||||||
dismissable = True
|
|
||||||
)
|
)
|
||||||
message.show()
|
message.show()
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,3 @@ class CloudProgressMessage(Message):
|
||||||
if not self._visible:
|
if not self._visible:
|
||||||
super().show()
|
super().show()
|
||||||
self.setProgress(percentage)
|
self.setProgress(percentage)
|
||||||
|
|
||||||
## Returns a boolean indicating whether the message is currently visible.
|
|
||||||
@property
|
|
||||||
def visible(self) -> bool:
|
|
||||||
return self._visible
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
|
||||||
|
|
||||||
self._monitor_view_qml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../resources/qml/MonitorStage.qml")
|
self._monitor_view_qml_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../resources/qml/MonitorStage.qml")
|
||||||
|
|
||||||
# trigger the printersChanged signal when the private signal is triggered
|
# Trigger the printersChanged signal when the private signal is triggered
|
||||||
self.printersChanged.connect(self._clusterPrintersChanged)
|
self.printersChanged.connect(self._clusterPrintersChanged)
|
||||||
|
|
||||||
self._accepts_commands = True # type: bool
|
self._accepts_commands = True # type: bool
|
||||||
|
|
|
@ -30,7 +30,7 @@ class FakeSignal:
|
||||||
# Any requests not prepared beforehand will cause KeyErrors.
|
# Any requests not prepared beforehand will cause KeyErrors.
|
||||||
class NetworkManagerMock:
|
class NetworkManagerMock:
|
||||||
|
|
||||||
# an enumeration of the supported operations and their code for the network access manager.
|
# An enumeration of the supported operations and their code for the network access manager.
|
||||||
_OPERATIONS = {
|
_OPERATIONS = {
|
||||||
"GET": QNetworkAccessManager.GetOperation,
|
"GET": QNetworkAccessManager.GetOperation,
|
||||||
"POST": QNetworkAccessManager.PostOperation,
|
"POST": QNetworkAccessManager.PostOperation,
|
||||||
|
@ -41,11 +41,11 @@ class NetworkManagerMock:
|
||||||
|
|
||||||
## Initializes the network manager mock.
|
## Initializes the network manager mock.
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
# a dict with the prepared replies, using the format {(http_method, url): reply}
|
# A dict with the prepared replies, using the format {(http_method, url): reply}
|
||||||
self.replies = {} # type: Dict[Tuple[str, str], MagicMock]
|
self.replies = {} # type: Dict[Tuple[str, str], MagicMock]
|
||||||
self.request_bodies = {} # type: Dict[Tuple[str, str], bytes]
|
self.request_bodies = {} # type: Dict[Tuple[str, str], bytes]
|
||||||
|
|
||||||
# signals used in the network manager.
|
# Signals used in the network manager.
|
||||||
self.finished = Signal()
|
self.finished = Signal()
|
||||||
self.authenticationRequired = Signal()
|
self.authenticationRequired = Signal()
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ class NetworkManagerMock:
|
||||||
# \return The mocked function, if the method name is known. Defaults to the standard getattr function.
|
# \return The mocked function, if the method name is known. Defaults to the standard getattr function.
|
||||||
def __getattr__(self, method: str) -> Any:
|
def __getattr__(self, method: str) -> Any:
|
||||||
## This mock implementation will simply return the reply from the prepared ones.
|
## This mock implementation will simply return the reply from the prepared ones.
|
||||||
# it raises a KeyError if requests are done without being prepared.
|
# it raises a KeyError if requests are done without being prepared.
|
||||||
def doRequest(request: QNetworkRequest, body: Optional[bytes] = None, *_):
|
def doRequest(request: QNetworkRequest, body: Optional[bytes] = None, *_):
|
||||||
key = method.upper(), request.url().toString()
|
key = method.upper(), request.url().toString()
|
||||||
if body:
|
if body:
|
||||||
|
|
|
@ -39,7 +39,7 @@ class TestCloudApiClient(TestCase):
|
||||||
data = parseFixture("getClusters")["data"]
|
data = parseFixture("getClusters")["data"]
|
||||||
|
|
||||||
self.network.prepareReply("GET", CuraCloudAPIRoot + "/connect/v1/clusters", 200, response)
|
self.network.prepareReply("GET", CuraCloudAPIRoot + "/connect/v1/clusters", 200, response)
|
||||||
# the callback is a function that adds the result of the call to getClusters to the result list
|
# The callback is a function that adds the result of the call to getClusters to the result list
|
||||||
self.api.getClusters(lambda clusters: result.extend(clusters))
|
self.api.getClusters(lambda clusters: result.extend(clusters))
|
||||||
|
|
||||||
self.network.flushReplies()
|
self.network.flushReplies()
|
||||||
|
|
|
@ -29,11 +29,16 @@ Cura.ExpandablePopup
|
||||||
text: isNetworkPrinter ? Cura.MachineManager.activeMachineNetworkGroupName : Cura.MachineManager.activeMachineName
|
text: isNetworkPrinter ? Cura.MachineManager.activeMachineNetworkGroupName : Cura.MachineManager.activeMachineName
|
||||||
source:
|
source:
|
||||||
{
|
{
|
||||||
if (isGroup) {
|
if (isGroup)
|
||||||
|
{
|
||||||
return UM.Theme.getIcon("printer_group")
|
return UM.Theme.getIcon("printer_group")
|
||||||
} else if (isNetworkPrinter || isCloudPrinter) {
|
}
|
||||||
|
else if (isNetworkPrinter || isCloudPrinter)
|
||||||
|
{
|
||||||
return UM.Theme.getIcon("printer_single")
|
return UM.Theme.getIcon("printer_single")
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,11 +57,16 @@ Cura.ExpandablePopup
|
||||||
|
|
||||||
source:
|
source:
|
||||||
{
|
{
|
||||||
if (isNetworkPrinter) {
|
if (isNetworkPrinter)
|
||||||
|
{
|
||||||
return UM.Theme.getIcon("printer_connected")
|
return UM.Theme.getIcon("printer_connected")
|
||||||
} else if (isCloudPrinter) {
|
}
|
||||||
|
else if (isCloudPrinter)
|
||||||
|
{
|
||||||
return UM.Theme.getIcon("printer_cloud_connected")
|
return UM.Theme.getIcon("printer_cloud_connected")
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue