SimpleModeSettingsManager.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty
  4. from UM.Application import Application
  5. class SimpleModeSettingsManager(QObject):
  6. def __init__(self, parent = None):
  7. super().__init__(parent)
  8. self._machine_manager = Application.getInstance().getMachineManager()
  9. self._is_profile_customized = False # True when default profile has user changes
  10. self._is_profile_user_created = False # True when profile was custom created by user
  11. self._machine_manager.activeStackValueChanged.connect(self._updateIsProfileCustomized)
  12. # update on create as the activeQualityChanged signal is emitted before this manager is created when Cura starts
  13. self._updateIsProfileCustomized()
  14. isProfileCustomizedChanged = pyqtSignal()
  15. @pyqtProperty(bool, notify = isProfileCustomizedChanged)
  16. def isProfileCustomized(self):
  17. return self._is_profile_customized
  18. def _updateIsProfileCustomized(self):
  19. user_setting_keys = set()
  20. if not self._machine_manager.activeMachine:
  21. return False
  22. global_stack = self._machine_manager.activeMachine
  23. # check user settings in the global stack
  24. user_setting_keys.update(global_stack.userChanges.getAllKeys())
  25. # check user settings in the extruder stacks
  26. if global_stack.extruderList:
  27. for extruder_stack in global_stack.extruderList:
  28. user_setting_keys.update(extruder_stack.userChanges.getAllKeys())
  29. has_customized_user_settings = len(user_setting_keys) > 0
  30. if has_customized_user_settings != self._is_profile_customized:
  31. self._is_profile_customized = has_customized_user_settings
  32. self.isProfileCustomizedChanged.emit()