Make cache of machines a protected field

We don't want to use it outside of the mapping. This mapping should be transparent.
We are still using it from our tests though but that's fine. Tests are allowed to touch private fields.

Contributes to issue CURA-6793.
This commit is contained in:
Ghostkeeper 2019-10-16 15:04:07 +02:00
parent 5624f0a8ae
commit 8179dfc412
No known key found for this signature in database
GPG key ID: 86BEF881AE2CF276
2 changed files with 8 additions and 8 deletions

View file

@ -84,7 +84,7 @@ class ContainerTree:
# This handles the lazy loading of MachineNodes.
class MachineNodeMap:
def __init__(self):
self.machines = {}
self._machines = {}
## Returns whether a printer with a certain definition ID exists. This
# is regardless of whether or not the printer is loaded yet.
@ -99,12 +99,12 @@ class ContainerTree:
# \param definition_id The definition to look for.
# \return A machine node for that definition.
def __getitem__(self, definition_id: str) -> MachineNode:
if definition_id not in self.machines:
if definition_id not in self._machines:
start_time = time.time()
self.machines[definition_id] = MachineNode(definition_id)
self.machines[definition_id].materialsChanged.connect(ContainerTree.getInstance().materialsChanged)
self._machines[definition_id] = MachineNode(definition_id)
self._machines[definition_id].materialsChanged.connect(ContainerTree.getInstance().materialsChanged)
Logger.log("d", "Adding container tree for {definition_id} took {duration} seconds.".format(definition_id = definition_id, duration = time.time() - start_time))
return self.machines[definition_id]
return self._machines[definition_id]
## Gets a machine node for the specified definition ID, with default.
#
@ -125,7 +125,7 @@ class ContainerTree:
# \param definition_id The definition that we may have cached.
# \return ``True`` if it's cached.
def is_loaded(self, definition_id: str) -> bool:
return definition_id in self.machines
return definition_id in self._machines
## Pre-loads all currently added printers as a background task so that
# switching printers in the interface is faster.