FavoriteMaterialsModel.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. ## Model that shows the list of favorite materials.
  5. class FavoriteMaterialsModel(BaseMaterialsModel):
  6. def __init__(self, parent = None):
  7. super().__init__(parent)
  8. self._update()
  9. def _update(self):
  10. if not self._canUpdate():
  11. return
  12. # Get updated list of favorites
  13. self._favorite_ids = self._material_manager.getFavorites()
  14. item_list = []
  15. for root_material_id, container_node in self._available_materials.items():
  16. metadata = container_node.getMetadata()
  17. # Do not include the materials from a to-be-removed package
  18. if bool(metadata.get("removed", False)):
  19. continue
  20. # Only add results for favorite materials
  21. if root_material_id not in self._favorite_ids:
  22. continue
  23. item = self._createMaterialItem(root_material_id, container_node)
  24. item_list.append(item)
  25. # Sort the item list alphabetically by name
  26. item_list = sorted(item_list, key = lambda d: d["brand"].upper())
  27. self.setItems(item_list)