Просмотр исходного кода

Merge remote-tracking branch 'origin/gracefully_fail_cloud_printer' into 5.0

Jelle Spijker 2 лет назад
Родитель
Сommit
334fca6691

+ 3 - 2
cura/Settings/CuraStackBuilder.py

@@ -17,7 +17,7 @@ class CuraStackBuilder:
     """Contains helper functions to create new machines."""
 
     @classmethod
-    def createMachine(cls, name: str, definition_id: str, machine_extruder_count: Optional[int] = None) -> Optional[GlobalStack]:
+    def createMachine(cls, name: str, definition_id: str, machine_extruder_count: Optional[int] = None, show_warning_message: bool = True) -> Optional[GlobalStack]:
         """Create a new instance of a machine.
 
         :param name: The name of the new machine.
@@ -34,7 +34,8 @@ class CuraStackBuilder:
 
         definitions = registry.findDefinitionContainers(id = definition_id)
         if not definitions:
-            ConfigurationErrorMessage.getInstance().addFaultyContainers(definition_id)
+            if show_warning_message:
+                ConfigurationErrorMessage.getInstance().addFaultyContainers(definition_id)
             Logger.log("w", "Definition {definition} was not found!", definition = definition_id)
             return None
 

+ 19 - 11
plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py

@@ -236,6 +236,8 @@ class CloudOutputDeviceManager:
         )
         message.show()
 
+        new_devices_added = []
+
         for idx, device in enumerate(new_devices):
             message_text = self.i18n_catalog.i18nc("info:status Filled in with printer name and printer model.", "Adding printer {name} ({model}) from your account").format(name = device.name, model = device.printerTypeName)
             message.setText(message_text)
@@ -246,21 +248,25 @@ class CloudOutputDeviceManager:
 
             # If there is no active machine, activate the first available cloud printer
             activate = not CuraApplication.getInstance().getMachineManager().activeMachine
-            self._createMachineFromDiscoveredDevice(device.getId(), activate = activate)
+
+            if self._createMachineFromDiscoveredDevice(device.getId(), activate = activate):
+                new_devices_added.append(device)
 
         message.setProgress(None)
 
         max_disp_devices = 3
-        if len(new_devices) > max_disp_devices:
-            num_hidden = len(new_devices) - max_disp_devices
+        if len(new_devices_added) > max_disp_devices:
+            num_hidden = len(new_devices_added) - max_disp_devices
             device_name_list = ["<li>{} ({})</li>".format(device.name, device.printerTypeName) for device in new_devices[0:max_disp_devices]]
             device_name_list.append("<li>" + self.i18n_catalog.i18ncp("info:{0} gets replaced by a number of printers", "... and {0} other", "... and {0} others", num_hidden) + "</li>")
             device_names = "".join(device_name_list)
         else:
-            device_names = "".join(["<li>{} ({})</li>".format(device.name, device.printerTypeName) for device in new_devices])
-
-        message_text = self.i18n_catalog.i18nc("info:status", "Printers added from Digital Factory:") + "<ul>" + device_names + "</ul>"
-        message.setText(message_text)
+            device_names = "".join(["<li>{} ({})</li>".format(device.name, device.printerTypeName) for device in new_devices_added])
+        if new_devices_added:
+            message_text = self.i18n_catalog.i18nc("info:status", "Printers added from Digital Factory:") + "<ul>" + device_names + "</ul>"
+            message.setText(message_text)
+        else:
+            message.hide()
 
     def _updateOnlinePrinters(self, printer_responses: Dict[str, CloudClusterResponse]) -> None:
         """
@@ -385,23 +391,25 @@ class CloudOutputDeviceManager:
         if device.key in output_device_manager.getOutputDeviceIds():
             output_device_manager.removeOutputDevice(device.key)
 
-    def _createMachineFromDiscoveredDevice(self, key: str, activate: bool = True) -> None:
+    def _createMachineFromDiscoveredDevice(self, key: str, activate: bool = True) -> bool:
         device = self._remote_clusters[key]
         if not device:
-            return
+            return False
 
         # Create a new machine.
         # We do not use use MachineManager.addMachine here because we need to set the cluster ID before activating it.
-        new_machine = CuraStackBuilder.createMachine(device.name, device.printerType)
+        new_machine = CuraStackBuilder.createMachine(device.name, device.printerType, show_warning_message=False)
         if not new_machine:
             Logger.log("e", "Failed creating a new machine")
-            return
+            return False
 
         self._setOutputDeviceMetadata(device, new_machine)
 
         if activate:
             CuraApplication.getInstance().getMachineManager().setActiveMachine(new_machine.getId())
 
+        return True
+
     def _connectToActiveMachine(self) -> None:
         """Callback for when the active machine was changed by the user"""