chiark / gitweb /
Update the printerconnections for multiple Doodle3D box support.
[cura.git] / Cura / util / printerConnection / dummyConnection.py
1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
2
3 import threading
4 import json
5 import httplib as httpclient
6 import urllib
7 import time
8
9 from Cura.util.printerConnection import printerConnectionBase
10
11 class dummyConnectionGroup(printerConnectionBase.printerConnectionGroup):
12         def __init__(self):
13                 super(dummyConnectionGroup, self).__init__("Dummy")
14                 self._list = [dummyConnection("Dummy 1"), dummyConnection("Dummy 2")]
15
16         def getAvailableConnections(self):
17                 return self._list
18
19 #Dummy printer class which is always
20 class dummyConnection(printerConnectionBase.printerConnectionBase):
21         def __init__(self, name):
22                 super(dummyConnection, self).__init__(name)
23
24                 self._printing = False
25                 self._lineCount = 0
26                 self._progressLine = 0
27
28                 self.printThread = threading.Thread(target=self._dummyThread)
29                 self.printThread.daemon = True
30                 self.printThread.start()
31
32         #Load the file into memory for printing.
33         def loadFile(self, filename):
34                 if self._printing:
35                         return False
36                 self._lineCount = 0
37                 f = open(filename, "r")
38                 for line in f:
39                         #Strip out comments, we do not need to send comments
40                         if ';' in line:
41                                 line = line[:line.index(';')]
42                         #Strip out whitespace at the beginning/end this saves data to send.
43                         line = line.strip()
44
45                         if len(line) < 1:
46                                 continue
47                         self._lineCount += 1
48                 self._doCallback()
49                 return True
50
51         #Start printing the previously loaded file
52         def startPrint(self):
53                 if self._printing or self._lineCount < 1:
54                         return
55                 self._progressLine = 0
56                 self._printing = True
57
58         #Abort the previously loaded print file
59         def cancelPrint(self):
60                 self._printing = False
61
62         def isPrinting(self):
63                 return self._printing
64
65         #Amount of progression of the current print file. 0.0 to 1.0
66         def getPrintProgress(self):
67                 if self._lineCount < 1:
68                         return 0.0
69                 return float(self._progressLine) / float(self._lineCount)
70
71         # Return if the printer with this connection type is available
72         def isAvailable(self):
73                 return True
74
75         # Get the connection status string. This is displayed to the user and can be used to communicate
76         #  various information to the user.
77         def getStatusString(self):
78                 return "DUMMY!\n%i %i\n%i" % (self._progressLine, self._lineCount, self._printing)
79
80         def _dummyThread(self):
81                 while True:
82                         if not self._printing:
83                                 time.sleep(5)
84                                 self._doCallback()
85                         else:
86                                 time.sleep(0.01)
87                                 self._progressLine += 1
88                                 if self._progressLine == self._lineCount:
89                                         self._printing = False
90                                 self._doCallback()