MaterialsModel.py 1007 B

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