| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | import sys |
|---|
| 19 | import os |
|---|
| 20 | import traceback |
|---|
| 21 | import threading |
|---|
| 22 | |
|---|
| 23 | import gtk |
|---|
| 24 | import pango |
|---|
| 25 | from common import i18n |
|---|
| 26 | import dialogs |
|---|
| 27 | |
|---|
| 28 | from cStringIO import StringIO |
|---|
| 29 | from common import helpers |
|---|
| 30 | |
|---|
| 31 | _exception_in_progress = threading.Lock() |
|---|
| 32 | |
|---|
| 33 | def _info(type, value, tb): |
|---|
| 34 | if not _exception_in_progress.acquire(False): |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | _excepthook_save(type, value, tb) |
|---|
| 38 | return |
|---|
| 39 | |
|---|
| 40 | dialog = dialogs.HigDialog(None, gtk.MESSAGE_WARNING, gtk.BUTTONS_NONE, |
|---|
| 41 | _('A programming error has been detected'), |
|---|
| 42 | _('It probably is not fatal, but should be reported ' |
|---|
| 43 | 'to the developers nonetheless.')) |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | RESPONSE_REPORT_BUG = 42 |
|---|
| 47 | dialog.add_buttons(gtk.STOCK_CLOSE, gtk.BUTTONS_CLOSE, |
|---|
| 48 | _('_Report Bug'), RESPONSE_REPORT_BUG) |
|---|
| 49 | dialog.set_default_response(RESPONSE_REPORT_BUG) |
|---|
| 50 | report_button = dialog.action_area.get_children()[0] |
|---|
| 51 | report_button.grab_focus() |
|---|
| 52 | |
|---|
| 53 | |
|---|
| 54 | textview = gtk.TextView() |
|---|
| 55 | textview.set_editable(False) |
|---|
| 56 | textview.modify_font(pango.FontDescription('Monospace')) |
|---|
| 57 | sw = gtk.ScrolledWindow() |
|---|
| 58 | sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|---|
| 59 | sw.add(textview) |
|---|
| 60 | frame = gtk.Frame() |
|---|
| 61 | frame.set_shadow_type(gtk.SHADOW_IN) |
|---|
| 62 | frame.add(sw) |
|---|
| 63 | frame.set_border_width(6) |
|---|
| 64 | textbuffer = textview.get_buffer() |
|---|
| 65 | trace = StringIO() |
|---|
| 66 | traceback.print_exception(type, value, tb, None, trace) |
|---|
| 67 | textbuffer.set_text(trace.getvalue()) |
|---|
| 68 | textview.set_size_request( |
|---|
| 69 | gtk.gdk.screen_width() / 3, |
|---|
| 70 | gtk.gdk.screen_height() / 4) |
|---|
| 71 | expander = gtk.Expander(_('Details')) |
|---|
| 72 | expander.add(frame) |
|---|
| 73 | dialog.vbox.add(expander) |
|---|
| 74 | |
|---|
| 75 | dialog.set_resizable(True) |
|---|
| 76 | |
|---|
| 77 | dialog.set_position(gtk.WIN_POS_CENTER_ALWAYS) |
|---|
| 78 | |
|---|
| 79 | dialog.show_all() |
|---|
| 80 | |
|---|
| 81 | close_clicked = False |
|---|
| 82 | while not close_clicked: |
|---|
| 83 | resp = dialog.run() |
|---|
| 84 | if resp == RESPONSE_REPORT_BUG: |
|---|
| 85 | url = 'http://trac.gajim.org/wiki/WikiStart#howto_report_ticket' |
|---|
| 86 | helpers.launch_browser_mailer('url', url) |
|---|
| 87 | else: |
|---|
| 88 | close_clicked = True |
|---|
| 89 | |
|---|
| 90 | dialog.destroy() |
|---|
| 91 | |
|---|
| 92 | _exception_in_progress.release() |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | if os.name == 'nt' or not sys.stderr.isatty(): |
|---|
| 96 | |
|---|
| 97 | _excepthook_save = sys.excepthook |
|---|
| 98 | sys.excepthook = _info |
|---|
| 99 | |
|---|
| 100 | |
|---|
| 101 | if __name__ == '__main__': |
|---|
| 102 | _excepthook_save = sys.excepthook |
|---|
| 103 | sys.excepthook = _info |
|---|
| 104 | print x |
|---|