Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3e382c

Browse files
committed
API: pass a handler to all of the CallbackRegistry instances
This handler prints the traceback, rather than letting an exception raised by the callback propagate. This is required because not all GUI frameworks gracefully handle exception raised in mouse/keyboard event callbacks (Qt5 exits the process on un-handled exceptions).
1 parent 9e9b82a commit a3e382c

File tree

7 files changed

+18
-9
lines changed

7 files changed

+18
-9
lines changed

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,8 @@ def cla(self):
971971
spine.cla()
972972

973973
self.ignore_existing_data_limits = True
974-
self.callbacks = cbook.CallbackRegistry()
974+
self.callbacks = cbook.CallbackRegistry(
975+
exception_handler=cbook.exception_printer)
975976

976977
if self._sharex is not None:
977978
# major and minor are class instances with

lib/matplotlib/axis.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,8 @@ def __init__(self, axes, pickradius=15):
638638
self.axes = axes
639639
self.major = Ticker()
640640
self.minor = Ticker()
641-
self.callbacks = cbook.CallbackRegistry()
641+
self.callbacks = cbook.CallbackRegistry(
642+
exception_handler=cbook.exception_printer)
642643

643644
self._autolabelpos = True
644645
self._smart_bounds = False
@@ -739,7 +740,8 @@ def cla(self):
739740
self.isDefault_label = True
740741

741742
# Clear the callback registry for this axis, or it may "leak"
742-
self.callbacks = cbook.CallbackRegistry()
743+
self.callbacks = cbook.CallbackRegistry(
744+
exception_handler=cbook.exception_printer)
743745

744746
# whether the grids are on
745747
self._gridOnMajor = (rcParams['axes.grid'] and

lib/matplotlib/backend_bases.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1784,7 +1784,8 @@ def __init__(self, figure):
17841784
figure.set_canvas(self)
17851785
self.figure = figure
17861786
# a dictionary from event name to a dictionary that maps cid->func
1787-
self.callbacks = cbook.CallbackRegistry()
1787+
self.callbacks = cbook.CallbackRegistry(
1788+
exception_handler=cbook.exception_printer)
17881789
self.widgetlock = widgets.LockDraw()
17891790
self._button = None # the button pressed
17901791
self._key = None # the key pressed

lib/matplotlib/backend_managers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ def __init__(self, figure=None):
6666
self._tools = {}
6767
self._keys = {}
6868
self._toggled = {}
69-
self._callbacks = cbook.CallbackRegistry()
69+
self._callbacks = cbook.CallbackRegistry(
70+
exception_handler=cbook.exception_printer)
7071

7172
# to process keypress event
7273
self.keypresslock = widgets.LockDraw()

lib/matplotlib/cm.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,8 @@ def __init__(self, norm=None, cmap=None):
190190
The colormap used to map normalized data values to RGBA colors.
191191
"""
192192

193-
self.callbacksSM = cbook.CallbackRegistry()
193+
self.callbacksSM = cbook.CallbackRegistry(
194+
exception_handler=cbook.exception_printer)
194195

195196
if cmap is None:
196197
cmap = get_cmap()

lib/matplotlib/figure.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ def __init__(self,
319319
# this is used by the property methods in the artist base class
320320
# which are over-ridden in this class
321321
del self._axes
322-
self.callbacks = cbook.CallbackRegistry()
322+
self.callbacks = cbook.CallbackRegistry(
323+
exception_handler=cbook.exception_printer)
323324

324325
if figsize is None:
325326
figsize = rcParams['figure.figsize']
@@ -1231,7 +1232,8 @@ def clf(self, keep_observers=False):
12311232
a gui widget is tracking the axes in the figure.
12321233
"""
12331234
self.suppressComposite = None
1234-
self.callbacks = cbook.CallbackRegistry()
1235+
self.callbacks = cbook.CallbackRegistry(
1236+
exception_handler=cbook.exception_printer)
12351237

12361238
for ax in tuple(self.axes): # Iterate over the copy.
12371239
ax.cla()

lib/mpl_toolkits/gtktools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,8 @@ def __init__(self, r, formatd=None, stringd=None):
382382
formatd = mlab.get_formatd(r)
383383

384384
self.stringd = stringd
385-
self.callbacks = cbook.CallbackRegistry()
385+
self.callbacks = cbook.CallbackRegistry(
386+
exception_handler=cbook.exception_printer)
386387

387388
self.r = r
388389

0 commit comments

Comments
 (0)