12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- from typing import Optional, TYPE_CHECKING
- from PyQt5.QtCore import QObject, pyqtProperty
- from cura.API.Backups import Backups
- from cura.API.Interface import Interface
- from cura.API.Account import Account
- if TYPE_CHECKING:
- from cura.CuraApplication import CuraApplication
- class CuraAPI(QObject):
-
- __instance = None
- _application = None
-
-
-
- def __new__(cls, application: Optional["CuraApplication"] = None):
- if cls.__instance is not None:
- raise RuntimeError("Tried to create singleton '{class_name}' more than once.".format(class_name = CuraAPI.__name__))
- if application is None:
- raise RuntimeError("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)
-
- self._account = Account(self._application)
-
- self._backups = Backups(self._application)
-
- self._interface = Interface(self._application)
- def initialize(self) -> None:
- self._account.initialize()
- @pyqtProperty(QObject, constant = True)
- def account(self) -> "Account":
- return self._account
- @property
- def backups(self) -> "Backups":
- return self._backups
- @property
- def interface(self) -> "Interface":
- return self._interface
|