GenericMaterialsModel.py 1.1 KB

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