GUI Exception Handler (gtkexcepthook.py
)¶
Graphical exception handler for PyGTK applications
Usage¶
import gtkexcepthook
gtkexcepthook.enable(optional_reporting_callback)
Notes¶
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
value (
BaseException
) –exctyp (
Type
[BaseException
]) –tback (
TracebackType
) –
-
static
make_details_dialog
(parent, text)[source]¶ Initialize and return the details dialog
- Parameters
parent (
Gtk.MessageDialog
) – A reference to the dialog frommake_info_dialog
.text (
str
) – The contents of the formatted traceback.
- Return type
-
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
exctyp (
Type
[BaseException
]) – Used for class name.value (
BaseException
) – Used for exception message.tracebk (
TracebackType
) – Used for everything else.context_lines (
int
) – See thecontext
argument toinspect.getinnerframes
max_width (
int
) – Width to hard word-wrap to.
- Return type
- Returns
The formatted traceback
-
gather_vars
(frame_rec, local_vars)[source]¶ Extract all the local variables from the given traceback frame using
lookup()
.- Parameters
frame_rec (
FrameInfo
) – A frame info object originally retrieved viainspect.getinnerframes
.local_vars (
Dict
[str
,Any
]) – A cached locals dict originally retrieved viainspect.getargvalues
.
- Return type
- 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
name (
str
) – Name of the variable to look up.frame (
FrameType
) – A frame object originally retrieved viainspect.getinnerframes
.local_vars (
Dict
[str
,Any
]) – A cached locals dict originally retrieved viainspect.getargvalues
.
- Return type
- Returns
A tuple of a
Scope
and the requested value.