Load tree when all metadata has been loaded

This should build up the tree initially.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-06 09:16:41 +02:00
parent 2565be01f3
commit 65b1a43e88
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
2 changed files with 17 additions and 2 deletions

View file

@ -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):

View file

@ -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: