2 ## src/gtkexcepthook.py
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>
8 ## This file is part of Gajim.
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/>.
30 from common
import i18n
# installs _() function
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
)
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()
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
)
66 frame
.set_shadow_type(gtk
.SHADOW_IN
)
68 frame
.set_border_width(6)
69 textbuffer
= textview
.get_buffer()
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'))
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
)
90 dialog
.connect('response', on_dialog_response
)
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