[kepi] ability to use subkeys. Fixes #6051
[gajim.git] / src / gtkexcepthook.py
blob1b85e93bbc69efe55adede3e6de7e947f8bcccb5
1 # -*- coding:utf-8 -*-
2 ## src/gtkexcepthook.py
3 ##
4 ## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
5 ## Copyright (C) 2005-2010 Yann Leboulanger <asterix AT lagaule.org>
6 ## Copyright (C) 2008 Stephan Erb <steve-e AT h3c.de>
7 ##
8 ## This file is part of Gajim.
9 ##
10 ## Gajim is free software; you can redistribute it and/or modify
11 ## it under the terms of the GNU General Public License as published
12 ## by the Free Software Foundation; version 3 only.
14 ## Gajim is distributed in the hope that it will be useful,
15 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ## GNU General Public License for more details.
19 ## You should have received a copy of the GNU General Public License
20 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
23 import sys
24 import os
25 import traceback
26 import threading
28 import gtk
29 import pango
30 from common import i18n # installs _() function
31 import dialogs
33 from cStringIO import StringIO
34 from common import helpers
36 _exception_in_progress = threading.Lock()
38 def _info(type_, value, tb):
39 if not _exception_in_progress.acquire(False):
40 # Exceptions have piled up, so we use the default exception
41 # handler for such exceptions
42 _excepthook_save(type_, value, tb)
43 return
45 dialog = dialogs.HigDialog(None, gtk.MESSAGE_WARNING, gtk.BUTTONS_NONE,
46 _('A programming error has been detected'),
47 _('It probably is not fatal, but should be reported '
48 'to the developers nonetheless.'))
50 dialog.set_modal(False)
51 #FIXME: add icon to this button
52 RESPONSE_REPORT_BUG = 42
53 dialog.add_buttons(gtk.STOCK_CLOSE, gtk.BUTTONS_CLOSE,
54 _('_Report Bug'), RESPONSE_REPORT_BUG)
55 report_button = dialog.action_area.get_children()[0] # right to left
56 report_button.grab_focus()
58 # Details
59 textview = gtk.TextView()
60 textview.set_editable(False)
61 textview.modify_font(pango.FontDescription('Monospace'))
62 sw = gtk.ScrolledWindow()
63 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
64 sw.add(textview)
65 frame = gtk.Frame()
66 frame.set_shadow_type(gtk.SHADOW_IN)
67 frame.add(sw)
68 frame.set_border_width(6)
69 textbuffer = textview.get_buffer()
70 trace = StringIO()
71 traceback.print_exception(type_, value, tb, None, trace)
72 textbuffer.set_text(trace.getvalue())
73 textview.set_size_request(
74 gtk.gdk.screen_width() / 3,
75 gtk.gdk.screen_height() / 4)
76 expander = gtk.Expander(_('Details'))
77 expander.add(frame)
78 dialog.vbox.add(expander)
80 dialog.set_resizable(True)
81 # on expand the details the dialog remains centered on screen
82 dialog.set_position(gtk.WIN_POS_CENTER_ALWAYS)
84 def on_dialog_response(dialog, response):
85 if response == RESPONSE_REPORT_BUG:
86 url = 'http://trac.gajim.org/wiki/HowToCreateATicket'
87 helpers.launch_browser_mailer('url', url)
88 else:
89 dialog.destroy()
90 dialog.connect('response', on_dialog_response)
91 dialog.show_all()
93 _exception_in_progress.release()
95 # gdb/kdm etc if we use startx this is not True
96 if os.name == 'nt' or not sys.stderr.isatty():
97 #FIXME: maybe always show dialog?
98 _excepthook_save = sys.excepthook
99 sys.excepthook = _info
101 # this is just to assist testing (python gtkexcepthook.py)
102 if __name__ == '__main__':
103 _excepthook_save = sys.excepthook
104 sys.excepthook = _info
105 raise Exception()