8000 Make draggable callbacks check that artist has not been removed. · matplotlib/matplotlib@d5a39f4 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d5a39f4

Browse files
committed
Make draggable callbacks check that artist has not been removed.
1 parent a9a495e commit d5a39f4

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,8 @@ def finalize_offset(self):
16151615
*update_offset* places the artists simply in display
16161616
coordinates. And *finalize_offset* recalculate their position in
16171617
the normalized axes coordinate and set a relavant attribute.
1618-
16191618
"""
1619+
16201620
def __init__(self, ref_artist, use_blit=False):
16211621
self.ref_artist = ref_artist
16221622
self.got_artist = False
@@ -1631,14 +1631,14 @@ def __init__(self, ref_artist, use_blit=False):
16311631
self.cids = [c2, c3]
16321632

16331633
def on_motion(self, evt):
1634-
if self.got_artist:
1634+
if self._check_still_parented() and self.got_artist:
16351635
dx = evt.x - self.mouse_x
16361636
dy = evt.y - self.mouse_y
16371637
self.update_offset(dx, dy)
16381638
self.canvas.draw()
16391639

16401640
def on_motion_blit(self, evt):
1641-
if self.got_artist:
1641+
if self._check_still_parented() and self.got_artist:
16421642
dx = evt.x - self.mouse_x
16431643
dy = evt.y - self.mouse_y
16441644
self.update_offset(dx, dy)
@@ -1647,7 +1647,7 @@ def on_motion_blit(self, evt):
16471647
self.canvas.blit(self.ref_artist.figure.bbox)
16481648

16491649
def on_pick(self, evt):
1650-
if evt.artist == self.ref_artist:
1650+
if self._check_still_parented() and evt.artist == self.ref_artist:
16511651

16521652
self.mouse_x = evt.mouseevent.x
16531653
self.mouse_y = evt.mouseevent.y
@@ -1668,14 +1668,21 @@ def on_pick(self, evt):
16681668
self.save_offset()
16691669

16701670
def on_release(self, event):
1671-
if self.got_artist:
1671+
if self._check_still_parented() and self.got_artist:
16721672
self.finalize_offset()
16731673
self.got_artist = False
16741674
self.canvas.mpl_disconnect(self._c1)
16751675

16761676
if self._use_blit:
16771677
self.ref_artist.set_animated(False)
16781678

1679+
def _check_still_parented(self):
1680+
if self.ref_artist.figure is None:
1681+
self.disconnect()
1682+
return False
1683+
else:
1684+
return True
1685+
16791686
def disconnect(self):
16801687
"""disconnect the callbacks"""
16811688
for cid in self.cids:

0 commit comments

Comments
 (0)
0