From 21c81603b491ab7378752b5afd2e16dd0b648899 Mon Sep 17 00:00:00 2001 From: ChrisTerBeke Date: Mon, 26 Nov 2018 13:33:14 +0100 Subject: [PATCH] Use application singleton instead of locally cached application --- cura/NetworkClient.py | 8 +++----- .../src/Cloud/CloudOutputDeviceManager.py | 14 ++++++++------ plugins/UM3NetworkPrinting/src/Cloud/Models.py | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/cura/NetworkClient.py b/cura/NetworkClient.py index eeedfeaa79..b150f59011 100644 --- a/cura/NetworkClient.py +++ b/cura/NetworkClient.py @@ -7,8 +7,8 @@ from PyQt5.QtCore import QUrl from PyQt5.QtNetwork import QNetworkAccessManager, QNetworkReply, QHttpMultiPart, QNetworkRequest, QHttpPart, \ QAuthenticator +from UM.Application import Application from UM.Logger import Logger -from cura.CuraApplication import CuraApplication ## Abstraction of QNetworkAccessManager for easier networking in Cura. @@ -17,9 +17,6 @@ class NetworkClient: def __init__(self) -> None: - # Use the given application instance or get the singleton instance. - self._application = CuraApplication.getInstance() - # Network manager instance to use for this client. self._manager = None # type: Optional[QNetworkAccessManager] @@ -29,7 +26,8 @@ class NetworkClient: self._last_request_time = None # type: Optional[float] # The user agent of Cura. - self._user_agent = "%s/%s " % (self._application.getApplicationName(), self._application.getVersion()) + application = Application.getInstance() + self._user_agent = "%s/%s " % (application.getApplicationName(), application.getVersion()) # Uses to store callback methods for finished network requests. # This allows us to register network calls with a callback directly instead of having to dissect the reply. diff --git a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py index e93393d736..17e82417ef 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/CloudOutputDeviceManager.py @@ -6,6 +6,7 @@ from typing import Dict, Optional from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply from UM.Logger import Logger +from cura.CuraApplication import CuraApplication from cura.NetworkClient import NetworkClient from plugins.UM3NetworkPrinting.src.Cloud.CloudOutputDevice import CloudOutputDevice from .Models import Cluster @@ -25,15 +26,16 @@ class CloudOutputDeviceManager(NetworkClient): def __init__(self): super().__init__() - - self._output_device_manager = self._application.getOutputDeviceManager() - self._account = self._application.getCuraAPI().account - + # Persistent dict containing the remote clusters for the authenticated user. self._remote_clusters = {} # type: Dict[str, CloudOutputDevice] + + application = CuraApplication.getInstance() + self._output_device_manager = application.getOutputDeviceManager() + self._account = application.getCuraAPI().account # When switching machines we check if we have to activate a remote cluster. - self._application.globalContainerStackChanged.connect(self._activeMachineChanged) + application.globalContainerStackChanged.connect(self._activeMachineChanged) # Fetch all remote clusters for the authenticated user. # TODO: update remote clusters periodically @@ -96,7 +98,7 @@ class CloudOutputDeviceManager(NetworkClient): ## Callback for when the active machine was changed by the user. def _activeMachineChanged(self): - active_machine = self._application.getGlobalContainerStack() + active_machine = CuraApplication.getInstance().getGlobalContainerStack() if not active_machine: return diff --git a/plugins/UM3NetworkPrinting/src/Cloud/Models.py b/plugins/UM3NetworkPrinting/src/Cloud/Models.py index 7d9bba32f7..b118f3e61c 100644 --- a/plugins/UM3NetworkPrinting/src/Cloud/Models.py +++ b/plugins/UM3NetworkPrinting/src/Cloud/Models.py @@ -8,4 +8,4 @@ Cluster = namedtuple("Cluster", [ "host_name", # Type: str "host_version", # Type: str "status", # Type: str -]) \ No newline at end of file +])