Browse Source

Subtract online printers from list of all printers instead of searching for offline printers.

This prevents printers without "is_online" in the metadata from being left out, and is generally more defensive for uncertain states.

CURA-9514
joeydelarago 2 years ago
parent
commit
91b8c97dae
1 changed files with 11 additions and 4 deletions
  1. 11 4
      cura/Machines/Models/MachineListModel.py

+ 11 - 4
cura/Machines/Models/MachineListModel.py

@@ -59,21 +59,28 @@ class MachineListModel(ListModel):
     def _update(self) -> None:
         self.setItems([])  # Clear items
 
+        other_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type="machine")
+
         abstract_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type = "abstract_machine")
         abstract_machine_stacks.sort(key = lambda machine: machine.getName(), reverse = True)
 
         for abstract_machine in abstract_machine_stacks:
             online_machine_stacks = AbstractMachine.getMachines(abstract_machine, online_only = True)
 
-            # Create item for abstract printer
+            # Create a list item for abstract machine
             self.addItem(abstract_machine, len(online_machine_stacks))
 
-            # Create list of printers that are children of the abstract printer
+            # Create list of machines that are children of the abstract machine
             for stack in online_machine_stacks:
                 self.addItem(stack)
+                # Remove this machine from the other stack list
+                other_machine_stacks.remove(stack)
+
 
-        offline_machine_stacks = CuraContainerRegistry.getInstance().findContainerStacks(type = "machine", is_online = "False")
-        for stack in offline_machine_stacks:
+        # Filtering must be done like this because searching with findContainerStacks(is_online = "True") does not return
+        # stacks that don't have is_online in their metadata. We still want to show these printers.
+        # offline_machine_stacks = [stack for stack in offline_machine_stacks if parseBool(stack.getMetaDataEntry("is_online", False))]
+        for stack in other_machine_stacks:
             self.addItem(stack)
 
     def addItem(self, container_stack: ContainerStack, machine_count: int = 0) -> None: