Cura/cura/API/__init__.py
Ghostkeeper 4e361a068c
Revert "Merge pull request #5726 from Ultimaker/CL-1331_use_API_for_UM3NetworkPrinting"
This reverts commit bec7b6546d3f7de457418a2e15f08c1e6dfa3148, reversing
changes made to 7094b222b10076af3a13f11b03dd3416eae12156.

The changes there were not accepted. Please see pull request https://github.com/Ultimaker/Cura/pull/5726 for the discussion about this.

Conflicts:
	plugins/UM3NetworkPrinting/src/UM3OutputDevicePlugin.py -> Just in one TODO comment.
2019-05-23 13:40:11 +02:00

64 lines
2.3 KiB
Python

# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
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
## The official Cura API that plug-ins can use to interact with Cura.
#
# Python does not technically prevent talking to other classes as well, but
# this API provides a version-safe interface with proper deprecation warnings
# etc. Usage of any other methods than the ones provided in this API can cause
# plug-ins to be unstable.
class CuraAPI(QObject):
# For now we use the same API version to be consistent.
__instance = None # type: "CuraAPI"
_application = None # type: CuraApplication
# This is done to ensure that the first time an instance is created, it's forced that the application is set.
# The main reason for this is that we want to prevent consumers of API to have a dependency on CuraApplication.
# 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
self._account = Account(self._application)
# Backups API
self._backups = Backups(self._application)
# Interface API
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