UserAgreement.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (c) 2017 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Extension import Extension
  4. from UM.Preferences import Preferences
  5. from UM.Application import Application
  6. from UM.PluginRegistry import PluginRegistry
  7. from UM.Logger import Logger
  8. from cura.CuraApplication import CuraApplication
  9. from PyQt5.QtCore import QObject, pyqtSlot
  10. import os.path
  11. class UserAgreement(QObject, Extension):
  12. def __init__(self):
  13. super(UserAgreement, self).__init__()
  14. self._user_agreement_window = None
  15. self._user_agreement_context = None
  16. Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated)
  17. Preferences.getInstance().addPreference("general/accepted_user_agreement", False)
  18. def _onEngineCreated(self):
  19. if not Preferences.getInstance().getValue("general/accepted_user_agreement"):
  20. self.showUserAgreement()
  21. def showUserAgreement(self):
  22. if not self._user_agreement_window:
  23. self.createUserAgreementWindow()
  24. self._user_agreement_window.show()
  25. @pyqtSlot(bool)
  26. def didAgree(self, user_choice):
  27. if user_choice:
  28. Logger.log("i", "User agreed to the user agreement")
  29. Preferences.getInstance().setValue("general/accepted_user_agreement", True)
  30. self._user_agreement_window.hide()
  31. else:
  32. Logger.log("i", "User did NOT agree to the user agreement")
  33. Preferences.getInstance().setValue("general/accepted_user_agreement", False)
  34. CuraApplication.getInstance().quit()
  35. CuraApplication.getInstance().setNeedToShowUserAgreement(False)
  36. def createUserAgreementWindow(self):
  37. path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "UserAgreement.qml")
  38. self._user_agreement_window = Application.getInstance().createQmlComponent(path, {"manager": self})