CustomQualityProfilesDropDownMenuModel.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) 2021 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import Optional, TYPE_CHECKING
  4. from UM.Logger import Logger
  5. import cura.CuraApplication # Imported this way to prevent circular references.
  6. from cura.Machines.ContainerTree import ContainerTree
  7. from cura.Machines.Models.QualityProfilesDropDownMenuModel import QualityProfilesDropDownMenuModel
  8. if TYPE_CHECKING:
  9. from PyQt5.QtCore import QObject
  10. from UM.Settings.Interfaces import ContainerInterface
  11. class CustomQualityProfilesDropDownMenuModel(QualityProfilesDropDownMenuModel):
  12. """This model is used for the custom profile items in the profile drop down menu."""
  13. def __init__(self, parent: Optional["QObject"] = None) -> None:
  14. super(CustomQualityProfilesDropDownMenuModel, self).__init__(parent = parent)
  15. container_registry = cura.CuraApplication.CuraApplication.getInstance().getContainerRegistry()
  16. container_registry.containerAdded.connect(self._qualityChangesListChanged)
  17. container_registry.containerRemoved.connect(self._qualityChangesListChanged)
  18. container_registry.containerMetaDataChanged.connect(self._qualityChangesListChanged)
  19. def _qualityChangesListChanged(self, container: "ContainerInterface") -> None:
  20. if container.getMetaDataEntry("type") == "quality_changes":
  21. self._update()
  22. def _update(self) -> None:
  23. Logger.log("d", "Updating {model_class_name}.".format(model_class_name = self.__class__.__name__))
  24. active_global_stack = cura.CuraApplication.CuraApplication.getInstance().getMachineManager().activeMachine
  25. if active_global_stack is None:
  26. self.setItems([])
  27. Logger.log("d", "No active GlobalStack, set %s as empty.", self.__class__.__name__)
  28. return
  29. quality_changes_list = ContainerTree.getInstance().getCurrentQualityChangesGroups()
  30. item_list = []
  31. for quality_changes_group in sorted(quality_changes_list, key = lambda qgc: qgc.name.lower()):
  32. item = {"name": quality_changes_group.name,
  33. "layer_height": "",
  34. "layer_height_without_unit": "",
  35. "available": quality_changes_group.is_available,
  36. "quality_changes_group": quality_changes_group}
  37. item_list.append(item)
  38. self.setItems(item_list)