GenericMaterialsModel.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (c) 2021 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional
  4. from cura.Machines.Models.BaseMaterialsModel import BaseMaterialsModel
  5. class GenericMaterialsModel(BaseMaterialsModel):
  6. def __init__(self, parent: Optional["QObject"] = None) -> None:
  7. super(GenericMaterialsModel, self).__init__(parent = parent)
  8. self._onChanged()
  9. def _update(self):
  10. if not self._canUpdate():
  11. return
  12. super()._update()
  13. item_list = []
  14. for root_material_id, container_node in self._available_materials.items():
  15. # Do not include the materials from a to-be-removed package
  16. if bool(container_node.getMetaDataEntry("removed", False)):
  17. continue
  18. # Only add results for generic materials
  19. if container_node.getMetaDataEntry("brand", "unknown").lower() != "generic":
  20. continue
  21. item = self._createMaterialItem(root_material_id, container_node)
  22. if item:
  23. item_list.append(item)
  24. # Sort the item list alphabetically by name
  25. item_list = sorted(item_list, key = lambda d: d["name"].upper())
  26. self.setItems(item_list)