From 65b1a43e88c1d445cc7a6206f3b709b93dfa5a74 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 6 Aug 2019 09:16:41 +0200 Subject: [PATCH] Load tree when all metadata has been loaded This should build up the tree initially. Contributes to issue CURA-6600. --- cura/Machines/ContainerTree.py | 13 ++++++++++++- cura/Machines/MachineNode.py | 6 +++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/cura/Machines/ContainerTree.py b/cura/Machines/ContainerTree.py index 43ddbb4e13..adc79b1116 100644 --- a/cura/Machines/ContainerTree.py +++ b/cura/Machines/ContainerTree.py @@ -16,7 +16,18 @@ from typing import Dict class ContainerTree: def __init__(self) -> None: self.machines = {} # type: Dict[str, MachineNode] # Mapping from definition ID to machine nodes. - ContainerRegistry.getInstance().containerAdded.connect(self._machineAdded) + container_registry = ContainerRegistry.getInstance() + container_registry.allMetadataLoaded.connect(self._reloadAll) + container_registry.containerAdded.connect(self._machineAdded) + self._reloadAll() + + ## (Re)builds the initial container tree. + def _reloadAll(self): + all_stacks = ContainerRegistry.getInstance().findContainerStacks() + for stack in all_stacks: + definition_id = stack.definition.getId() + if definition_id not in self.machines: + self.machines[definition_id] = MachineNode(definition_id) ## When a printer gets added, we need to build up the tree for that container. def _machineAdded(self, definition_container: ContainerInterface): diff --git a/cura/Machines/MachineNode.py b/cura/Machines/MachineNode.py index 587960820a..a062f0eae0 100644 --- a/cura/Machines/MachineNode.py +++ b/cura/Machines/MachineNode.py @@ -19,10 +19,14 @@ class MachineNode(ContainerNode): super().__init__(container_id, None) self.variants = {} # type: Dict[str, VariantNode] # mapping variant names to their nodes. container_registry = ContainerRegistry.getInstance() + container_registry.allMetadataLoaded.connect(self._reloadAll) container_registry.containerAdded.connect(self._variantAdded) + self._reloadAll() + ## (Re)loads all variants under this printer. + def _reloadAll(self): # Find all the variants for this definition ID. - variants = container_registry.findInstanceContainersMetadata(type = "variant", definition = self.container_id, hardware_type = "nozzle") + variants = ContainerRegistry.getInstance().findInstanceContainersMetadata(type = "variant", definition = self.container_id, hardware_type = "nozzle") for variant in variants: variant_name = variant["name"] if variant_name not in self.variants: