mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-14 17:25:57 +08:00
Ensure that CuraAPI can be called in the same way as before
This should prevent another API break. CURA-5744
This commit is contained in:
parent
acb7df710c
commit
18361b9434
@ -23,10 +23,22 @@ class CuraAPI(QObject):
|
|||||||
|
|
||||||
# For now we use the same API version to be consistent.
|
# For now we use the same API version to be consistent.
|
||||||
VERSION = PluginRegistry.APIVersion
|
VERSION = PluginRegistry.APIVersion
|
||||||
|
__instance = None # type: "CuraAPI"
|
||||||
|
_application = None # type: CuraApplication
|
||||||
|
|
||||||
def __init__(self, application: "CuraApplication") -> None:
|
# This is done to ensure that the first time an instance is created, it's forced that the application is set.
|
||||||
super().__init__(parent = application)
|
# The main reason for this is that we want to prevent consumers of API to have a dependency on CuraApplication.
|
||||||
self._application = application
|
# Since the API is intended to be used by plugins, the cura application should have already created this.
|
||||||
|
def __new__(cls, application: Optional["CuraApplication"] = None):
|
||||||
|
if cls.__instance is None:
|
||||||
|
if application is None:
|
||||||
|
raise Exception("Upon first time creation, the application must be set.")
|
||||||
|
cls.__instance = super(CuraAPI, cls).__new__(cls)
|
||||||
|
cls._application = application
|
||||||
|
return cls.__instance
|
||||||
|
|
||||||
|
def __init__(self, application: Optional["CuraApplication"] = None) -> None:
|
||||||
|
super().__init__(parent = CuraAPI._application)
|
||||||
|
|
||||||
# Accounts API
|
# Accounts API
|
||||||
self._account = Account(self._application)
|
self._account = Account(self._application)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user