From 2034aeb5c17e5b624ea41cb3f645ebf5736cae50 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Tue, 19 Apr 2016 12:05:03 +0200 Subject: [PATCH] Progress of a print job is now tracked CURA-49 --- NetworkPrinterOutputDevice.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/NetworkPrinterOutputDevice.py b/NetworkPrinterOutputDevice.py index a385cdf197..5bcbcea9aa 100644 --- a/NetworkPrinterOutputDevice.py +++ b/NetworkPrinterOutputDevice.py @@ -45,9 +45,9 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): Logger.log("d", "Update thread of printer with key %s and ip %s started", self._key, self._address) while self.isConnected(): try: - reply = self._httpGet("printer") - if reply.status_code == 200: - self._json_printer_state = reply.json() + printer_reply = self._httpGet("printer") + if printer_reply.status_code == 200: + self._json_printer_state = printer_reply.json() try: self._spliceJSONData() except: @@ -57,8 +57,16 @@ class NetworkPrinterOutputDevice(PrinterOutputDevice): # First successful response, so we are now "connected" self.setConnectionState(ConnectionState.connected) else: - Logger.log("w", "Got http status code %s while trying to request data.", reply.status_code) + Logger.log("w", "Got http status code %s while trying to request data.", printer_reply.status_code) self.setConnectionState(ConnectionState.error) + + print_job_reply = self._httpGet("print_job") + if print_job_reply.status_code != 404: + self.setProgress(print_job_reply.json()["progress"]) + else: + self.setProgress(0) + + except Exception as e: self.setConnectionState(ConnectionState.error) Logger.log("w", "Exception occured while connecting; %s", str(e))