def printProgress(self):
if self._lineCount < 1:
return 0.0
- return float(d._progressLine) / float(d._lineCount)
+ return float(self._progressLine) / float(self._lineCount)
# Return if the printer with this connection type is available
def isAvailable(self):
# Get the connection status string. This is displayed to the user and can be used to communicate
# various information to the user.
def getStatusString(self):
+ if not self._isAvailable:
+ return "Doodle3D box not found"
return "TODO"
def _doodle3Dthread(self):
stateReply = self._request('GET', '/d3dapi/printer/state')
if stateReply is None: #No API, wait 15 seconds before looking for Doodle3D again.
self._isAvailable = False
+ self._doCallback()
time.sleep(15)
continue
if not stateReply: #API gave back an error (this can happen if the Doodle3D box is connecting to the printer)
self._isAvailable = False
+ self._doCallback()
time.sleep(5)
continue
- self._isAvailable = True
+ if not self._isAvailable:
+ self._isAvailable = True
+ self._doCallback()
if stateReply['data']['state'] == 'idle':
if self._printing:
--- /dev/null
+__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
+
+import threading
+import json
+import httplib as httpclient
+import urllib
+import time
+
+from Cura.util.printerConnection import printerConnectionBase
+
+#Dummy printer class which is always
+class dummyConnection(printerConnectionBase.printerConnectionBase):
+ def __init__(self):
+ super(dummyConnection, self).__init__()
+
+ self._printing = False
+ self._lineCount = 0
+ self._progressLine = 0
+
+ self.printThread = threading.Thread(target=self._dummyThread)
+ self.printThread.daemon = True
+ self.printThread.start()
+
+ #Load the file into memory for printing.
+ def loadFile(self, filename):
+ if self._printing:
+ return
+ self._lineCount = 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
+
+ #Start printing the previously loaded file
+ def startPrint(self):
+ if self._printing or self._lineCount < 1:
+ return
+ self._progressLine = 0
+ self._printing = True
+
+ #Abort the previously loaded print file
+ def cancelPrint(self):
+ self._printing = False
+
+ 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(self._progressLine) / float(self._lineCount)
+
+ # Return if the printer with this connection type is available
+ def isAvailable(self):
+ return True
+
+ # Get the connection status string. This is displayed to the user and can be used to communicate
+ # various information to the user.
+ def getStatusString(self):
+ return "DUMMY!"
+
+ def _dummyThread(self):
+ while True:
+ if not self._printing:
+ time.sleep(5)
+ else:
+ time.sleep(0.01)
+ self._progressLine += 1
+ if self._progressLine == self._lineCount:
+ self._printing = False
+ self._doCallback()
def sendCommand(self, command):
pass
- # Return if the printer with this connection type is available
+ # Return if the printer with this connection type is available for possible printing right now.
+ # It is used to auto-detect which connection should default to the print button.
# This means the printer is detected, but no connection has been made yet.
# Example: COM port is detected, but no connection has been made.
- # Example: WiFi box is detected
+ # Example: WiFi box is detected and is ready to print with a printer connected
def isAvailable(self):
return False
--- /dev/null
+__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
+
+from Cura.util import version
+from Cura.util.printerConnection import dummyConnection
+from Cura.util.printerConnection import doodle3dConnect
+
+class connectionEntry(object):
+ def __init__(self, name, priority, icon, connection):
+ self.name = name
+ self.priority = priority
+ self.icon = icon
+ self.connection = connection
+
+ def __cmp__(self, other):
+ return self.priority - other.priority
+
+ def __repr__(self):
+ return self.name
+
+class PrinterConnectionManager(object):
+ def __init__(self):
+ self._connectionList = []
+ if version.isDevVersion():
+ self._connectionList.append(connectionEntry('Dummy', -1, 5, dummyConnection.dummyConnection()))
+ self._connectionList.append(connectionEntry('Doodle3D', 100, 27, doodle3dConnect.doodle3dConnect()))
+
+ #Sort the connections by highest priority first.
+ self._connectionList.sort(reverse=True)
+
+ #Return the highest priority available connection.
+ def getAvailableConnection(self):
+ for e in self._connectionList:
+ if e.connection.isAvailable():
+ return e
+ return None