GenericMaterialsModel.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) 2018 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._update()
  8. def _update(self):
  9. if not self._canUpdate():
  10. return
  11. # Get updated list of favorites
  12. self._favorite_ids = self._material_manager.getFavorites()
  13. item_list = []
  14. for root_material_id, container_node in self._available_materials.items():
  15. metadata = container_node.getMetadata()
  16. # Do not include the materials from a to-be-removed package
  17. if bool(metadata.get("removed", False)):
  18. continue
  19. # Only add results for generic materials
  20. if metadata["brand"].lower() != "generic":
  21. continue
  22. item = self._createMaterialItem(root_material_id, container_node)
  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)