chiark / gitweb /
Add progress to the new printerconnectionbase.
authordaid <daid303@gmail.com>
Mon, 25 Nov 2013 15:21:38 +0000 (16:21 +0100)
committerdaid <daid303@gmail.com>
Mon, 25 Nov 2013 15:21:38 +0000 (16:21 +0100)
Cura/util/printerConnection/doodle3dConnect.py
Cura/util/printerConnection/printerConnectionBase.py

index e2f89f53c1488209413e2a12669f2e5d74e925f3..a0eb4353c917b46bf2644358a5f209be65bfa3fe 100644 (file)
@@ -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
index 4de6dd0df6b787d27ee2cc9d5eb19d264af2c09e..9e0a7941c32e44c9b3d5d82e03819eceb807a811 100644 (file)
@@ -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)