Cura/cura/Settings/MaterialsModel.py
Ghostkeeper bc219a06fe
Add MaterialsModel to make material list update upon metadata change
This new model inherits from InstanceContainersModel. The only change is that it updates when the metadata of a material container changes. This is needed to make the list of materials update when the material diameter changes.

Contributes to issue CURA-2822.
2017-06-22 18:17:16 +02:00

21 lines
1007 B
Python

# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from UM.Settings.ContainerRegistry import ContainerRegistry #To listen for changes to the materials.
from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel #We're extending this class.
## A model that shows a list of currently valid materials.
class MaterialsModel(InstanceContainersModel):
def __init__(self, parent = None):
super().__init__(parent)
ContainerRegistry.getInstance().containerMetaDataChanged.connect(self._onContainerMetaDataChanged)
## Called when the metadata of the container was changed.
#
# This makes sure that we only update when it was a material that changed.
#
# \param container The container whose metadata was changed.
def _onContainerMetaDataChanged(self, container):
if container.getMetaDataEntry("type") == "material": #Only need to update if a material was changed.
self._update()