mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-01 08:14:22 +08:00

I was hoping to completely nix the generic materials model (since it's basically just a brand "Generic", but then in the QML it has to be have the same in terms of sub-menus or fold-outs and that looked stupid (Generic -> ABS -> ABS)). So we keep that one for now. It is cleaner though. Contributes to CURA-5162, CURA-5378
55 lines
2.0 KiB
Python
55 lines
2.0 KiB
Python
# Copyright (c) 2018 Ultimaker B.V.
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
|
|
from UM.Logger import Logger
|
|
from cura.Machines.Models.BaseMaterialsModel import BaseMaterialsModel
|
|
|
|
class FavoriteMaterialsModel(BaseMaterialsModel):
|
|
|
|
def __init__(self, parent = None):
|
|
super().__init__(parent)
|
|
self._material_manager.favoritesUpdated.connect(self._update) # Update when favorites are changed
|
|
self._update()
|
|
|
|
def _update(self):
|
|
|
|
# Perform standard check and reset if the check fails
|
|
if not self._canUpdate():
|
|
self.setItems([])
|
|
return
|
|
|
|
# Get updated list of favorites
|
|
self._favorite_ids = self._material_manager.getFavorites()
|
|
|
|
item_list = []
|
|
|
|
for root_material_id, container_node in self._available_materials.items():
|
|
metadata = container_node.metadata
|
|
|
|
# Do not include the materials from a to-be-removed package
|
|
if bool(metadata.get("removed", False)):
|
|
continue
|
|
|
|
# Only add results for favorite materials
|
|
if root_material_id not in self._favorite_ids:
|
|
continue
|
|
|
|
item = {
|
|
"root_material_id": root_material_id,
|
|
"id": metadata["id"],
|
|
"GUID": metadata["GUID"],
|
|
"name": metadata["name"],
|
|
"brand": metadata["brand"],
|
|
"material": metadata["material"],
|
|
"color_name": metadata["color_name"],
|
|
"color_code": metadata["color_code"],
|
|
"container_node": container_node,
|
|
"is_favorite": True # Don't need to set since we only include favorites anyway
|
|
}
|
|
item_list.append(item)
|
|
|
|
# Sort the item list alphabetically by name
|
|
item_list = sorted(item_list, key = lambda d: d["brand"].upper())
|
|
|
|
self.setItems(item_list)
|