chiark / gitweb /
Add printWindow2, the new printerConnection based print window.
[cura.git] / Cura / util / printerConnection / printerConnectionBase.py
1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
2
3 import traceback
4
5 #Base class for different printer connection implementations.
6 # A printer connection can connect to printers in different ways, trough network, USB or carrier pigeons.
7 # Each printer connection has different capabilities that you can query with the "has" functions.
8 # Each printer connection has a state that you can query with the "is" functions.
9 # Each printer connection has callback objects that receive status updates from the printer when information changes.
10
11 class printerConnectionBase(object):
12         def __init__(self):
13                 self._callbackList = []
14
15         #Load the file into memory for printing, returns True on success
16         def loadFile(self, filename):
17                 return False
18
19         #Start printing the previously loaded file
20         def startPrint(self):
21                 pass
22
23         #Abort the previously loaded print file
24         def cancelPrint(self):
25                 pass
26
27         def isPrinting(self):
28                 return False
29
30         #Amount of progression of the current print file. 0.0 to 1.0
31         def getPrintProgress(self):
32                 return 0.0
33
34         #Returns true if we need to establish an active connection.
35         # Depending on the type of the connection some types do not need an active connection (Doodle3D WiFi Box for example)
36         def hasActiveConnection(self):
37                 return False
38
39         #Open the active connection to the printer so we can send commands
40         def openActiveConnection(self):
41                 pass
42
43         #Close the active connection to the printer
44         def closeActiveConnection(self):
45                 pass
46
47         #Is the active connection open right now.
48         def isActiveConnectionOpen(self):
49                 return False
50
51         #Returns true if we have the ability to pause the file printing.
52         def hasPause(self):
53                 return False
54
55         def isPaused(self):
56                 return False
57
58         #Pause or unpause the printing depending on the value, if supported.
59         def pause(self, value):
60                 pass
61
62         #Are we able to send a direct coammand with sendCommand at this moment in time.
63         def isAbleToSendDirectCommand(self):
64                 return False
65
66         #Directly send a command to the printer.
67         def sendCommand(self, command):
68                 pass
69
70         # Return if the printer with this connection type is available for possible printing right now.
71         #  It is used to auto-detect which connection should default to the print button.
72         #  This means the printer is detected, but no connection has been made yet.
73         #  Example: COM port is detected, but no connection has been made.
74         #  Example: WiFi box is detected and is ready to print with a printer connected
75         def isAvailable(self):
76                 return False
77
78         #Get the temperature of an extruder, returns None is no temperature is known for this extruder
79         def getTemperature(self, extruder):
80                 return None
81
82         #Get the temperature of the heated bed, returns None is no temperature is known for the heated bed
83         def getBedTemperature(self):
84                 return None
85
86         # Get the connection status string. This is displayed to the user and can be used to communicate
87         #  various information to the user.
88         def getStatusString(self):
89                 return "TODO"
90
91         def addCallback(self, callback):
92                 self._callbackList.append(callback)
93
94         def removeCallback(self, callback):
95                 if callback in self._callbackList:
96                         self._callbackList.remove(callback)
97
98         #Returns true if we got some kind of error. The getErrorLog returns all the information to diagnose the problem.
99         def isInErrorState(self):
100                 return False
101         #Returns the error log in case there was an error.
102         def getErrorLog(self):
103                 return ""
104
105         #Run a callback, this can be ran from a different thread, the receivers of the callback need to make sure they are thread safe.
106         def _doCallback(self, param=None):
107                 for callback in self._callbackList:
108                         try:
109                                 callback(self, param)
110                         except:
111                                 self.removeCallback(callback)
112                                 traceback.print_exc()