2008-08-15 19:31:51 +02:00
|
|
|
# -*- coding:utf-8 -*-
|
2008-08-15 05:20:23 +02:00
|
|
|
## src/gtkexcepthook.py
|
2005-09-09 22:26:06 +02:00
|
|
|
##
|
2008-08-15 05:20:23 +02:00
|
|
|
## Copyright (C) 2005-2006 Nikos Kouremenos <kourem AT gmail.com>
|
2013-04-05 21:35:39 +02:00
|
|
|
## Copyright (C) 2005-2013 Yann Leboulanger <asterix AT lagaule.org>
|
2008-08-15 19:31:51 +02:00
|
|
|
## Copyright (C) 2008 Stephan Erb <steve-e AT h3c.de>
|
2005-09-09 22:26:06 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## This file is part of Gajim.
|
|
|
|
##
|
|
|
|
## Gajim is free software; you can redistribute it and/or modify
|
2005-09-09 22:26:06 +02:00
|
|
|
## it under the terms of the GNU General Public License as published
|
2007-10-22 13:13:13 +02:00
|
|
|
## by the Free Software Foundation; version 3 only.
|
2005-09-09 22:26:06 +02:00
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## Gajim is distributed in the hope that it will be useful,
|
2005-09-09 22:26:06 +02:00
|
|
|
## but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2008-08-15 05:20:23 +02:00
|
|
|
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2005-09-09 22:26:06 +02:00
|
|
|
## GNU General Public License for more details.
|
|
|
|
##
|
2007-10-22 13:13:13 +02:00
|
|
|
## You should have received a copy of the GNU General Public License
|
2008-08-15 05:20:23 +02:00
|
|
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
2007-10-22 13:13:13 +02:00
|
|
|
##
|
2005-09-09 22:26:06 +02:00
|
|
|
|
2005-09-09 19:09:04 +02:00
|
|
|
import sys
|
2006-05-26 15:26:53 +02:00
|
|
|
import os
|
2005-09-09 19:09:04 +02:00
|
|
|
import traceback
|
2005-09-13 13:11:39 +02:00
|
|
|
import threading
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Gtk
|
2012-12-28 22:00:24 +01:00
|
|
|
from gi.repository import Gdk
|
2012-12-23 16:23:43 +01:00
|
|
|
from gi.repository import Pango
|
2008-12-02 15:44:26 +01:00
|
|
|
from common import i18n # installs _() function
|
2013-01-02 13:54:02 +01:00
|
|
|
from dialogs import HigDialog
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2013-01-02 13:54:02 +01:00
|
|
|
from io import StringIO
|
2005-09-11 15:41:21 +02:00
|
|
|
from common import helpers
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2005-09-13 13:11:39 +02:00
|
|
|
_exception_in_progress = threading.Lock()
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2008-10-11 12:22:04 +02:00
|
|
|
def _info(type_, value, tb):
|
2010-02-08 15:08:40 +01:00
|
|
|
if not _exception_in_progress.acquire(False):
|
|
|
|
# Exceptions have piled up, so we use the default exception
|
|
|
|
# handler for such exceptions
|
|
|
|
_excepthook_save(type_, value, tb)
|
|
|
|
return
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2013-01-02 13:54:02 +01:00
|
|
|
dialog = HigDialog(None, Gtk.MessageType.WARNING, Gtk.ButtonsType.NONE,
|
2010-02-08 15:08:40 +01:00
|
|
|
_('A programming error has been detected'),
|
|
|
|
_('It probably is not fatal, but should be reported '
|
|
|
|
'to the developers nonetheless.'))
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
dialog.set_modal(False)
|
|
|
|
#FIXME: add icon to this button
|
|
|
|
RESPONSE_REPORT_BUG = 42
|
2012-12-23 16:23:43 +01:00
|
|
|
dialog.add_buttons(Gtk.STOCK_CLOSE, Gtk.ButtonsType.CLOSE,
|
2010-02-08 15:08:40 +01:00
|
|
|
_('_Report Bug'), RESPONSE_REPORT_BUG)
|
|
|
|
report_button = dialog.action_area.get_children()[0] # right to left
|
|
|
|
report_button.grab_focus()
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
# Details
|
2012-12-23 16:23:43 +01:00
|
|
|
textview = Gtk.TextView()
|
2010-02-08 15:08:40 +01:00
|
|
|
textview.set_editable(False)
|
2013-07-31 16:40:33 +02:00
|
|
|
textview.override_font(Pango.FontDescription('Monospace'))
|
2012-12-23 16:23:43 +01:00
|
|
|
sw = Gtk.ScrolledWindow()
|
|
|
|
sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
|
2010-02-08 15:08:40 +01:00
|
|
|
sw.add(textview)
|
2012-12-23 16:23:43 +01:00
|
|
|
frame = Gtk.Frame()
|
|
|
|
frame.set_shadow_type(Gtk.ShadowType.IN)
|
2010-02-08 15:08:40 +01:00
|
|
|
frame.add(sw)
|
|
|
|
frame.set_border_width(6)
|
|
|
|
textbuffer = textview.get_buffer()
|
|
|
|
trace = StringIO()
|
|
|
|
traceback.print_exception(type_, value, tb, None, trace)
|
|
|
|
textbuffer.set_text(trace.getvalue())
|
|
|
|
textview.set_size_request(
|
2012-12-23 16:23:43 +01:00
|
|
|
Gdk.Screen.width() / 3,
|
|
|
|
Gdk.Screen.height() / 4)
|
2013-01-20 22:38:23 +01:00
|
|
|
expander = Gtk.Expander(label=_('Details'))
|
2010-02-08 15:08:40 +01:00
|
|
|
expander.add(frame)
|
2013-04-21 10:25:34 +02:00
|
|
|
dialog.vbox.pack_start(expander, True, True, 0)
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
dialog.set_resizable(True)
|
|
|
|
# on expand the details the dialog remains centered on screen
|
2012-12-23 16:23:43 +01:00
|
|
|
dialog.set_position(Gtk.WindowPosition.CENTER_ALWAYS)
|
2005-09-09 19:09:04 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
def on_dialog_response(dialog, response):
|
|
|
|
if response == RESPONSE_REPORT_BUG:
|
|
|
|
url = 'http://trac.gajim.org/wiki/HowToCreateATicket'
|
|
|
|
helpers.launch_browser_mailer('url', url)
|
|
|
|
else:
|
|
|
|
dialog.destroy()
|
|
|
|
dialog.connect('response', on_dialog_response)
|
|
|
|
dialog.show_all()
|
2005-09-11 15:41:21 +02:00
|
|
|
|
2010-02-08 15:08:40 +01:00
|
|
|
_exception_in_progress.release()
|
2008-12-03 22:56:12 +01:00
|
|
|
|
2006-05-26 15:26:53 +02:00
|
|
|
# gdb/kdm etc if we use startx this is not True
|
|
|
|
if os.name == 'nt' or not sys.stderr.isatty():
|
2010-02-08 15:08:40 +01:00
|
|
|
#FIXME: maybe always show dialog?
|
|
|
|
_excepthook_save = sys.excepthook
|
|
|
|
sys.excepthook = _info
|
2005-09-09 19:09:04 +02:00
|
|
|
|
|
|
|
# this is just to assist testing (python gtkexcepthook.py)
|
|
|
|
if __name__ == '__main__':
|
2010-02-08 15:08:40 +01:00
|
|
|
_excepthook_save = sys.excepthook
|
|
|
|
sys.excepthook = _info
|
|
|
|
raise Exception()
|