Fix more review comments

This commit is contained in:
ChrisTerBeke 2019-01-11 16:38:25 +01:00
parent 3c10cca0de
commit 7bbd43928a
5 changed files with 7 additions and 7 deletions

View file

@ -11,7 +11,7 @@ from PyQt5.QtNetwork import QNetworkRequest, QNetworkReply, QNetworkAccessManage
from UM.Logger import Logger from UM.Logger import Logger
from cura import UltimakerCloudAuthentication from cura import UltimakerCloudAuthentication
from cura.API import Account from cura.API import Account
from .MeshUploader import MeshUploader from .ToolPathUploader import ToolPathUploader
from ..Models import BaseModel from ..Models import BaseModel
from .Models.CloudClusterResponse import CloudClusterResponse from .Models.CloudClusterResponse import CloudClusterResponse
from .Models.CloudError import CloudError from .Models.CloudError import CloudError
@ -42,7 +42,7 @@ class CloudApiClient:
self._manager = QNetworkAccessManager() self._manager = QNetworkAccessManager()
self._account = account self._account = account
self._on_error = on_error self._on_error = on_error
self._upload = None # type: Optional[MeshUploader] self._upload = None # type: Optional[ToolPathUploader]
# In order to avoid garbage collection we keep the callbacks in this list. # In order to avoid garbage collection we keep the callbacks in this list.
self._anti_gc_callbacks = [] # type: List[Callable[[], None]] self._anti_gc_callbacks = [] # type: List[Callable[[], None]]
@ -84,7 +84,7 @@ class CloudApiClient:
# \param on_error: A function to be called if the upload fails. # \param on_error: A function to be called if the upload fails.
def uploadToolPath(self, print_job: CloudPrintJobResponse, mesh: bytes, on_finished: Callable[[], Any], def uploadToolPath(self, print_job: CloudPrintJobResponse, mesh: bytes, on_finished: Callable[[], Any],
on_progress: Callable[[int], Any], on_error: Callable[[], Any]): on_progress: Callable[[int], Any], on_error: Callable[[], Any]):
self._upload = MeshUploader(self._manager, print_job, mesh, on_finished, on_progress, on_error) self._upload = ToolPathUploader(self._manager, print_job, mesh, on_finished, on_progress, on_error)
self._upload.start() self._upload.start()
# Requests a cluster to print the given print job. # Requests a cluster to print the given print job.

View file

@ -100,6 +100,8 @@ class CloudOutputDevice(NetworkedPrinterOutputDevice):
## Connects this device. ## Connects this device.
def connect(self) -> None: def connect(self) -> None:
if self.isConnected():
return
super().connect() super().connect()
Logger.log("i", "Connected to cluster %s", self.key) Logger.log("i", "Connected to cluster %s", self.key)
CuraApplication.getInstance().getBackend().backendStateChange.connect(self._onBackendStateChange) CuraApplication.getInstance().getBackend().backendStateChange.connect(self._onBackendStateChange)

View file

@ -131,8 +131,7 @@ class CloudOutputDeviceManager:
## Connects to an output device and makes sure it is registered in the output device manager. ## Connects to an output device and makes sure it is registered in the output device manager.
def _connectToOutputDevice(self, device: CloudOutputDevice) -> None: def _connectToOutputDevice(self, device: CloudOutputDevice) -> None:
if not device.isConnected(): device.connect()
device.connect()
self._output_device_manager.addOutputDevice(device) self._output_device_manager.addOutputDevice(device)
## Handles an API error received from the cloud. ## Handles an API error received from the cloud.

View file

@ -10,7 +10,7 @@ from .Models.CloudPrintJobResponse import CloudPrintJobResponse
## Class responsible for uploading meshes to the cloud in separate requests. ## Class responsible for uploading meshes to the cloud in separate requests.
class MeshUploader: class ToolPathUploader:
# The maximum amount of times to retry if the server returns one of the RETRY_HTTP_CODES # The maximum amount of times to retry if the server returns one of the RETRY_HTTP_CODES
MAX_RETRIES = 10 MAX_RETRIES = 10

View file

@ -125,5 +125,4 @@ class TestCloudOutputDeviceManager(TestCase):
} }
self.network.prepareReply("GET", self.URL, 200, self.clusters_response) self.network.prepareReply("GET", self.URL, 200, self.clusters_response)
self._loadData() self._loadData()
message_mock.assert_called_once_with(text='Not found!', title='Error', lifetime=10, dismissable=True)
message_mock.return_value.show.assert_called_once_with() message_mock.return_value.show.assert_called_once_with()