chiark / gitweb /
Update the doodle3d class to auto-detect local network boxes, as well as access point...
[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 #Dummy printer class which is always
12 class dummyConnection(printerConnectionBase.printerConnectionBase):
13         def __init__(self):
14                 super(dummyConnection, self).__init__()
15
16                 self._printing = False
17                 self._lineCount = 0
18                 self._progressLine = 0
19
20                 self.printThread = threading.Thread(target=self._dummyThread)
21                 self.printThread.daemon = True
22                 self.printThread.start()
23
24         #Load the file into memory for printing.
25         def loadFile(self, filename):
26                 if self._printing:
27                         return
28                 self._lineCount = 0
29                 f = open(filename, "r")
30                 for line in f:
31                         #Strip out comments, we do not need to send comments
32                         if ';' in line:
33                                 line = line[:line.index(';')]
34                         #Strip out whitespace at the beginning/end this saves data to send.
35                         line = line.strip()
36
37                         if len(line) < 1:
38                                 continue
39                         self._lineCount += 1
40
41         #Start printing the previously loaded file
42         def startPrint(self):
43                 if self._printing or self._lineCount < 1:
44                         return
45                 self._progressLine = 0
46                 self._printing = True
47
48         #Abort the previously loaded print file
49         def cancelPrint(self):
50                 self._printing = False
51
52         def isPrinting(self):
53                 return self._printing
54
55         #Amount of progression of the current print file. 0.0 to 1.0
56         def getPrintProgress(self):
57                 if self._lineCount < 1:
58                         return 0.0
59                 return float(self._progressLine) / float(self._lineCount)
60
61         # Return if the printer with this connection type is available
62         def isAvailable(self):
63                 return True
64
65         # Get the connection status string. This is displayed to the user and can be used to communicate
66         #  various information to the user.
67         def getStatusString(self):
68                 return "DUMMY!"
69
70         def _dummyThread(self):
71                 while True:
72                         if not self._printing:
73                                 time.sleep(5)
74                         else:
75                                 time.sleep(0.01)
76                                 self._progressLine += 1
77                                 if self._progressLine == self._lineCount:
78                                         self._printing = False
79                                 self._doCallback()