Continue on exceptions in callback functions

master
kliment 2011-06-28 11:38:55 +02:00
parent ea35ea0e23
commit 26c174402f
1 changed files with 28 additions and 8 deletions

View File

@ -80,25 +80,36 @@ class printcore():
if(len(line)>1): if(len(line)>1):
self.log+=[line] self.log+=[line]
if self.recvcb is not None: if self.recvcb is not None:
self.recvcb(line) try:
self.recvcb(line)
except:
pass
if self.loud: if self.loud:
print "RECV: ",line.rstrip() print "RECV: ",line.rstrip()
if(line.startswith('start') or line.startswith('ok')): if(line.startswith('start') or line.startswith('ok')):
self.clear=True self.clear=True
if(line.startswith('start') or line.startswith('ok') or "T:" in line): if(line.startswith('start') or line.startswith('ok') or "T:" in line):
if (not self.online or line.startswith('start')) and self.onlinecb is not None: if (not self.online or line.startswith('start')) and self.onlinecb is not None:
self.onlinecb() try:
self.onlinecb()
except:
pass
self.online=True self.online=True
if(line.startswith('ok')): if(line.startswith('ok')):
#self.resendfrom=-1 #self.resendfrom=-1
#put temp handling here #put temp handling here
if "T:" in line and self.tempcb is not None: if "T:" in line and self.tempcb is not None:
self.tempcb(line) try:
self.tempcb(line)
except:
pass
#callback for temp, status, whatever #callback for temp, status, whatever
elif(line.startswith('Error')): elif(line.startswith('Error')):
if self.errorcb is not None: if self.errorcb is not None:
self.errorcb(line) try:
self.errorcb(line)
except:
pass
#callback for errors #callback for errors
pass pass
if "resend" in line.lower() or "rs" in line: if "resend" in line.lower() or "rs" in line:
@ -172,11 +183,17 @@ class printcore():
def _print(self): def _print(self):
#callback for printing started #callback for printing started
if self.startcb is not None: if self.startcb is not None:
self.startcb() try:
self.startcb()
except:
pass
while(self.printing and self.printer and self.online): while(self.printing and self.printer and self.online):
self._sendnext() self._sendnext()
if self.endcb is not None: if self.endcb is not None:
self.endcb() try:
self.endcb()
except:
pass
#callback for printing done #callback for printing done
def _sendnext(self): def _sendnext(self):
@ -225,7 +242,10 @@ class printcore():
if self.loud: if self.loud:
print "SENT: ",command print "SENT: ",command
if self.sendcb is not None: if self.sendcb is not None:
self.sendcb(command) try:
self.sendcb(command)
except:
pass
self.printer.write(command+"\n") self.printer.write(command+"\n")
if __name__ == '__main__': if __name__ == '__main__':