diff --git a/cura/Settings/ContainerManager.py b/cura/Settings/ContainerManager.py index 4b0a82f184..621e559eb2 100644 --- a/cura/Settings/ContainerManager.py +++ b/cura/Settings/ContainerManager.py @@ -235,6 +235,31 @@ class ContainerManager(QObject): return True + ## Set a metadata entry of the specified container. + # + # \param container_id \type{str} The ID of the container to change. + # \param setting_key \type{str} The key of the setting. + # \param property_name \type{str} The name of the property, eg "value". + # \param property_value \type{str} The new value of the property. + # + # \return True if successful, False if not. + @pyqtSlot(str, str, str, str, result = bool) + def setContainerProperty(self, container_id, setting_key, property_name, value_value): + containers = self._container_registry.findContainers(None, id = container_id) + if not containers: + Logger.log("w", "Could not set properties of container %s because it was not found.", container_id) + return False + + container = containers[0] + + if container.isReadOnly(): + Logger.log("w", "Cannot set properties of read-only container %s.", container_id) + return False + + container.setProperty(setting_key, property_name, value_value) + + return True + ## Set the name of the specified container. @pyqtSlot(str, str, result = bool) def setContainerName(self, container_id, new_name): diff --git a/resources/qml/Preferences/MaterialView.qml b/resources/qml/Preferences/MaterialView.qml index 9290126502..5424a80546 100644 --- a/resources/qml/Preferences/MaterialView.qml +++ b/resources/qml/Preferences/MaterialView.qml @@ -164,7 +164,11 @@ TabView stepSize: 0.01 readOnly: !base.editingEnabled - onEditingFinished: base.setMetaDataEntry("properties/diameter", properties.diameter, value) + onEditingFinished: + { + Cura.ContainerManager.setContainerProperty(base.containerId, "material_diameter", "value", value) + base.setMetaDataEntry("properties/diameter", properties.diameter, value) + } onValueChanged: updateCostPerMeter() }