2 Base of all printer connections. A printer connection is a way a connection can be made with a printer.
3 The connections are based on a group, where each group can have 1 or more connections.
5 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
9 class printerConnectionGroup(object):
11 Base for the printer connection group, needs to be subclassed.
12 Has functions for all available connections, getting the name, icon and priority.
14 The getIconID, getPriority and getAvailableConnections functions should be overloaded in a subclass.
16 def __init__(self, name):
19 def getAvailableConnections(self):
28 def getPriority(self):
31 def __cmp__(self, other):
32 return self.getPriority() - other.getPriority()
35 return '%s %d' % (self._name, self.getPriority())
37 class printerConnectionBase(object):
39 Base class for different printer connection implementations.
40 A printer connection can connect to printers in different ways, trough network, USB or carrier pigeons.
41 Each printer connection has different capabilities that you can query with the "has" functions.
42 Each printer connection has a state that you can query with the "is" functions.
43 Each printer connection has callback objects that receive status updates from the printer when information changes.
45 def __init__(self, name):
46 self._callbackList = []
53 #Load the data into memory for printing, returns True on success
54 def loadGCodeData(self, dataStream):
57 #Start printing the previously loaded file
61 #Abort the previously loaded print file
62 def cancelPrint(self):
68 #Amount of progression of the current print file. 0.0 to 1.0
69 def getPrintProgress(self):
72 #Returns true if we need to establish an active connection.
73 # Depending on the type of the connection some types do not need an active connection (Doodle3D WiFi Box for example)
74 def hasActiveConnection(self):
77 #Open the active connection to the printer so we can send commands
78 def openActiveConnection(self):
81 #Close the active connection to the printer
82 def closeActiveConnection(self):
85 #Is the active connection open right now.
86 def isActiveConnectionOpen(self):
89 #Are we trying to open an active connection right now.
90 def isActiveConnectionOpening(self):
93 #Returns true if we have the ability to pause the file printing.
100 #Pause or unpause the printing depending on the value, if supported.
101 def pause(self, value):
104 #Are we able to send a direct coammand with sendCommand at this moment in time.
105 def isAbleToSendDirectCommand(self):
108 #Directly send a command to the printer.
109 def sendCommand(self, command):
112 # Return if the printer with this connection type is available for possible printing right now.
113 # It is used to auto-detect which connection should default to the print button.
114 # This means the printer is detected, but no connection has been made yet.
115 # Example: COM port is detected, but no connection has been made.
116 # Example: WiFi box is detected and is ready to print with a printer connected
117 def isAvailable(self):
120 #Get the temperature of an extruder, returns None is no temperature is known for this extruder
121 def getTemperature(self, extruder):
124 #Get the temperature of the heated bed, returns None is no temperature is known for the heated bed
125 def getBedTemperature(self):
128 # Get the connection status string. This is displayed to the user and can be used to communicate
129 # various information to the user.
130 def getStatusString(self):
133 def addCallback(self, callback):
134 self._callbackList.append(callback)
136 def removeCallback(self, callback):
137 if callback in self._callbackList:
138 self._callbackList.remove(callback)
140 #Returns true if we got some kind of error. The getErrorLog returns all the information to diagnose the problem.
141 def isInErrorState(self):
143 #Returns the error log in case there was an error.
144 def getErrorLog(self):
147 #Run a callback, this can be ran from a different thread, the receivers of the callback need to make sure they are thread safe.
148 def _doCallback(self, param=None):
149 for callback in self._callbackList:
151 callback(self, param)
153 self.removeCallback(callback)
154 traceback.print_exc()