@@ -1631,14 +1631,14 @@ def __init__(self, ref_artist, use_blit=False):
1631
1631
self .cids = [c2 , c3 ]
1632
1632
1633
1633
def on_motion (self , evt ):
1634
- if self .got_artist :
1634
+ if self ._check_still_parented () and self . got_artist :
1635
1635
dx = evt .x - self .mouse_x
1636
1636
dy = evt .y - self .mouse_y
1637
1637
self .update_offset (dx , dy )
1638
1638
self .canvas .draw ()
1639
1639
1640
1640
def on_motion_blit (self , evt ):
1641
- if self .got_artist :
1641
+ if self ._check_still_parented () and self . got_artist :
1642
1642
dx = evt .x - self .mouse_x
1643
1643
dy = evt .y - self .mouse_y
1644
1644
self .update_offset (dx , dy )
@@ -1647,7 +1647,7 @@ def on_motion_blit(self, evt):
1647
1647
self .canvas .blit (self .ref_artist .figure .bbox )
1648
1648
1649
1649
def on_pick (self , evt ):
1650
- if evt .artist == self .ref_artist :
1650
+ if self . _check_still_parented () and evt .artist == self .ref_artist :
1651
1651
1652
1652
self .mouse_x = evt .mouseevent .x
1653
1653
self .mouse_y = evt .mouseevent .y
@@ -1668,14 +1668,21 @@ def on_pick(self, evt):
1668
1668
self .save_offset ()
1669
1669
1670
1670
def on_release (self , event ):
1671
- if self .got_artist :
1671
+ if self ._check_still_parented () and self . got_artist :
1672
1672
self .finalize_offset ()
1673
1673
self .got_artist = False
1674
1674
self .canvas .mpl_disconnect (self ._c1 )
1675
1675
1676
1676
if self ._use_blit :
1677
1677
self .ref_artist .set_animated (False )
1678
1678
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
+
1679
1686
def disconnect (self ):
1680
1687
"""disconnect the callbacks"""
1681
1688
for cid in self .cids :
0 commit comments