本文整理汇总了Python中UM.Settings.ContainerStack.ContainerStack.getContainers方法的典型用法代码示例。如果您正苦于以下问题:Python ContainerStack.getContainers方法的具体用法?Python ContainerStack.getContainers怎么用?Python ContainerStack.getContainers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Settings.ContainerStack.ContainerStack
的用法示例。
在下文中一共展示了ContainerStack.getContainers方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _test_serialize_cycle
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import getContainers [as 别名]
def _test_serialize_cycle(container_stack):
name = container_stack.getName()
metadata = container_stack.getMetaData()
containers = container_stack.getContainers()
serialised = container_stack.serialize()
container_stack = ContainerStack(uuid.uuid4().int) # Completely fresh container stack.
container_stack.deserialize(serialised)
#ID and nextStack are allowed to be different.
assert name == container_stack.getName()
assert metadata == container_stack.getMetaData()
assert containers == container_stack.getContainers()
示例2: _settingIsOverwritingInheritance
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import getContainers [as 别名]
def _settingIsOverwritingInheritance(self, key: str, stack: ContainerStack = None) -> bool:
has_setting_function = False
if not stack:
stack = self._active_container_stack
if not stack: #No active container stack yet!
return False
containers = []
## Check if the setting has a user state. If not, it is never overwritten.
has_user_state = stack.getProperty(key, "state") == InstanceState.User
if not has_user_state:
return False
## If a setting is not enabled, don't label it as overwritten (It's never visible anyway).
if not stack.getProperty(key, "enabled"):
return False
## Also check if the top container is not a setting function (this happens if the inheritance is restored).
if isinstance(stack.getTop().getProperty(key, "value"), SettingFunction):
return False
## Mash all containers for all the stacks together.
while stack:
containers.extend(stack.getContainers())
stack = stack.getNextStack()
has_non_function_value = False
for container in containers:
try:
value = container.getProperty(key, "value")
except AttributeError:
continue
if value is not None:
# If a setting doesn't use any keys, it won't change it's value, so treat it as if it's a fixed value
has_setting_function = isinstance(value, SettingFunction)
if has_setting_function:
for setting_key in value.getUsedSettingKeys():
if setting_key in self._active_container_stack.getAllKeys():
break # We found an actual setting. So has_setting_function can remain true
else:
# All of the setting_keys turned out to not be setting keys at all!
# This can happen due enum keys also being marked as settings.
has_setting_function = False
if has_setting_function is False:
has_non_function_value = True
continue
if has_setting_function:
break # There is a setting function somewhere, stop looking deeper.
return has_setting_function and has_non_function_value
示例3: _test_serialize_cycle
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import getContainers [as 别名]
def _test_serialize_cycle(container_stack, ignored_metadata_keys: Optional[set] = None):
metadata = {key: value for key, value in container_stack.getMetaData().items()}
containers = container_stack.getContainers()
serialised = container_stack.serialize(ignored_metadata_keys = ignored_metadata_keys)
container_stack = ContainerStack(str(uuid.uuid4())) # Completely fresh container stack.
container_stack.deserialize(serialised)
# Remove ignored keys from metadata dict
if ignored_metadata_keys:
for key in ignored_metadata_keys:
if key in metadata:
del metadata[key]
# ID and nextStack are allowed to be different.
assert metadata.items() <= container_stack.getMetaData().items()
assert containers == container_stack.getContainers()
示例4: read
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import getContainers [as 别名]
#.........这里部分代码省略.........
stack.setName(self._container_registry.uniqueName(stack.getName()))
container_stacks_added.append(stack)
self._container_registry.addContainer(stack)
else:
Logger.log("w", "Resolve strategy of %s for machine is not supported", self._resolve_strategies["machine"])
else:
stack = ContainerStack(container_id)
# Deserialize stack by converting read data from bytes to string
stack.deserialize(archive.open(container_stack_file).read().decode("utf-8"))
container_stacks_added.append(stack)
self._container_registry.addContainer(stack)
if stack.getMetaDataEntry("type") == "extruder_train":
extruder_stacks.append(stack)
else:
global_stack = stack
except:
Logger.log("W", "We failed to serialize the stack. Trying to clean up.")
# Something went really wrong. Try to remove any data that we added.
for container in containers_to_add:
self._container_registry.getInstance().removeContainer(container.getId())
for container in container_stacks_added:
self._container_registry.getInstance().removeContainer(container.getId())
return None
if self._resolve_strategies["machine"] == "new":
# A new machine was made, but it was serialized with the wrong user container. Fix that now.
for container in user_instance_containers:
extruder_id = container.getMetaDataEntry("extruder", None)
if extruder_id:
for extruder in extruder_stacks:
if extruder.getId() == extruder_id:
extruder.replaceContainer(0, container)
continue
machine_id = container.getMetaDataEntry("machine", None)
if machine_id:
if global_stack.getId() == machine_id:
global_stack.replaceContainer(0, container)
continue
if self._resolve_strategies["quality_changes"] == "new":
# Quality changes needs to get a new ID, added to registry and to the right stacks
for container in quality_changes_instance_containers:
old_id = container.getId()
container.setName(self._container_registry.uniqueName(container.getName()))
# We're not really supposed to change the ID in normal cases, but this is an exception.
container._id = self.getNewId(container.getId())
# The container was not added yet, as it didn't have an unique ID. It does now, so add it.
self._container_registry.addContainer(container)
# Replace the quality changes container
old_container = global_stack.findContainer({"type": "quality_changes"})
if old_container.getId() == old_id:
quality_changes_index = global_stack.getContainerIndex(old_container)
global_stack.replaceContainer(quality_changes_index, container)
continue
for stack in extruder_stacks:
old_container = stack.findContainer({"type": "quality_changes"})
if old_container.getId() == old_id:
quality_changes_index = stack.getContainerIndex(old_container)
stack.replaceContainer(quality_changes_index, container)
if self._resolve_strategies["material"] == "new":
for material in material_containers:
old_material = global_stack.findContainer({"type": "material"})
if old_material.getId() in self._id_mapping:
material_index = global_stack.getContainerIndex(old_material)
global_stack.replaceContainer(material_index, material)
continue
for stack in extruder_stacks:
old_material = stack.findContainer({"type": "material"})
if old_material.getId() in self._id_mapping:
material_index = stack.getContainerIndex(old_material)
stack.replaceContainer(material_index, material)
continue
for stack in extruder_stacks:
ExtruderManager.getInstance().registerExtruder(stack, global_stack.getId())
else:
# Machine has no extruders, but it needs to be registered with the extruder manager.
ExtruderManager.getInstance().registerExtruder(None, global_stack.getId())
Logger.log("d", "Workspace loading is notifying rest of the code of changes...")
# Notify everything/one that is to notify about changes.
for container in global_stack.getContainers():
global_stack.containersChanged.emit(container)
for stack in extruder_stacks:
stack.setNextStack(global_stack)
for container in stack.getContainers():
stack.containersChanged.emit(container)
# Actually change the active machine.
Application.getInstance().setGlobalContainerStack(global_stack)
return nodes
示例5: test_deserialize_containers
# 需要导入模块: from UM.Settings.ContainerStack import ContainerStack [as 别名]
# 或者: from UM.Settings.ContainerStack.ContainerStack import getContainers [as 别名]
def test_deserialize_containers(container_stack, container_registry):
container = InstanceContainer("a")
container_registry.addContainer(container)
serialised = """
[general]
name = Test
id = testid
version = {version}
[containers]
0 = a
""".format(version = ContainerStack.Version) # Test case where there is a container.
container_stack.deserialize(serialised)
assert container_stack.getContainers() == [container]
container_stack = ContainerStack(str(uuid.uuid4()))
serialised = """
[general]
name = Test
id = testid
version = {version}
[containers]
""".format(version = ContainerStack.Version) # Test case where there is no container.
container_stack.deserialize(serialised)
assert container_stack.getContainers() == []
container_stack = ContainerStack(str(uuid.uuid4()))
serialised = """
[general]
name = Test
id = testid
version = {version}
[containers]
0 = a
1 = a
""".format(version = ContainerStack.Version) # Test case where there are two of the same containers.
container_stack.deserialize(serialised)
assert container_stack.getContainers() == [container, container]
container_stack = ContainerStack(str(uuid.uuid4()))
serialised = """
[general]
name = Test
id = testid
version = {version}
[containers]
0 = a
1 = b
""".format(version = ContainerStack.Version) # Test case where a container doesn't exist.
with pytest.raises(Exception):
container_stack.deserialize(serialised)
container_stack = ContainerStack(str(uuid.uuid4()))
container_b = InstanceContainer("b") # Add the missing container and try again.
ContainerRegistry.getInstance().addContainer(container_b)
container_stack.deserialize(serialised)
assert container_stack.getContainers() == [container, container_b]