No longer chache singleton objects

CURA-6005
This commit is contained in:
Jaime van Kessel 2019-01-03 16:44:08 +01:00
parent 773190bee1
commit 65183ade0a
3 changed files with 13 additions and 18 deletions

View file

@ -7,4 +7,4 @@ def getMetaData():
return {} return {}
def register(app): def register(app):
return {"extension": DrivePluginExtension(app)} return {"extension": DrivePluginExtension()}

View file

@ -12,16 +12,14 @@ import requests
from UM.Logger import Logger from UM.Logger import Logger
from UM.Message import Message from UM.Message import Message
from UM.Signal import Signal from UM.Signal import Signal
from cura.CuraApplication import CuraApplication
from .UploadBackupJob import UploadBackupJob from .UploadBackupJob import UploadBackupJob
from .Settings import Settings from .Settings import Settings
## The DriveApiService is responsible for interacting with the CuraDrive API and Cura's backup handling.
class DriveApiService: 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) GET_BACKUPS_URL = "{}/backups".format(Settings.DRIVE_API_URL)
PUT_BACKUP_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) DELETE_BACKUP_URL = "{}/backups".format(Settings.DRIVE_API_URL)
@ -32,9 +30,8 @@ class DriveApiService:
# Emit signal when creating backup started or finished. # Emit signal when creating backup started or finished.
onCreatingStateChanged = Signal() onCreatingStateChanged = Signal()
def __init__(self, cura_api) -> None: def __init__(self) -> None:
"""Create a new instance of the Drive API service and set the cura_api object.""" self._cura_api = CuraApplication.getInstance().getCuraAPI()
self._cura_api = cura_api
def getBackups(self) -> List[Dict[str, Any]]: def getBackups(self) -> List[Dict[str, Any]]:
"""Get all backups from the API.""" """Get all backups from the API."""

View file

@ -7,8 +7,10 @@ from typing import Optional
from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal
from UM.Application import Application
from UM.Extension import Extension from UM.Extension import Extension
from UM.Message import Message from UM.Message import Message
from cura.CuraApplication import CuraApplication
from .Settings import Settings from .Settings import Settings
from .DriveApiService import DriveApiService from .DriveApiService import DriveApiService
@ -34,11 +36,8 @@ class DrivePluginExtension(QObject, Extension):
DATE_FORMAT = "%d/%m/%Y %H:%M:%S" DATE_FORMAT = "%d/%m/%Y %H:%M:%S"
def __init__(self, application): def __init__(self):
super(DrivePluginExtension, self).__init__() super(DrivePluginExtension, self).__init__()
# Re-usable instance of application.
self._application = application
# Local data caching for the UI. # Local data caching for the UI.
self._drive_window = None # type: Optional[QObject] self._drive_window = None # type: Optional[QObject]
@ -47,12 +46,11 @@ class DrivePluginExtension(QObject, Extension):
self._is_creating_backup = False self._is_creating_backup = False
# Initialize services. # Initialize services.
self._preferences = self._application.getPreferences() self._preferences = CuraApplication.getInstance().getPreferences()
self._cura_api = self._application.getCuraAPI() self._drive_api_service = DriveApiService()
self._drive_api_service = DriveApiService(self._cura_api)
# Attach signals. # 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.onRestoringStateChanged.connect(self._onRestoringStateChanged)
self._drive_api_service.onCreatingStateChanged.connect(self._onCreatingStateChanged) self._drive_api_service.onCreatingStateChanged.connect(self._onCreatingStateChanged)
@ -65,7 +63,7 @@ class DrivePluginExtension(QObject, Extension):
self._updateMenuItems() self._updateMenuItems()
# Make auto-backup on boot if required. # Make auto-backup on boot if required.
self._application.engineCreatedSignal.connect(self._autoBackup) CuraApplication.getInstance().engineCreatedSignal.connect(self._autoBackup)
def showDriveWindow(self) -> None: def showDriveWindow(self) -> None:
"""Show the Drive UI popup window.""" """Show the Drive UI popup window."""
@ -81,7 +79,7 @@ class DrivePluginExtension(QObject, Extension):
:return: The popup window object. :return: The popup window object.
""" """
path = os.path.join(os.path.dirname(__file__), "qml", "main.qml") 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: def _updateMenuItems(self) -> None:
"""Update the menu items.""" """Update the menu items."""