GUI Exception Handler (gtkexcepthook.py)

Graphical exception handler for PyGTK applications

Usage

import gtkexcepthook
gtkexcepthook.enable(optional_reporting_callback)

Notes

©2003 Gustavo J A M Carneiro gjc at inescporto.pt
©2004-2005 Filip Van Raemdonck
©2009, 2011, 2017, 2019 Stephan Sokolow
http://www.daa.com.au/pipermail/pygtk/2003-August/005775.html
Message-ID: <1062087716.1196.5.camel@emperor.homelinux.net>
"The license is whatever you want."

Contains changes merged back from qtexcepthook.py, a Qt 5 port of gtkexcepthook.py by Stephan Sokolow ©2019.

Changes from Van Raemdonck version:
  • Ported to PyGI and GTK 3.x

  • Refactored code for maintainability and added MyPy type annotations

  • Switched from auto-enable to gtkexcepthook.enable to silence PyFlakes false positives. (Borrowed naming convention from cgitb)

  • Split out traceback import to silence PyFlakes warning.

  • Started to resolve PyLint complaints

API Documentation

class ExceptionHandler(reporting_cb=None)[source]

GTK-based graphical exception handler

Parameters

reporting_cb (Optional[Callable[[str], None]]) – A callback to be exposed via a Report… button which will receive the formatted traceback as a string.

__call__(exctyp, value, tback)[source]

Custom sys.excepthook callback which displays a GTK dialog

Parameters
static make_details_dialog(parent, text)[source]

Initialize and return the details dialog

Parameters
Return type

Gtk.MessageDialog

make_info_dialog()[source]

Initialize and return the top-level dialog

Return type

Gtk.MessageDialog

class Scope[source]

The scope of a variable looked up by lookup

Builtin = 1
Global = 2
Local = 3
NONE = None
analyse(exctyp, value, tracebk, context_lines=3, max_width=80)[source]

Generate a traceback, including the contents of variables in each stack frame.

Parameters
Return type

StringIO

Returns

The formatted traceback

enable(reporting_cb=None)[source]

Call this to set gtkexcepthook as the default exception handler

Parameters

reporting_cb (Optional[Callable[[str], None]]) –

If provided, this callback will be exposed in the dialog as a Report… button.

The function will receive the same formatted traceback visible via the Details… button.

gather_vars(frame_rec, local_vars)[source]

Extract all the local variables from the given traceback frame using lookup().

Parameters
Return type

Dict[str, Any]

Returns

A dict of the local variables.

lookup(name, frame, local_vars)[source]

Find the value for a given name in the given frame

Parameters
Return type

Tuple[Scope, Any]

Returns

A tuple of a Scope and the requested value.

tokenize_frame(frame_rec)[source]

Generator which produces a lexical token stream from a frame record

Parameters

frame_rec (FrameInfo) –

Return type

Generator[TokenInfo, None, None]