From 081f628c5e78228d46b1f836a816b6b59d5c9bd1 Mon Sep 17 00:00:00 2001 From: daid Date: Mon, 25 Nov 2013 16:21:38 +0100 Subject: [PATCH] Add progress to the new printerconnectionbase. --- Cura/util/printerConnection/doodle3dConnect.py | 9 +++++++++ .../printerConnection/printerConnectionBase.py | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/Cura/util/printerConnection/doodle3dConnect.py b/Cura/util/printerConnection/doodle3dConnect.py index e2f89f53..a0eb4353 100644 --- a/Cura/util/printerConnection/doodle3dConnect.py +++ b/Cura/util/printerConnection/doodle3dConnect.py @@ -38,13 +38,16 @@ class doodle3dConnect(printerConnectionBase.printerConnectionBase): blockSize = 0 f = open(filename, "r") for line in f: + #Strip out comments, we do not need to send comments if ';' in line: line = line[:line.index(';')] + #Strip out whitespace at the beginning/end this saves data to send. line = line.strip() if len(line) < 1: continue self._lineCount += 1 + #Put the lines in 2k sized blocks, so we can send those blocks as http requests. if blockSize + len(line) > 2048: self._fileBlocks.append('\n'.join(block) + '\n') block = [] @@ -72,6 +75,12 @@ class doodle3dConnect(printerConnectionBase.printerConnectionBase): def isPrinting(self): return self._printing + #Amount of progression of the current print file. 0.0 to 1.0 + def printProgress(self): + if self._lineCount < 1: + return 0.0 + return float(d._progressLine) / float(d._lineCount) + # Return if the printer with this connection type is available def isAvailable(self): return self._isAvailable diff --git a/Cura/util/printerConnection/printerConnectionBase.py b/Cura/util/printerConnection/printerConnectionBase.py index 4de6dd0d..9e0a7941 100644 --- a/Cura/util/printerConnection/printerConnectionBase.py +++ b/Cura/util/printerConnection/printerConnectionBase.py @@ -25,6 +25,10 @@ class printerConnectionBase(object): def isPrinting(self): return False + #Amount of progression of the current print file. 0.0 to 1.0 + def printProgress(self): + return 0.0 + #Returns true if we need to establish an active connection. # Depending on the type of the connection some types do not need an active connection (Doodle3D WiFi Box for example) def hasActiveConnection(self): @@ -73,6 +77,14 @@ class printerConnectionBase(object): def getStatusString(self): return "TODO" - def _doCallback(self): + def addCallback(self, callback): + self._callbackList.append(callback) + + def removeCallback(self, callback): + if callback in self._callbackList: + self._callbackList.remove(callback) + + #Run a callback, this can be ran from a different thread. + def _doCallback(self, param=None): for callback in self._callbackList: - callback(self) + callback(self, param) -- 2.30.2