8000 Move emission of axes_enter/leave_event to a separate handler. · matplotlib/matplotlib@e26189b · GitHub
[go: up one dir, main page]

Skip to content

Commit e26189b

Browse files
anntzertacaswell
authored andcommitted
Move emission of axes_enter/leave_event to a separate handler.
1 parent 4e21912 commit e26189b

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

lib/matplotlib/backend_bases.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,22 +1344,6 @@ def __init__(self, name, canvas, x, y, guiEvent=None):
13441344
self.xdata = xdata
13451345
self.ydata = ydata
13461346

1347-
def _process(self):
1348-
last = LocationEvent.lastevent
1349-
last_axes = last.inaxes if last is not None else None
1350-
if last_axes != self.inaxes:
1351-
if last_axes is not None:
1352-
try:
1353-
last.c 10000 anvas.callbacks.process("axes_leave_event", last)
1354-
except Exception:
1355-
# The last canvas may already have been torn down.
1356-
pass
1357-
if self.inaxes is not None:
1358-
self.canvas.callbacks.process("axes_enter_event", self)
1359-
LocationEvent.lastevent = (
1360-
None if self.name == "figure_leave_event" else self)
1361-
super()._process()
1362-
13631347

13641348
class MouseButton(IntEnum):
13651349
LEFT = 1
@@ -1549,6 +1533,22 @@ def _process(self):
15491533
super()._process()
15501534

15511535

1536+
def _axes_enter_leave_emitter(event):
1537+
last = LocationEvent.lastevent
1538+
last_axes = last.inaxes if last is not None else None
1539+
if last_axes != event.inaxes:
1540+
if last_axes is not None:
1541+
try:
1542+
last.canvas.callbacks.process("axes_leave_event", last)
1543+
except Exception:
1544+
# The last canvas may already have been torn down.
1545+
pass
1546+
if event.inaxes is not None:
1547+
event.canvas.callbacks.process("axes_enter_event", event)
1548+
LocationEvent.lastevent = (
1549+
None if event.name == "figure_leave_event" else event)
1550+
1551+
15521552
def _get_renderer(figure, print_method=None):
15531553
"""
15541554
Get the renderer that would be used to save a `.Figure`, and cache it on

lib/matplotlib/figure.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import numpy as np
2424

2525
import matplotlib as mpl
26-
from matplotlib import _blocking_input, _docstring, projections
26+
from matplotlib import _blocking_input, backend_bases, _docstring, projections
2727
from matplotlib.artist import (
2828
Artist, allow_rasterization, _finalize_rasterization)
2929
from matplotlib.backend_bases import (
@@ -2376,6 +2376,8 @@ def __init__(self,
23762376
'button_press_event', self.pick)
23772377
self._scroll_pick_id = self._canvas_callbacks._connect_picklable(
23782378
'scroll_event', self.pick)
2379+
self._axes_enter_leave_id = self._canvas_callbacks.connect(
2380+
'motion_notify_event', backend_bases._axes_enter_leave_emitter)
23792381

23802382
if figsize is None:
23812383
figsize = mpl.rcParams['figure.figsize']

0 commit comments

Comments
 (0)
0