本文整理汇总了Python中UM.Settings.ContainerStack.ContainerStack类的典型用法代码示例。如果您正苦于以下问题:Python ContainerStack类的具体用法?Python ContainerStack怎么用?Python ContainerStack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ContainerStack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setNextStack
def setNextStack(self, stack: ContainerStack) -> None:
super().setNextStack(stack)
stack.addExtruder(self)
self.addMetaDataEntry("machine", stack.id)
# For backward compatibility: Register the extruder with the Extruder Manager
ExtruderManager.getInstance().registerExtruder(self, stack.id)
示例2: _buildExtruderMessage
def _buildExtruderMessage(self, stack: ContainerStack) -> None:
message = self._slice_message.addRepeatedMessage("extruders")
message.id = int(stack.getMetaDataEntry("position"))
if not self._all_extruders_settings:
self._cacheAllExtruderSettings()
if self._all_extruders_settings is None:
return
extruder_nr = stack.getProperty("extruder_nr", "value")
settings = self._all_extruders_settings[str(extruder_nr)].copy()
# Also send the material GUID. This is a setting in fdmprinter, but we have no interface for it.
settings["material_guid"] = stack.material.getMetaDataEntry("GUID", "")
# Replace the setting tokens in start and end g-code.
extruder_nr = stack.getProperty("extruder_nr", "value")
settings["machine_extruder_start_code"] = self._expandGcodeTokens(settings["machine_extruder_start_code"], extruder_nr)
settings["machine_extruder_end_code"] = self._expandGcodeTokens(settings["machine_extruder_end_code"], extruder_nr)
for key, value in settings.items():
# Do not send settings that are not settable_per_extruder.
if not stack.getProperty(key, "settable_per_extruder"):
continue
setting = message.getMessage("settings").addRepeatedMessage("settings")
setting.name = key
setting.value = str(value).encode("utf-8")
Job.yieldThread()
示例3: _buildGlobalInheritsStackMessage
def _buildGlobalInheritsStackMessage(self, stack: ContainerStack) -> None:
for key in stack.getAllKeys():
extruder_position = int(round(float(stack.getProperty(key, "limit_to_extruder"))))
if extruder_position >= 0: # Set to a specific extruder.
setting_extruder = self._slice_message.addRepeatedMessage("limit_to_extruder")
setting_extruder.name = key
setting_extruder.extruder = extruder_position
Job.yieldThread()
示例4: _checkStackForErrors
def _checkStackForErrors(self, stack: ContainerStack) -> bool:
if stack is None:
return False
for key in stack.getAllKeys():
validation_state = stack.getProperty(key, "validationState")
if validation_state in (ValidatorState.Exception, ValidatorState.MaximumError, ValidatorState.MinimumError, ValidatorState.Invalid):
Logger.log("w", "Setting %s is not valid, but %s. Aborting slicing.", key, validation_state)
return True
Job.yieldThread()
return False
示例5: test_findContainerStacks
def test_findContainerStacks(container_registry, data):
for container in data["containers"]: # Fill the registry with container stacks.
container = container.copy()
container_id = container["id"]
del container["id"]
container_stack = ContainerStack(container_id)
for key, value in container.items(): # Copy data into metadata.
container_stack.getMetaData()[key] = value
container_registry.addContainer(container_stack)
results = container_registry.findContainerStacks(**data["filter"]) # The actual function call we're testing.
_verifyMetaDataMatches(results, data["result"])
示例6: _settingIsOverwritingInheritance
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
示例7: test_serialize
def test_serialize(container_stack):
registry = ContainerRegistry.getInstance() # All containers need to be registered in order to be recovered again after deserialising.
# First test the empty container stack.
_test_serialize_cycle(container_stack)
# Case with one subcontainer.
container = InstanceContainer(str(uuid.uuid4()))
registry.addContainer(container)
container_stack.addContainer(container)
_test_serialize_cycle(container_stack)
# Case with two subcontainers.
container = InstanceContainer(str(uuid.uuid4()))
registry.addContainer(container)
container_stack.addContainer(container) # Already had one, if all previous assertions were correct.
_test_serialize_cycle(container_stack)
# Case with all types of subcontainers.
container = DefinitionContainer(str(uuid.uuid4()))
registry.addContainer(container)
container_stack.addContainer(container)
container = ContainerStack(str(uuid.uuid4()))
registry.addContainer(container)
container_stack.addContainer(container)
_test_serialize_cycle(container_stack)
# With some metadata.
container_stack.getMetaData()["foo"] = "bar"
_test_serialize_cycle(container_stack)
# With a changed name.
container_stack.setName("Fred")
_test_serialize_cycle(container_stack)
# A name with special characters, to test the encoding.
container_stack.setName("ルベン")
_test_serialize_cycle(container_stack)
# Just to bully the one who implements this, a name with special characters in JSON and CFG.
container_stack.setName("=,\"")
_test_serialize_cycle(container_stack)
# A container that is not in the registry.
container_stack.addContainer(DefinitionContainer(str(uuid.uuid4())))
serialised = container_stack.serialize()
container_stack = ContainerStack(str(uuid.uuid4())) # Completely fresh container stack.
with pytest.raises(Exception):
container_stack.deserialize(serialised)
示例8: __init__
def __init__(self):
super().__init__()
self._settings = None
self._stack = None
setting_data = self.getSettingData()
self._stack = ContainerStack(stack_id=id(self))
self._stack.setDirty(False) # This stack does not need to be saved.
## Check if the definition of this script already exists. If not, add it to the registry.
if "key" in setting_data:
definitions = ContainerRegistry.getInstance().findDefinitionContainers(id = setting_data["key"])
if definitions:
# Definition was found
self._definition = definitions[0]
else:
self._definition = DefinitionContainer(setting_data["key"])
self._definition.deserialize(json.dumps(setting_data))
ContainerRegistry.getInstance().addContainer(self._definition)
self._stack.addContainer(self._definition)
self._instance = InstanceContainer(container_id="ScriptInstanceContainer")
self._instance.setDefinition(self._definition)
self._stack.addContainer(self._instance)
ContainerRegistry.getInstance().addContainer(self._stack)
示例9: initialize
def initialize(self) -> None:
setting_data = self.getSettingData()
self._stack = ContainerStack(stack_id=str(id(self)))
self._stack.setDirty(False) # This stack does not need to be saved.
## Check if the definition of this script already exists. If not, add it to the registry.
if "key" in setting_data:
definitions = ContainerRegistry.getInstance().findDefinitionContainers(id=setting_data["key"])
if definitions:
# Definition was found
self._definition = definitions[0]
else:
self._definition = DefinitionContainer(setting_data["key"])
try:
self._definition.deserialize(json.dumps(setting_data))
ContainerRegistry.getInstance().addContainer(self._definition)
except ContainerFormatError:
self._definition = None
return
if self._definition is None:
return
self._stack.addContainer(self._definition)
self._instance = InstanceContainer(container_id="ScriptInstanceContainer")
self._instance.setDefinition(self._definition.getId())
self._instance.setMetaDataEntry("setting_version",
self._definition.getMetaDataEntry("setting_version", default=0))
self._stack.addContainer(self._instance)
self._stack.propertyChanged.connect(self._onPropertyChanged)
ContainerRegistry.getInstance().addContainer(self._stack)
示例10: SettingOverrideDecorator
class SettingOverrideDecorator(SceneNodeDecorator):
def __init__(self):
super().__init__()
self._stack = ContainerStack(id = "SettingOverrideStack")
self._instance = InstanceContainer(id = "SettingOverrideInstanceContainer")
self._stack.addContainer(self._instance)
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
self._onGlobalContainerStackChanged()
def _onGlobalContainerStackChanged(self):
## Ensure that the next stack is always the global stack.
self._stack.setNextStack(Application.getInstance().getGlobalContainerStack())
def getStack(self):
return self._stack
示例11: _test_serialize_cycle
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()
示例12: __init__
def __init__(self):
super().__init__()
self._stack = ContainerStack(id = "SettingOverrideStack")
self._instance = InstanceContainer(id = "SettingOverrideInstanceContainer")
self._stack.addContainer(self._instance)
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
self._onGlobalContainerStackChanged()
示例13: test_deserializeInvalidMetadata
def test_deserializeInvalidMetadata():
# No version
serialised = """
[general]
name = Test
id = testid
"""
with pytest.raises(InvalidContainerStackError):
ContainerStack.deserializeMetadata(serialised, "testid")
# No name
serialised = """
[general]
id = testid
version = {version}
""".format(version=ContainerStack.Version)
with pytest.raises(InvalidContainerStackError):
ContainerStack.deserializeMetadata(serialised, "testid")
示例14: _buildReplacementTokens
def _buildReplacementTokens(self, stack: ContainerStack) -> Dict[str, Any]:
result = {}
for key in stack.getAllKeys():
value = stack.getProperty(key, "value")
result[key] = value
Job.yieldThread()
result["print_bed_temperature"] = result["material_bed_temperature"] # Renamed settings.
result["print_temperature"] = result["material_print_temperature"]
result["travel_speed"] = result["speed_travel"]
result["time"] = time.strftime("%H:%M:%S") #Some extra settings.
result["date"] = time.strftime("%d-%m-%Y")
result["day"] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"][int(time.strftime("%w"))]
initial_extruder_stack = CuraApplication.getInstance().getExtruderManager().getUsedExtruderStacks()[0]
initial_extruder_nr = initial_extruder_stack.getProperty("extruder_nr", "value")
result["initial_extruder_nr"] = initial_extruder_nr
return result
示例15: __init__
def __init__(self):
super().__init__()
self._stack = ContainerStack(stack_id = id(self))
self._instance = InstanceContainer(container_id = "SettingOverrideInstanceContainer")
self._stack.addContainer(self._instance)
ContainerRegistry.getInstance().addContainer(self._stack)
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerStackChanged)
self._onGlobalContainerStackChanged()