8000 Release mouse grabs when owning Axes is removed · matplotlib/matplotlib@ad5a98b · GitHub
[go: up one dir, main page]

Skip to content

Commit ad5a98b

Browse files
committed
Release mouse grabs when owning Axes is removed
Otherwise, _nothing_ will remove the grab, and no other Axes can grab the mouse (either raising the `RuntimeError` exception, or in the case of widgets, ignoring mouse events altogether.) Fixes #25345
1 parent 7eafdd8 commit ad5a98b

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

lib/matplotlib/figure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ def _break_share_link(ax, grouper):
931931
self._axobservers.process("_axes_change_event", self)
932932
self.stale = True
933933
self._localaxes.remove(ax)
934+
self.canvas.release_mouse(ax)
934935

935936
# Break link between any shared axes
936937
for name in ax._axis_names:

lib/matplotlib/tests/test_backend_bases.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ def test_non_gui_warning(monkeypatch):
9595
in str(rec[0].message))
9696

9797

98+
def test_grab_clear():
99+
fig, ax = plt.subplots()
100+
101+
fig.canvas.grab_mouse(ax)
102+
assert fig.canvas.mouse_grabber == ax
103+
104+
fig.clear()
105+
assert fig.canvas.mouse_grabber is None
106+
107+
98108
@pytest.mark.parametrize(
99109
"x, y", [(42, 24), (None, 42), (None, None), (200, 100.01), (205.75, 2.0)])
100110
def test_location_event_position(x, y):

0 commit comments

Comments
 (0)
0