<s> import time <EOL> import cStringIO <EOL> import traceback <EOL> from pandasqt . compat import QtGui <EOL> import codecs <EOL> import os <EOL> import tempfile <EOL> from easygui . boxes . derived_boxes import msgbox <EOL> def excepthook ( excType , excValue , tracebackobj ) : <EOL> """<STR_LIT>""" <EOL> separator = u'<STR_LIT:->' * <NUM_LIT> <EOL> logFile = os . path . join ( tempfile . gettempdir ( ) , "<STR_LIT>" ) <EOL> notice = """<STR_LIT>""" <EOL> notice += """<STR_LIT>""" . format ( logFile ) <EOL> timeString = time . strftime ( "<STR_LIT>" ) <EOL> tbinfofile = cStringIO . StringIO ( ) <EOL> traceback . print_tb ( tracebackobj , None , tbinfofile ) <EOL> tbinfofile . seek ( <NUM_LIT:0> ) <EOL> tbinfo = tbinfofile . read ( ) <EOL> tbinfo = tbinfo . decode ( '<STR_LIT:utf-8>' ) <EOL> try : <EOL> excValueStr = str ( excValue ) . decode ( '<STR_LIT:utf-8>' ) <EOL> except UnicodeEncodeError , e : <EOL> excValueStr = unicode ( excValue ) <EOL> errmsg = u'<STR_LIT>' . format ( excType , excValueStr ) <EOL> sections = [ u'<STR_LIT:\n>' , separator , timeString , separator , errmsg , separator , tbinfo ] <EOL> msg = u'<STR_LIT:\n>' . join ( sections ) <EOL> try : <EOL> f = codecs . open ( logFile , "<STR_LIT>" , encoding = '<STR_LIT:utf-8>' ) <EOL> f . write ( msg ) <EOL> f . close ( ) <EOL> except IOError , e : <EOL> msgbox ( u"<STR_LIT>" . format ( logFile ) , u"<STR_LIT>" ) <EOL> try : <EOL> if not _isQAppRunning ( ) : <EOL> app = QtGui . QApplication ( [ ] ) <EOL> _showMessageBox ( unicode ( notice ) + unicode ( msg ) ) <EOL> except : <EOL> msgbox ( unicode ( notice ) + unicode ( msg ) , u"<STR_LIT>" ) <EOL> def _isQAppRunning ( ) : <EOL> if QtGui . QApplication . instance ( ) is None : <EOL> return False <EOL> else : <EOL> return True <EOL> def _showMessageBox ( text ) : <EOL> errorbox = QtGui . QMessageBox ( ) <EOL> errorbox . setText ( text ) <EOL> errorbox . exec_ ( ) </s>
