Add some more documentation to ContainerManager

Contributes to CURA-341
This commit is contained in:
Arjen Hiemstra 2016-07-05 16:44:13 +02:00
parent 6f3fa19890
commit ff9e4c9bb7

View file

@ -8,13 +8,26 @@ import UM.Settings
from UM.i18n import i18nCatalog from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura") catalog = i18nCatalog("cura")
## Manager class that contains common actions to deal with containers in Cura.
#
# This is primarily intended as a class to be able to perform certain actions
# from within QML. We want to be able to trigger things like removing a container
# when a certain action happens. This can be done through this class.
class ContainerManager(QObject): class ContainerManager(QObject):
def __init__(self, parent = None): def __init__(self, parent = None):
super().__init__(parent) super().__init__(parent)
self._registry = UM.Settings.ContainerRegistry.getInstance() self._registry = UM.Settings.ContainerRegistry.getInstance()
@pyqtSlot(str) ## Create a duplicate of the specified container
#
# This will create and add a duplicate of the container corresponding
# to the container ID.
#
# \param container_id \type{str} The ID of the container to duplicate.
#
# \return The ID of the new container, or an empty string if duplication failed.
@pyqtSlot(str, result = str)
def duplicateContainer(self, container_id): def duplicateContainer(self, container_id):
containers = self._registry.findInstanceContainers(id = container_id) containers = self._registry.findInstanceContainers(id = container_id)
if not containers: if not containers:
@ -32,6 +45,16 @@ class ContainerManager(QObject):
def removeContainer(self, container_id): def removeContainer(self, container_id):
pass pass
## Set a metadata entry of the specified container.
#
# This will set the specified entry of the container's metadata to the specified
# value. Note that entries containing dictionaries can have their entries changed
# by using "/" as a separator. For example, to change an entry "foo" in a
# dictionary entry "bar", you can specify "bar/foo" as entry name.
#
# \param container_id \type{str} The ID of the container to change.
# \param entry_name \type{str} The name of the metadata entry to change.
# \param entry_value The new value of the entry.
@pyqtSlot(str, str, str) @pyqtSlot(str, str, str)
def setContainerMetaDataEntry(self, container_id, entry_name, entry_value): def setContainerMetaDataEntry(self, container_id, entry_name, entry_value):
containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id) containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
@ -58,6 +81,7 @@ class ContainerManager(QObject):
containers[0].setMetaDataEntry(entry_name, entry_value) containers[0].setMetaDataEntry(entry_name, entry_value)
# Factory function, used by QML
@staticmethod @staticmethod
def createContainerManager(engine, js_engine): def createContainerManager(engine, js_engine):
return ContainerManager() return ContainerManager()