UM2UpgradeSelection.py 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Uranium is released under the terms of the AGPLv3 or higher.
  3. from UM.Settings.ContainerRegistry import ContainerRegistry
  4. from UM.Settings.InstanceContainer import InstanceContainer
  5. from cura.MachineAction import MachineAction
  6. from PyQt5.QtCore import pyqtSlot, pyqtSignal, pyqtProperty
  7. from UM.i18n import i18nCatalog
  8. from UM.Application import Application
  9. from UM.Util import parseBool
  10. catalog = i18nCatalog("cura")
  11. import UM.Settings.InstanceContainer
  12. ## The Ultimaker 2 can have a few revisions & upgrades.
  13. class UM2UpgradeSelection(MachineAction):
  14. def __init__(self):
  15. super().__init__("UM2UpgradeSelection", catalog.i18nc("@action", "Select upgrades"))
  16. self._qml_url = "UM2UpgradeSelectionMachineAction.qml"
  17. self._container_registry = ContainerRegistry.getInstance()
  18. def _reset(self):
  19. self.hasVariantsChanged.emit()
  20. hasVariantsChanged = pyqtSignal()
  21. @pyqtProperty(bool, notify = hasVariantsChanged)
  22. def hasVariants(self):
  23. global_container_stack = Application.getInstance().getGlobalContainerStack()
  24. if global_container_stack:
  25. return parseBool(global_container_stack.getMetaDataEntry("has_variants", "false"))
  26. @pyqtSlot(bool)
  27. def setHasVariants(self, has_variants = True):
  28. global_container_stack = Application.getInstance().getGlobalContainerStack()
  29. if global_container_stack:
  30. variant_container = global_container_stack.variant
  31. variant_index = global_container_stack.getContainerIndex(variant_container)
  32. if has_variants:
  33. if "has_variants" in global_container_stack.getMetaData():
  34. global_container_stack.setMetaDataEntry("has_variants", True)
  35. else:
  36. global_container_stack.addMetaDataEntry("has_variants", True)
  37. # Set the variant container to a sane default
  38. empty_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
  39. if type(variant_container) == type(empty_container):
  40. search_criteria = { "type": "variant", "definition": "ultimaker2", "id": "*0.4*" }
  41. containers = self._container_registry.findInstanceContainers(**search_criteria)
  42. if containers:
  43. global_container_stack.variant = containers[0]
  44. else:
  45. # The metadata entry is stored in an ini, and ini files are parsed as strings only.
  46. # Because any non-empty string evaluates to a boolean True, we have to remove the entry to make it False.
  47. if "has_variants" in global_container_stack.getMetaData():
  48. global_container_stack.removeMetaDataEntry("has_variants")
  49. # Set the variant container to an empty variant
  50. global_container_stack.variant = ContainerRegistry.getInstance().getEmptyInstanceContainer()
  51. Application.getInstance().globalContainerStackChanged.emit()