From 8c7dbe1f8664b3c5cc3def7be7b3978d43e2fa21 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Tue, 9 Jun 2020 18:16:22 -0400 Subject: [PATCH] Backport PR #16948: solution: All subclasses of LocationEvent could be used in cbook.callbacks before being fully initialized - issue 15139 --- lib/matplotlib/backend_bases.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 85cf80005981..aa62c309b319 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -1420,7 +1420,6 @@ def __init__(self, name, canvas, x, y, button=None, key=None, (*x*, *y*) in figure coords ((0, 0) = bottom left) button pressed None, 1, 2, 3, 'up', 'down' """ - LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent) if button in MouseButton.__members__.values(): button = MouseButton(button) self.button = button @@ -1428,6 +1427,10 @@ def __init__(self, name, canvas, x, y, button=None, key=None, self.step = step self.dblclick = dblclick + # super-init is deferred to the end because it calls back on + # 'axes_enter_event', which requires a fully initialized event. + LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent) + def __str__(self): return (f"{self.name}: " f"xy=({self.x}, {self.y}) xydata=({self.xdata}, {self.ydata}) " @@ -1512,8 +1515,9 @@ def on_key(event): cid = fig.canvas.mpl_connect('key_press_event', on_key) """ def __init__(self, name, canvas, key, x=0, y=0, guiEvent=None): - LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent) self.key = key + # super-init deferred to the end: callback errors if called before + LocationEvent.__init__(self, name, canvas, x, y, guiEvent=guiEvent) def _get_renderer(figure, print_method, *, draw_disabled=False):