GenericMaterialsModel.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Logger import Logger
  4. from cura.Machines.Models.BaseMaterialsModel import BaseMaterialsModel
  5. class GenericMaterialsModel(BaseMaterialsModel):
  6. def __init__(self, parent = None):
  7. super().__init__(parent)
  8. self._update()
  9. def _update(self):
  10. # Perform standard check and reset if the check fails
  11. if not self._canUpdate():
  12. self.setItems([])
  13. return
  14. # Get updated list of favorites
  15. self._favorite_ids = self._material_manager.getFavorites()
  16. item_list = []
  17. for root_material_id, container_node in self._available_materials.items():
  18. metadata = container_node.getMetadata()
  19. # Do not include the materials from a to-be-removed package
  20. if bool(metadata.get("removed", False)):
  21. continue
  22. # Only add results for generic materials
  23. if metadata["brand"].lower() != "generic":
  24. continue
  25. item = self._createMaterialItem(root_material_id, container_node)
  26. item_list.append(item)
  27. # Sort the item list alphabetically by name
  28. item_list = sorted(item_list, key = lambda d: d["name"].upper())
  29. self.setItems(item_list)