UMOUpgradeSelection.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. from UM.Settings.ContainerRegistry import ContainerRegistry
  2. from UM.Settings.InstanceContainer import InstanceContainer
  3. from cura.MachineAction import MachineAction
  4. from PyQt5.QtCore import pyqtSlot, pyqtSignal, pyqtProperty
  5. from UM.i18n import i18nCatalog
  6. from UM.Application import Application
  7. catalog = i18nCatalog("cura")
  8. import UM.Settings.InstanceContainer
  9. ## The Ultimaker Original can have a few revisions & upgrades. This action helps with selecting them, so they are added
  10. # as a variant.
  11. class UMOUpgradeSelection(MachineAction):
  12. def __init__(self):
  13. super().__init__("UMOUpgradeSelection", catalog.i18nc("@action", "Select upgrades"))
  14. self._qml_url = "UMOUpgradeSelectionMachineAction.qml"
  15. def _reset(self):
  16. self.heatedBedChanged.emit()
  17. heatedBedChanged = pyqtSignal()
  18. @pyqtProperty(bool, notify = heatedBedChanged)
  19. def hasHeatedBed(self):
  20. global_container_stack = Application.getInstance().getGlobalContainerStack()
  21. if global_container_stack:
  22. return global_container_stack.getProperty("machine_heated_bed", "value")
  23. @pyqtSlot(bool)
  24. def setHeatedBed(self, heated_bed = True):
  25. global_container_stack = Application.getInstance().getGlobalContainerStack()
  26. if global_container_stack:
  27. # Make sure there is a definition_changes container to store the machine settings
  28. definition_changes_container = global_container_stack.findContainer({"type": "definition_changes"})
  29. if not definition_changes_container:
  30. definition_changes_container = self._createDefinitionChangesContainer(global_container_stack)
  31. definition_changes_container.setProperty("machine_heated_bed", "value", heated_bed)
  32. self.heatedBedChanged.emit()
  33. def _createDefinitionChangesContainer(self, global_container_stack):
  34. # Create a definition_changes container to store the settings in and add it to the stack
  35. definition_changes_container = UM.Settings.InstanceContainer(global_container_stack.getName() + "_settings")
  36. definition = global_container_stack.getBottom()
  37. definition_changes_container.setDefinition(definition)
  38. definition_changes_container.addMetaDataEntry("type", "definition_changes")
  39. UM.Settings.ContainerRegistry.getInstance().addContainer(definition_changes_container)
  40. # Insert definition_changes between the definition and the variant
  41. global_container_stack.insertContainer(-1, definition_changes_container)
  42. return definition_changes_container