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

Skip to content

Commit 53f4fb5

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

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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.axes 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)