From 65183ade0a53deceac8c00413e656aec79e12628 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 3 Jan 2019 16:44:08 +0100 Subject: [PATCH] No longer chache singleton objects CURA-6005 --- plugins/CuraDrive/__init__.py | 2 +- plugins/CuraDrive/src/DriveApiService.py | 11 ++++------- plugins/CuraDrive/src/DrivePluginExtension.py | 18 ++++++++---------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/plugins/CuraDrive/__init__.py b/plugins/CuraDrive/__init__.py index 766d94752f..dd7ffeaac3 100644 --- a/plugins/CuraDrive/__init__.py +++ b/plugins/CuraDrive/__init__.py @@ -7,4 +7,4 @@ def getMetaData(): return {} def register(app): - return {"extension": DrivePluginExtension(app)} + return {"extension": DrivePluginExtension()} diff --git a/plugins/CuraDrive/src/DriveApiService.py b/plugins/CuraDrive/src/DriveApiService.py index a542ac439e..3b6641cd74 100644 --- a/plugins/CuraDrive/src/DriveApiService.py +++ b/plugins/CuraDrive/src/DriveApiService.py @@ -12,16 +12,14 @@ import requests from UM.Logger import Logger from UM.Message import Message from UM.Signal import Signal +from cura.CuraApplication import CuraApplication from .UploadBackupJob import UploadBackupJob from .Settings import Settings +## The DriveApiService is responsible for interacting with the CuraDrive API and Cura's backup handling. class DriveApiService: - """ - The DriveApiService is responsible for interacting with the CuraDrive API and Cura's backup handling. - """ - GET_BACKUPS_URL = "{}/backups".format(Settings.DRIVE_API_URL) PUT_BACKUP_URL = "{}/backups".format(Settings.DRIVE_API_URL) DELETE_BACKUP_URL = "{}/backups".format(Settings.DRIVE_API_URL) @@ -32,9 +30,8 @@ class DriveApiService: # Emit signal when creating backup started or finished. onCreatingStateChanged = Signal() - def __init__(self, cura_api) -> None: - """Create a new instance of the Drive API service and set the cura_api object.""" - self._cura_api = cura_api + def __init__(self) -> None: + self._cura_api = CuraApplication.getInstance().getCuraAPI() def getBackups(self) -> List[Dict[str, Any]]: """Get all backups from the API.""" diff --git a/plugins/CuraDrive/src/DrivePluginExtension.py b/plugins/CuraDrive/src/DrivePluginExtension.py index a76c623fe8..bed54140d9 100644 --- a/plugins/CuraDrive/src/DrivePluginExtension.py +++ b/plugins/CuraDrive/src/DrivePluginExtension.py @@ -7,8 +7,10 @@ from typing import Optional from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal +from UM.Application import Application from UM.Extension import Extension from UM.Message import Message +from cura.CuraApplication import CuraApplication from .Settings import Settings from .DriveApiService import DriveApiService @@ -34,11 +36,8 @@ class DrivePluginExtension(QObject, Extension): DATE_FORMAT = "%d/%m/%Y %H:%M:%S" - def __init__(self, application): + def __init__(self): super(DrivePluginExtension, self).__init__() - - # Re-usable instance of application. - self._application = application # Local data caching for the UI. self._drive_window = None # type: Optional[QObject] @@ -47,12 +46,11 @@ class DrivePluginExtension(QObject, Extension): self._is_creating_backup = False # Initialize services. - self._preferences = self._application.getPreferences() - self._cura_api = self._application.getCuraAPI() - self._drive_api_service = DriveApiService(self._cura_api) + self._preferences = CuraApplication.getInstance().getPreferences() + self._drive_api_service = DriveApiService() # Attach signals. - self._cura_api.account.loginStateChanged.connect(self._onLoginStateChanged) + CuraApplication.getInstance().getCuraAPI().account.loginStateChanged.connect(self._onLoginStateChanged) self._drive_api_service.onRestoringStateChanged.connect(self._onRestoringStateChanged) self._drive_api_service.onCreatingStateChanged.connect(self._onCreatingStateChanged) @@ -65,7 +63,7 @@ class DrivePluginExtension(QObject, Extension): self._updateMenuItems() # Make auto-backup on boot if required. - self._application.engineCreatedSignal.connect(self._autoBackup) + CuraApplication.getInstance().engineCreatedSignal.connect(self._autoBackup) def showDriveWindow(self) -> None: """Show the Drive UI popup window.""" @@ -81,7 +79,7 @@ class DrivePluginExtension(QObject, Extension): :return: The popup window object. """ path = os.path.join(os.path.dirname(__file__), "qml", "main.qml") - return self._application.createQmlComponent(path, {"CuraDrive": self}) + return CuraApplication.getInstance().createQmlComponent(path, {"CuraDrive": self}) def _updateMenuItems(self) -> None: """Update the menu items."""