1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
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.
11 class printerConnectionBase(object):
13 self._callbackList = []
15 #Load the file into memory for printing, returns True on success
16 def loadFile(self, filename):
19 #Start printing the previously loaded file
23 #Abort the previously loaded print file
24 def cancelPrint(self):
30 #Amount of progression of the current print file. 0.0 to 1.0
31 def getPrintProgress(self):
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):
39 #Open the active connection to the printer so we can send commands
40 def openActiveConnection(self):
43 #Close the active connection to the printer
44 def closeActiveConnection(self):
47 #Is the active connection open right now.
48 def isActiveConnectionOpen(self):
51 #Returns true if we have the ability to pause the file printing.
58 #Pause or unpause the printing depending on the value, if supported.
59 def pause(self, value):
62 #Are we able to send a direct coammand with sendCommand at this moment in time.
63 def isAbleToSendDirectCommand(self):
66 #Directly send a command to the printer.
67 def sendCommand(self, command):
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):
78 #Get the temperature of an extruder, returns None is no temperature is known for this extruder
79 def getTemperature(self, extruder):
82 #Get the temperature of the heated bed, returns None is no temperature is known for the heated bed
83 def getBedTemperature(self):
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):
91 def addCallback(self, callback):
92 self._callbackList.append(callback)
94 def removeCallback(self, callback):
95 if callback in self._callbackList:
96 self._callbackList.remove(callback)
98 #Returns true if we got some kind of error. The getErrorLog returns all the information to diagnose the problem.
99 def isInErrorState(self):
101 #Returns the error log in case there was an error.
102 def getErrorLog(self):
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:
109 callback(self, param)
111 self.removeCallback(callback)
112 traceback.print_exc()