IntentCategoryModel.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #Copyright (c) 2019 Ultimaker B.V.
  2. #Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt5.QtCore import Qt
  4. import collections
  5. from cura.Settings.IntentManager import IntentManager
  6. from UM.Qt.ListModel import ListModel
  7. from UM.i18n import i18nCatalog
  8. catalog = i18nCatalog("cura")
  9. ## Lists the intent categories that are available for the current printer
  10. # configuration.
  11. class IntentCategoryModel(ListModel):
  12. NameRole = Qt.UserRole + 1
  13. IntentCategoryRole = Qt.UserRole + 2
  14. WeightRole = Qt.UserRole + 3
  15. #Translations to user-visible string. Ordered by weight.
  16. #TODO: Create a solution for this name and weight to be used dynamically.
  17. name_translation = collections.OrderedDict() #type: "collections.OrderedDict[str,str]"
  18. name_translation["default"] = catalog.i18nc("@label", "Default")
  19. name_translation["engineering"] = catalog.i18nc("@label", "Engineering")
  20. name_translation["smooth"] = catalog.i18nc("@label", "Smooth")
  21. ## Creates a new model for a certain intent category.
  22. # \param The category to list the intent profiles for.
  23. def __init__(self, intent_category: str) -> None:
  24. super().__init__()
  25. self._intent_category = intent_category
  26. self.addRoleName(self.NameRole, "name")
  27. self.addRoleName(self.IntentCategoryRole, "intent_category")
  28. self.addRoleName(self.WeightRole, "weight")
  29. ## Updates the list of intents.
  30. def update(self) -> None:
  31. available_categories = IntentManager.getInstance().currentAvailableIntentCategories()
  32. result = []
  33. for category in available_categories:
  34. result.append({
  35. "name": self.name_translation.get(category, catalog.i18nc("@label", "Unknown")),
  36. "intent_category": category,
  37. "weight": list(self.name_translation.items()).index(category)
  38. })
  39. super().update(result)