Browse Source

Fixed all codestyle and nitpicks from review

ChrisTerBeke 6 years ago
parent
commit
3c10cca0de

+ 15 - 17
plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDevice.py

@@ -95,7 +95,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
         self._finished_jobs = set()  # type: Set[str]
 
         # 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]
 
     ## 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.
     def _onBackendStateChange(self, _: BackendState) -> None:
-        self._mesh = None
+        self._tool_path = None
         self._uploaded_print_job = None
 
     ## 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.
     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.setShortDescription(I18N_CATALOG.i18nc("@action:button", "Print via Cloud"))
         self.setDescription(I18N_CATALOG.i18nc("@properties:tooltip", "Print via Cloud"))
@@ -154,8 +154,8 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
             return
 
         if self._uploaded_print_job:
-            # the mesh didn't change, let's not upload it again
-            self._api.requestPrint(self.key, self._uploaded_print_job.job_id, self._onPrintRequested)
+            # The mesh didn't change, let's not upload it again
+            self._api.requestPrint(self.key, self._uploaded_print_job.job_id, self._onPrintUploadCompleted)
             return
 
         # Indicate we have started sending a job.
@@ -168,7 +168,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
 
         mesh = mesh_format.getBytes(nodes)
 
-        self._mesh = mesh
+        self._tool_path = mesh
         request = CloudPrintJobUploadRequest(
             job_name = file_name or mesh_format.file_extension,
             file_size = len(mesh),
@@ -180,7 +180,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
     def _update(self) -> None:
         super()._update()
         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)
         if self._account.isLoggedIn:
@@ -226,7 +226,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
         if self._printers and not self._active_printer:
             self.setActivePrinter(self._printers[0])
 
-        if added_printers or removed_printers or updated_printers:
+        if added_printers or removed_printers:
             self.printersChanged.emit()
 
     ## 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
         # 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()
 
     ## 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
     def _onPrintJobStateChanged(self) -> None:
         user_name = self._getUserName()
+        # TODO: confirm that notifications in Cura are still required
         for job in self._print_jobs:
             if job.state == "wait_cleanup" and job.key not in self._finished_jobs and job.owner == user_name:
                 self._finished_jobs.add(job.key)
@@ -282,9 +283,6 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
                             )),
                 ).show()
 
-        # Ensure UI gets updated
-        self.printJobsChanged.emit()
-
     ## 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)
@@ -301,18 +299,18 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
     def _onPrintJobCreated(self, job_response: CloudPrintJobResponse) -> None:
         self._progress.show()
         self._uploaded_print_job = job_response
-        mesh = cast(bytes, self._mesh)
-        self._api.uploadToolPath(job_response, mesh, self._onPrintJobUploaded, self._progress.update, self._onUploadError)
+        tool_path = cast(bytes, self._tool_path)
+        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.
     def _onPrintJobUploaded(self) -> None:
         self._progress.update(100)
         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
     #  \param message: The message to display.
-    def _onUploadError(self, message = None) -> None:
+    def _onUploadError(self, message: str = None) -> None:
         self._progress.hide()
         self._uploaded_print_job = None
         Message(
@@ -324,7 +322,7 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
 
     ## Shows a message when the upload has succeeded
     #  \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)
         self._progress.hide()
         Message(

+ 2 - 4
plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py

@@ -41,7 +41,7 @@ class CloudOutputDeviceManager:
         self._account = application.getCuraAPI().account  # type: Account
         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.setInterval(int(self.CHECK_CLUSTER_INTERVAL * 1000))
         self._update_timer.setSingleShot(False)
@@ -99,7 +99,6 @@ class CloudOutputDeviceManager:
     def _connectToActiveMachine(self) -> None:
         active_machine = CuraApplication.getInstance().getGlobalContainerStack()
         if not active_machine:
-            Logger.log("d", "no active machine")
             return
 
         # Remove all output devices that we have registered.
@@ -143,8 +142,7 @@ class CloudOutputDeviceManager:
         message = Message(
             text = text,
             title = self.I18N_CATALOG.i18nc("@info:title", "Error"),
-            lifetime = 10,
-            dismissable = True
+            lifetime = 10
         )
         message.show()
 

+ 0 - 5
plugins/UM3NetworkPrinting/src/Cloud/CloudProgressMessage.py

@@ -30,8 +30,3 @@ class CloudProgressMessage(Message):
         if not self._visible:
             super().show()
         self.setProgress(percentage)
-
-    ## Returns a boolean indicating whether the message is currently visible.
-    @property
-    def visible(self) -> bool:
-        return self._visible

+ 1 - 1
plugins/UM3NetworkPrinting/src/ClusterUM3OutputDevice.py

@@ -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")
 
-        # 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._accepts_commands = True  # type: bool

+ 4 - 4
plugins/UM3NetworkPrinting/tests/Cloud/NetworkManagerMock.py

@@ -30,7 +30,7 @@ class FakeSignal:
 #  Any requests not prepared beforehand will cause KeyErrors.
 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 = {
         "GET": QNetworkAccessManager.GetOperation,
         "POST": QNetworkAccessManager.PostOperation,
@@ -41,11 +41,11 @@ class NetworkManagerMock:
 
     ## Initializes the network manager mock.
     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.request_bodies = {}  # type: Dict[Tuple[str, str], bytes]
 
-        # signals used in the network manager.
+        # Signals used in the network manager.
         self.finished = 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.
     def __getattr__(self, method: str) -> Any:
         ## 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, *_):
             key = method.upper(), request.url().toString()
             if body:

+ 1 - 1
plugins/UM3NetworkPrinting/tests/Cloud/TestCloudApiClient.py

@@ -39,7 +39,7 @@ class TestCloudApiClient(TestCase):
         data = parseFixture("getClusters")["data"]
 
         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.network.flushReplies()

+ 16 - 6
resources/qml/PrinterSelector/MachineSelector.qml

@@ -29,11 +29,16 @@ Cura.ExpandablePopup
         text: isNetworkPrinter ? Cura.MachineManager.activeMachineNetworkGroupName : Cura.MachineManager.activeMachineName
         source:
         {
-            if (isGroup) {
+            if (isGroup)
+            {
                 return UM.Theme.getIcon("printer_group")
-            } else if (isNetworkPrinter || isCloudPrinter) {
+            }
+            else if (isNetworkPrinter || isCloudPrinter)
+            {
                 return UM.Theme.getIcon("printer_single")
-            } else {
+            }
+            else
+            {
                 return ""
             }
         }
@@ -52,11 +57,16 @@ Cura.ExpandablePopup
 
             source:
             {
-                if (isNetworkPrinter) {
+                if (isNetworkPrinter)
+                {
                     return UM.Theme.getIcon("printer_connected")
-                } else if (isCloudPrinter) {
+                }
+                else if (isCloudPrinter)
+                {
                     return UM.Theme.getIcon("printer_cloud_connected")
-                } else {
+                }
+                else
+                {
                     return ""
                 }
             }