From fd548975ccfd62bb308ed37e8aae83d1a07b42be Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 21 Nov 2017 10:19:17 +0100 Subject: [PATCH] Closing a connection now actually stops the updates CL-541 --- cura/PrinterOutput/NetworkedPrinterOutputDevice.py | 4 +++- cura/PrinterOutputDevice.py | 3 +++ plugins/UM3NetworkPrinting/UM3OutputDevicePlugin.py | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py index 951b7138f1..2c33f2e397 100644 --- a/cura/PrinterOutput/NetworkedPrinterOutputDevice.py +++ b/cura/PrinterOutput/NetworkedPrinterOutputDevice.py @@ -1,7 +1,7 @@ from UM.Application import Application from UM.Logger import Logger -from cura.PrinterOutputDevice import PrinterOutputDevice +from cura.PrinterOutputDevice import PrinterOutputDevice, ConnectionState from PyQt5.QtNetwork import QHttpMultiPart, QHttpPart, QNetworkRequest, QNetworkAccessManager, QNetworkReply from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QTimer, pyqtSignal, QUrl @@ -67,6 +67,8 @@ class NetworkedPrinterOutputDevice(PrinterOutputDevice): def __handleOnFinished(self, reply: QNetworkReply): self._last_response_time = time() + # TODO: Check if the message is actually correct + self.setConnectionState(ConnectionState.connected) try: self._onFinishedCallbacks[reply.url().toString() + str(reply.operation())](reply) except Exception: diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index 573fe63158..f5afb0da6a 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -54,6 +54,9 @@ class PrinterOutputDevice(QObject, OutputDevice): def isConnected(self): return self._connection_state != ConnectionState.closed and self._connection_state != ConnectionState.error + def setConnectionState(self, new_state): + self._connection_state = new_state + def _update(self): pass diff --git a/plugins/UM3NetworkPrinting/UM3OutputDevicePlugin.py b/plugins/UM3NetworkPrinting/UM3OutputDevicePlugin.py index 0d1154e07c..b4ea1663b6 100644 --- a/plugins/UM3NetworkPrinting/UM3OutputDevicePlugin.py +++ b/plugins/UM3NetworkPrinting/UM3OutputDevicePlugin.py @@ -76,8 +76,8 @@ class UM3OutputDevicePlugin(OutputDevicePlugin): else: if self._discovered_devices[key].isConnected(): Logger.log("d", "Attempting to close connection with [%s]" % key) - self._printers[key].close() - self._printers[key].connectionStateChanged.disconnect(self._onDeviceConnectionStateChanged) + self._discovered_devices[key].close() + self._discovered_devices[key].connectionStateChanged.disconnect(self._onDeviceConnectionStateChanged) def _onDeviceConnectionStateChanged(self, key): pass # TODO