Add parameters to terminate() that specify an (optional) error message to display on termination.

This commit is contained in:
Daniel Burrows 2006-12-01 11:54:12 +01:00
parent 0483beb3b8
commit 0ee7dfd435
3 changed files with 20 additions and 3 deletions

View File

@ -525,9 +525,14 @@ class Blinkenlights(BlinkenBase, UIBase):
finally: finally:
s.c.unlock() s.c.unlock()
def terminate(s, exitstatus = 0): def terminate(s, exitstatus = 0, errortitle = None, errormsg = None):
s.c.stop() s.c.stop()
UIBase.terminate(s, exitstatus) if errormsg <> None:
if errortitle <> None:
sys.stderr.write('%s: %s\n'%(errortitle, errormsg))
else:
sys.stderr.write('%s\n' % errormsg)
UIBase.terminate(s, exitstatus = exitstatus, errortitle = errortitle, errormsg = errormsg)
def threadException(s, thread): def threadException(s, thread):
s.c.stop() s.c.stop()

View File

@ -247,6 +247,13 @@ class VerboseUI(UIBase):
tf.destroy() tf.destroy()
s.tflock.release() s.tflock.release()
def terminate(s, exitstatus = 0, errortitle = None, errormsg = None):
if errormsg <> None:
if errortitle == None:
errortitle = "Error"
TextOKDialog(errortitle, errormsg)
UIBase.terminate(s, exitstatus = exitstatus, errortitle = None, errormsg = None)
def threadException(s, thread): def threadException(s, thread):
exceptionstr = s.getThreadExceptionString(thread) exceptionstr = s.getThreadExceptionString(thread)
print exceptionstr print exceptionstr

View File

@ -301,8 +301,13 @@ class UIBase:
def mainException(s): def mainException(s):
s._msg(s.getMainExceptionString()) s._msg(s.getMainExceptionString())
def terminate(s, exitstatus = 0): def terminate(s, exitstatus = 0, errortitle = None, errormsg = None):
"""Called to terminate the application.""" """Called to terminate the application."""
if errormsg <> None:
if errortitle <> None:
sys.stderr.write('ERROR: %s\n\n%s\n'%(errortitle, errormsg))
else:
sys.stderr.write('%s\n' % errormsg)
sys.exit(exitstatus) sys.exit(exitstatus)
def threadExited(s, thread): def threadExited(s, thread):