mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-13 01:37:51 -06:00
No longer chache singleton objects
CURA-6005
This commit is contained in:
parent
773190bee1
commit
65183ade0a
3 changed files with 13 additions and 18 deletions
|
@ -7,4 +7,4 @@ def getMetaData():
|
|||
return {}
|
||||
|
||||
def register(app):
|
||||
return {"extension": DrivePluginExtension(app)}
|
||||
return {"extension": DrivePluginExtension()}
|
||||
|
|
|
@ -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."""
|
||||
|
|
|
@ -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,12 +36,9 @@ 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]
|
||||
self._backups_list_model = BackupListModel()
|
||||
|
@ -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."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue