Cura/plugins/UserAgreement/UserAgreement.py
Diego Prado Gesto 43657010ba CURA-5164 The Preferences is not a singleton class anymore since in some point
several instances need to be created.

- In the ThreeMFWorkspaceReader we need to create some temporal
instances of Preferences that makes it not singleton anymore.

- The current preferences are kept in the Application class and so all
the calls to the preferences are changed to get the preferences from
Application.

- The method getInstance in Preferences is kept as deprecated since some
external plugins.
2018-05-11 08:50:42 +02:00

48 lines
1.9 KiB
Python

# Copyright (c) 2017 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from UM.Extension import Extension
from UM.Application import Application
from UM.PluginRegistry import PluginRegistry
from UM.Logger import Logger
from cura.CuraApplication import CuraApplication
from PyQt5.QtCore import QObject, pyqtSlot
import os.path
class UserAgreement(QObject, Extension):
def __init__(self):
super(UserAgreement, self).__init__()
self._user_agreement_window = None
self._user_agreement_context = None
Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated)
Application.getInstance().getPreferences().addPreference("general/accepted_user_agreement", False)
def _onEngineCreated(self):
if not Application.getInstance().getPreferences().getValue("general/accepted_user_agreement"):
self.showUserAgreement()
def showUserAgreement(self):
if not self._user_agreement_window:
self.createUserAgreementWindow()
self._user_agreement_window.show()
@pyqtSlot(bool)
def didAgree(self, user_choice):
if user_choice:
Logger.log("i", "User agreed to the user agreement")
Application.getInstance().getPreferences().setValue("general/accepted_user_agreement", True)
self._user_agreement_window.hide()
else:
Logger.log("i", "User did NOT agree to the user agreement")
Application.getInstance().getPreferences().setValue("general/accepted_user_agreement", False)
CuraApplication.getInstance().quit()
CuraApplication.getInstance().setNeedToShowUserAgreement(False)
def createUserAgreementWindow(self):
path = os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "UserAgreement.qml")
self._user_agreement_window = Application.getInstance().createQmlComponent(path, {"manager": self})