本文整理汇总了Python中UM.Settings.InstanceContainer.InstanceContainer._id方法的典型用法代码示例。如果您正苦于以下问题:Python InstanceContainer._id方法的具体用法?Python InstanceContainer._id怎么用?Python InstanceContainer._id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UM.Settings.InstanceContainer.InstanceContainer
的用法示例。
在下文中一共展示了InstanceContainer._id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convertUserContainerToQuality
# 需要导入模块: from UM.Settings.InstanceContainer import InstanceContainer [as 别名]
# 或者: from UM.Settings.InstanceContainer.InstanceContainer import _id [as 别名]
def convertUserContainerToQuality(self):
if not self._global_container_stack:
return
new_quality_container = InstanceContainer("")
name = self._createUniqueName("quality", "", self.activeQualityName, catalog.i18nc("@label", "Custom profile"))
user_settings = self._global_container_stack.getTop()
## Copy all values
new_quality_container.deserialize(user_settings.serialize())
## If the currently active machine does not have quality profiles of its own,
# make the new quality profile available for all machines that don't have
# unique quality profiles (including the current machine)
if not self.filterQualityByMachine:
new_quality_container.setDefinition(UM.Settings.ContainerRegistry.getInstance().findDefinitionContainers(id = "fdmprinter")[0])
## Change type / id / name
new_quality_container.setMetaDataEntry("type", "quality")
new_quality_container.setMetaDataEntry("read_only", False)
new_quality_container.setName(name)
new_quality_container._id = name
UM.Settings.ContainerRegistry.getInstance().addContainer(new_quality_container)
self.clearUserSettings() # As all users settings are now transfered to the new quality profile, remove them.
self.setActiveQuality(name)
return name
示例2: renameQualityContainer
# 需要导入模块: from UM.Settings.InstanceContainer import InstanceContainer [as 别名]
# 或者: from UM.Settings.InstanceContainer.InstanceContainer import _id [as 别名]
def renameQualityContainer(self, container_id, new_name):
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id, type = "quality")
if containers:
new_name = self._createUniqueName("quality", containers[0].getName(), new_name,
catalog.i18nc("@label", "Custom profile"))
if containers[0].getName() == new_name:
# Nothing to do.
return
# As we also want the id of the container to be changed (so that profile name is the name of the file
# on disk. We need to create a new instance and remove it (so the old file of the container is removed)
# If we don't do that, we might get duplicates & other weird issues.
new_container = InstanceContainer("")
new_container.deserialize(containers[0].serialize())
# Actually set the name
new_container.setName(new_name)
new_container._id = new_name # Todo: Fix proper id change function for this.
# Add the "new" container.
UM.Settings.ContainerRegistry.getInstance().addContainer(new_container)
# Ensure that the renamed profile is saved -before- we remove the old profile.
Application.getInstance().saveSettings()
# Actually set & remove new / old quality.
self.setActiveQuality(new_name)
self.removeQualityContainer(containers[0].getId())
示例3: _configureProfile
# 需要导入模块: from UM.Settings.InstanceContainer import InstanceContainer [as 别名]
# 或者: from UM.Settings.InstanceContainer.InstanceContainer import _id [as 别名]
def _configureProfile(self, profile: InstanceContainer, id_seed: str, new_name: str) -> Optional[str]:
profile.setDirty(True) # Ensure the profiles are correctly saved
new_id = self.createUniqueName("quality_changes", "", id_seed, catalog.i18nc("@label", "Custom profile"))
profile._id = new_id
profile.setName(new_name)
if "type" in profile.getMetaData():
profile.setMetaDataEntry("type", "quality_changes")
else:
profile.addMetaDataEntry("type", "quality_changes")
quality_type = profile.getMetaDataEntry("quality_type")
if not quality_type:
return catalog.i18nc("@info:status", "Profile is missing a quality type.")
quality_type_criteria = {"quality_type": quality_type}
if self._machineHasOwnQualities():
profile.setDefinition(self._activeQualityDefinition().getId())
if self._machineHasOwnMaterials():
active_material_id = self._activeMaterialId()
if active_material_id and active_material_id != "empty": # only update if there is an active material
profile.addMetaDataEntry("material", active_material_id)
quality_type_criteria["material"] = active_material_id
quality_type_criteria["definition"] = profile.getDefinition().getId()
else:
profile.setDefinition(fdmprinter)
quality_type_criteria["definition"] = "fdmprinter"
machine_definition = Application.getInstance().getGlobalContainerStack().getBottom()
del quality_type_criteria["definition"]
# materials = None
if "material" in quality_type_criteria:
# materials = ContainerRegistry.getInstance().findInstanceContainers(id = quality_type_criteria["material"])
del quality_type_criteria["material"]
# Do not filter quality containers here with materials because we are trying to import a profile, so it should
# NOT be restricted by the active materials on the current machine.
materials = None
# Check to make sure the imported profile actually makes sense in context of the current configuration.
# This prevents issues where importing a "draft" profile for a machine without "draft" qualities would report as
# successfully imported but then fail to show up.
from cura.QualityManager import QualityManager
qualities = QualityManager.getInstance()._getFilteredContainersForStack(machine_definition, materials, **quality_type_criteria)
if not qualities:
return catalog.i18nc("@info:status", "Could not find a quality type {0} for the current configuration.", quality_type)
ContainerRegistry.getInstance().addContainer(profile)
return None
示例4: duplicateContainer
# 需要导入模块: from UM.Settings.InstanceContainer import InstanceContainer [as 别名]
# 或者: from UM.Settings.InstanceContainer.InstanceContainer import _id [as 别名]
def duplicateContainer(self, container_id):
if not self._active_container_stack:
return ""
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
if containers:
new_name = self._createUniqueName("quality", "", containers[0].getName(), catalog.i18nc("@label", "Custom profile"))
new_container = InstanceContainer("")
## Copy all values
new_container.deserialize(containers[0].serialize())
new_container.setReadOnly(False)
new_container.setName(new_name)
new_container._id = new_name
UM.Settings.ContainerRegistry.getInstance().addContainer(new_container)
return new_name
return ""
示例5: read
# 需要导入模块: from UM.Settings.InstanceContainer import InstanceContainer [as 别名]
# 或者: from UM.Settings.InstanceContainer.InstanceContainer import _id [as 别名]
def read(self, file_name):
if file_name.split(".")[-1] != "gcode":
return None
prefix = ";SETTING_" + str(GCodeProfileReader.version) + " "
prefix_length = len(prefix)
# Loading all settings from the file.
# They are all at the end, but Python has no reverse seek any more since Python3.
# TODO: Consider moving settings to the start?
serialized = "" # Will be filled with the serialized profile.
try:
with open(file_name) as f:
for line in f:
if line.startswith(prefix):
# Remove the prefix and the newline from the line and add it to the rest.
serialized += line[prefix_length : -1]
except IOError as e:
Logger.log("e", "Unable to open file %s for reading: %s", file_name, str(e))
return None
# Un-escape the serialized profile.
pattern = re.compile("|".join(GCodeProfileReader.escape_characters.keys()))
# Perform the replacement with a regular expression.
serialized = pattern.sub(lambda m: GCodeProfileReader.escape_characters[re.escape(m.group(0))], serialized)
Logger.log("i", "Serialized the following from %s: %s" %(file_name, repr(serialized)))
# Create an empty profile - the id will be changed later
profile = InstanceContainer("")
profile.addMetaDataEntry("type", "quality")
try:
profile.deserialize(serialized)
except Exception as e: # Not a valid g-code file.
Logger.log("e", "Unable to serialise the profile: %s", str(e))
return None
#Creating a unique name using the filename of the GCode
new_name = catalog.i18nc("@label", "Custom profile (%s)") %(os.path.splitext(os.path.basename(file_name))[0])
profile.setName(new_name)
profile._id = new_name
return profile
示例6: _configureProfile
# 需要导入模块: from UM.Settings.InstanceContainer import InstanceContainer [as 别名]
# 或者: from UM.Settings.InstanceContainer.InstanceContainer import _id [as 别名]
def _configureProfile(self, profile: InstanceContainer, id_seed: str, new_name: str) -> Optional[str]:
profile.setReadOnly(False)
profile.setDirty(True) # Ensure the profiles are correctly saved
new_id = self.createUniqueName("quality_changes", "", id_seed, catalog.i18nc("@label", "Custom profile"))
profile._id = new_id
profile.setName(new_name)
if "type" in profile.getMetaData():
profile.setMetaDataEntry("type", "quality_changes")
else:
profile.addMetaDataEntry("type", "quality_changes")
quality_type = profile.getMetaDataEntry("quality_type")
if not quality_type:
return catalog.i18nc("@info:status", "Profile is missing a quality type.")
quality_type_criteria = {"quality_type": quality_type}
if self._machineHasOwnQualities():
profile.setDefinition(self._activeQualityDefinition())
if self._machineHasOwnMaterials():
active_material_id = self._activeMaterialId()
if active_material_id: # only update if there is an active material
profile.addMetaDataEntry("material", active_material_id)
quality_type_criteria["material"] = active_material_id
quality_type_criteria["definition"] = profile.getDefinition().getId()
else:
profile.setDefinition(ContainerRegistry.getInstance().findDefinitionContainers(id="fdmprinter")[0])
quality_type_criteria["definition"] = "fdmprinter"
# Check to make sure the imported profile actually makes sense in context of the current configuration.
# This prevents issues where importing a "draft" profile for a machine without "draft" qualities would report as
# successfully imported but then fail to show up.
qualities = self.findInstanceContainers(**quality_type_criteria)
if not qualities:
return catalog.i18nc("@info:status", "Could not find a quality type {0} for the current configuration.", quality_type)
ContainerRegistry.getInstance().addContainer(profile)
return None
示例7: read
# 需要导入模块: from UM.Settings.InstanceContainer import InstanceContainer [as 别名]
# 或者: from UM.Settings.InstanceContainer.InstanceContainer import _id [as 别名]
def read(self, file_name):
# Load all the nodes / meshdata of the workspace
nodes = self._3mf_mesh_reader.read(file_name)
if nodes is None:
nodes = []
archive = zipfile.ZipFile(file_name, "r")
cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
# Create a shadow copy of the preferences (we don't want all of the preferences, but we do want to re-use its
# parsing code.
temp_preferences = Preferences()
temp_preferences.readFromFile(io.TextIOWrapper(archive.open("Cura/preferences.cfg"))) # We need to wrap it, else the archive parser breaks.
# Copy a number of settings from the temp preferences to the global
global_preferences = Preferences.getInstance()
global_preferences.setValue("general/visible_settings", temp_preferences.getValue("general/visible_settings"))
global_preferences.setValue("cura/categories_expanded", temp_preferences.getValue("cura/categories_expanded"))
Application.getInstance().expandedCategoriesChanged.emit() # Notify the GUI of the change
self._id_mapping = {}
# We don't add containers right away, but wait right until right before the stack serialization.
# We do this so that if something goes wrong, it's easier to clean up.
containers_to_add = []
# TODO: For the moment we use pretty naive existence checking. If the ID is the same, we assume in quite a few
# TODO: cases that the container loaded is the same (most notable in materials & definitions).
# TODO: It might be possible that we need to add smarter checking in the future.
Logger.log("d", "Workspace loading is checking definitions...")
# Get all the definition files & check if they exist. If not, add them.
definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
for definition_container_file in definition_container_files:
container_id = self._stripFileToId(definition_container_file)
definitions = self._container_registry.findDefinitionContainers(id=container_id)
if not definitions:
definition_container = DefinitionContainer(container_id)
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
self._container_registry.addContainer(definition_container)
Logger.log("d", "Workspace loading is checking materials...")
material_containers = []
# Get all the material files and check if they exist. If not, add them.
xml_material_profile = self._getXmlProfileClass()
if self._material_container_suffix is None:
self._material_container_suffix = ContainerRegistry.getMimeTypeForContainer(xml_material_profile).suffixes[0]
if xml_material_profile:
material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
for material_container_file in material_container_files:
container_id = self._stripFileToId(material_container_file)
materials = self._container_registry.findInstanceContainers(id=container_id)
if not materials:
material_container = xml_material_profile(container_id)
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
containers_to_add.append(material_container)
else:
if not materials[0].isReadOnly(): # Only create new materials if they are not read only.
if self._resolve_strategies["material"] == "override":
materials[0].deserialize(archive.open(material_container_file).read().decode("utf-8"))
elif self._resolve_strategies["material"] == "new":
# Note that we *must* deserialize it with a new ID, as multiple containers will be
# auto created & added.
material_container = xml_material_profile(self.getNewId(container_id))
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
containers_to_add.append(material_container)
material_containers.append(material_container)
Logger.log("d", "Workspace loading is checking instance containers...")
# Get quality_changes and user profiles saved in the workspace
instance_container_files = [name for name in cura_file_names if name.endswith(self._instance_container_suffix)]
user_instance_containers = []
quality_changes_instance_containers = []
for instance_container_file in instance_container_files:
container_id = self._stripFileToId(instance_container_file)
instance_container = InstanceContainer(container_id)
# Deserialize InstanceContainer by converting read data from bytes to string
instance_container.deserialize(archive.open(instance_container_file).read().decode("utf-8"))
container_type = instance_container.getMetaDataEntry("type")
if container_type == "user":
# Check if quality changes already exists.
user_containers = self._container_registry.findInstanceContainers(id=container_id)
if not user_containers:
containers_to_add.append(instance_container)
else:
if self._resolve_strategies["machine"] == "override":
user_containers[0].deserialize(archive.open(instance_container_file).read().decode("utf-8"))
elif self._resolve_strategies["machine"] == "new":
# The machine is going to get a spiffy new name, so ensure that the id's of user settings match.
extruder_id = instance_container.getMetaDataEntry("extruder", None)
if extruder_id:
new_id = self.getNewId(extruder_id) + "_current_settings"
instance_container._id = new_id
instance_container.setName(new_id)
instance_container.setMetaDataEntry("extruder", self.getNewId(extruder_id))
containers_to_add.append(instance_container)
machine_id = instance_container.getMetaDataEntry("machine", None)
if machine_id:
#.........这里部分代码省略.........
示例8: read
# 需要导入模块: from UM.Settings.InstanceContainer import InstanceContainer [as 别名]
# 或者: from UM.Settings.InstanceContainer.InstanceContainer import _id [as 别名]
def read(self, file_name):
archive = zipfile.ZipFile(file_name, "r")
cura_file_names = [name for name in archive.namelist() if name.startswith("Cura/")]
# Create a shadow copy of the preferences (we don't want all of the preferences, but we do want to re-use its
# parsing code.
temp_preferences = Preferences()
temp_preferences.readFromFile(io.TextIOWrapper(archive.open("Cura/preferences.cfg"))) # We need to wrap it, else the archive parser breaks.
# Copy a number of settings from the temp preferences to the global
global_preferences = Preferences.getInstance()
visible_settings = temp_preferences.getValue("general/visible_settings")
if visible_settings is None:
Logger.log("w", "Workspace did not contain visible settings. Leaving visibility unchanged")
else:
global_preferences.setValue("general/visible_settings", visible_settings)
categories_expanded = temp_preferences.getValue("cura/categories_expanded")
if categories_expanded is None:
Logger.log("w", "Workspace did not contain expanded categories. Leaving them unchanged")
else:
global_preferences.setValue("cura/categories_expanded", categories_expanded)
Application.getInstance().expandedCategoriesChanged.emit() # Notify the GUI of the change
self._id_mapping = {}
# We don't add containers right away, but wait right until right before the stack serialization.
# We do this so that if something goes wrong, it's easier to clean up.
containers_to_add = []
global_stack_file, extruder_stack_files = self._determineGlobalAndExtruderStackFiles(file_name, cura_file_names)
global_stack = None
extruder_stacks = []
extruder_stacks_added = []
container_stacks_added = []
containers_added = []
global_stack_id_original = self._stripFileToId(global_stack_file)
global_stack_id_new = global_stack_id_original
global_stack_need_rename = False
extruder_stack_id_map = {} # new and old ExtruderStack IDs map
if self._resolve_strategies["machine"] == "new":
# We need a new id if the id already exists
if self._container_registry.findContainerStacks(id = global_stack_id_original):
global_stack_id_new = self.getNewId(global_stack_id_original)
global_stack_need_rename = True
for each_extruder_stack_file in extruder_stack_files:
old_container_id = self._stripFileToId(each_extruder_stack_file)
new_container_id = old_container_id
if self._container_registry.findContainerStacks(id = old_container_id):
# get a new name for this extruder
new_container_id = self.getNewId(old_container_id)
extruder_stack_id_map[old_container_id] = new_container_id
# TODO: For the moment we use pretty naive existence checking. If the ID is the same, we assume in quite a few
# TODO: cases that the container loaded is the same (most notable in materials & definitions).
# TODO: It might be possible that we need to add smarter checking in the future.
Logger.log("d", "Workspace loading is checking definitions...")
# Get all the definition files & check if they exist. If not, add them.
definition_container_files = [name for name in cura_file_names if name.endswith(self._definition_container_suffix)]
for definition_container_file in definition_container_files:
container_id = self._stripFileToId(definition_container_file)
definitions = self._container_registry.findDefinitionContainers(id = container_id)
if not definitions:
definition_container = DefinitionContainer(container_id)
definition_container.deserialize(archive.open(definition_container_file).read().decode("utf-8"))
self._container_registry.addContainer(definition_container)
Job.yieldThread()
Logger.log("d", "Workspace loading is checking materials...")
material_containers = []
# Get all the material files and check if they exist. If not, add them.
xml_material_profile = self._getXmlProfileClass()
if self._material_container_suffix is None:
self._material_container_suffix = ContainerRegistry.getMimeTypeForContainer(xml_material_profile).suffixes[0]
if xml_material_profile:
material_container_files = [name for name in cura_file_names if name.endswith(self._material_container_suffix)]
for material_container_file in material_container_files:
container_id = self._stripFileToId(material_container_file)
materials = self._container_registry.findInstanceContainers(id = container_id)
if not materials:
material_container = xml_material_profile(container_id)
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
containers_to_add.append(material_container)
else:
material_container = materials[0]
if not material_container.isReadOnly(): # Only create new materials if they are not read only.
if self._resolve_strategies["material"] == "override":
material_container.deserialize(archive.open(material_container_file).read().decode("utf-8"))
elif self._resolve_strategies["material"] == "new":
# Note that we *must* deserialize it with a new ID, as multiple containers will be
#.........这里部分代码省略.........