UserAgreement.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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.QtQml import QQmlComponent, QQmlContext
  10. from PyQt5.QtCore import QUrl, QObject, pyqtSlot
  11. import os.path
  12. class UserAgreement(QObject, Extension):
  13. def __init__(self, parent = None):
  14. super(UserAgreement, self).__init__()
  15. self._user_agreement_window = None
  16. self._user_agreement_context = None
  17. Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated)
  18. Preferences.getInstance().addPreference("general/accepted_user_agreement", False)
  19. def _onEngineCreated(self):
  20. if not Preferences.getInstance().getValue("general/accepted_user_agreement"):
  21. self.showUserAgreement()
  22. def showUserAgreement(self):
  23. if not self._user_agreement_window:
  24. self.createUserAgreementWindow()
  25. self._user_agreement_window.show()
  26. @pyqtSlot(bool)
  27. def didAgree(self, userChoice):
  28. if userChoice:
  29. Logger.log("i", "User agreed to the user agreement")
  30. Preferences.getInstance().setValue("general/accepted_user_agreement", True)
  31. self._user_agreement_window.hide()
  32. else:
  33. Logger.log("i", "User did NOT agree to the user agreement")
  34. Preferences.getInstance().setValue("general/accepted_user_agreement", False)
  35. CuraApplication.getInstance().quit()
  36. CuraApplication.getInstance().setNeedToShowUserAgreement(False)
  37. def createUserAgreementWindow(self):
  38. path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "UserAgreement.qml"))
  39. component = QQmlComponent(Application.getInstance()._engine, path)
  40. self._user_agreement_context = QQmlContext(Application.getInstance()._engine.rootContext())
  41. self._user_agreement_context.setContextProperty("manager", self)
  42. self._user_agreement_window = component.create(self._user_agreement_context)