mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-16 18:25:54 +08:00
Add a setContainerMetaDataEntry to ContainerManager
So that we can set metadata from QML Contributes to CURA-342
This commit is contained in:
parent
8badb061da
commit
92d3bea229
@ -12,15 +12,17 @@ class ContainerManager(QObject):
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
|
||||
self._registry = UM.Settings.ContainerRegistry.getInstance()
|
||||
|
||||
@pyqtSlot(str)
|
||||
def duplicateContainer(self, container_id):
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
||||
containers = self._registry.findInstanceContainers(id = container_id)
|
||||
if not containers:
|
||||
return
|
||||
|
||||
new_name = UM.Settings.ContainerRegistry.getInstance().uniqueName(containers[0].getName())
|
||||
new_name = self_registry.uniqueName(containers[0].getName())
|
||||
new_material = containers[0].duplicate(new_name)
|
||||
UM.Settings.ContainerRegistry.getInstance().addContainer(new_material)
|
||||
self._registry.addContainer(new_material)
|
||||
|
||||
@pyqtSlot(str, str)
|
||||
def renameContainer(self, container_id, new_name):
|
||||
@ -30,5 +32,31 @@ class ContainerManager(QObject):
|
||||
def removeContainer(self, container_id):
|
||||
pass
|
||||
|
||||
@pyqtSlot(str, str, str)
|
||||
def setContainerMetaDataEntry(self, container_id, entry_name, entry_value):
|
||||
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
||||
if not containers:
|
||||
return
|
||||
|
||||
container = containers[0]
|
||||
|
||||
entries = entry_name.split("/")
|
||||
entry_name = entries.pop()
|
||||
|
||||
if entries:
|
||||
root_name = entries.pop(0)
|
||||
root = container.getMetaDataEntry(root_name)
|
||||
|
||||
item = root
|
||||
for entry in entries:
|
||||
item = item.get(entries.pop(0), { })
|
||||
|
||||
item[entry_name] = entry_value
|
||||
|
||||
entry_name = root_name
|
||||
entry_value = root
|
||||
|
||||
containers[0].setMetaDataEntry(entry_name, entry_value)
|
||||
|
||||
def createContainerManager(engine, js_engine):
|
||||
return ContainerManager()
|
||||
|
Loading…
x
Reference in New Issue
Block a user