On Thursday 22 March 2007 16:47, Luper Rouch wrote: > Hi, > > What is the proper way to add a global exceptions catcher to a > QApplication, for example to bring a bug report dialog when an exception > reaches the main event loop ? > I guess I have to make my own event loop but my attempts failed > miserably, any pointers to an example ? > I just asked this question not long ago.
You can set sys.excepthook to a function that creates a dialog window. from http://svn.berlios.de/viewcvs/dosbox-pykde/trunk/lib/dboxpykde/kdelib/base.py?rev=76&view=markup ------------------------ import traceback from StringIO import StringIO separator = '-' * 80 def excepthook(type, value, tracebackobj): tbinfofile = StringIO() traceback.print_tb(tracebackobj, None, tbinfofile) tbinfofile.seek(0) tbinfo = tbinfofile.read() errmsg = '%s: %s' % (str(type), str(value)) sections = [separator, errmsg, separator] msg = '\n'.join(sections) KMessageBox.detailedError(None, msg, tbinfo) -------------- and in the main script - I do the override just before creating the application instance. ------------------ KCmdLineArgs.init(sys.argv, aboutData) sys.excepthook = excepthook #raise StandardError, 'testing an error' # setup application app = MainApplication() ------------------- you could uncomment the raise statement above to do test the excepthook out. I just recently started using the detailedError box and it looks pretty nice. I hope this helps. :) > Thanks, > Luper Rouch > > > _______________________________________________ > PyQt mailing list [email protected] > http://www.riverbankcomputing.com/mailman/listinfo/pyqt -- Joseph Rawson
pgpeCN2U1AiCw.pgp
Description: PGP signature
_______________________________________________ PyQt mailing list [email protected] http://www.riverbankcomputing.com/mailman/listinfo/pyqt
