mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-30 15:54:32 +08:00

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.
48 lines
1.9 KiB
Python
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})
|