@@ -1500,16 +1500,23 @@ def __init__(self, ref_artist, use_blit=False):
15001500 ref_artist .set_picker (True )
15011501 self .got_artist = False
15021502 self ._use_blit = use_blit and self .canvas .supports_blit
1503- self .cids = [
1504- self .canvas .callbacks ._connect_picklable (
1505- 'pick_event' , self .on_pick ),
1506- self .canvas .callbacks ._connect_picklable (
1507- 'button_release_event' , self .on_release ),
1503+ callbacks = ref_artist .figure ._canvas_callbacks
1504+ self ._disconnectors = [
1505+ functools .partial (
1506+ callbacks .disconnect , callbacks ._connect_picklable (name , func ))
1507+ for name , func in [
1508+ ("pick_event" , self .on_pick ),
1509+ ("button_release_event" , self .on_release ),
1510+ ("motion_notify_event" , self .on_motion ),
1511+ ]
15081512 ]
15091513
15101514 # A property, not an attribute, to maintain picklability.
15111515 canvas = property (lambda self : self .ref_artist .figure .canvas )
15121516
1517+ cids = property (lambda self : [
1518+ disconnect .args [0 ] for disconnect in self ._disconnectors [:2 ]])
1519+
15131520 def on_motion (self , evt ):
15141521 if self ._check_still_parented () and self .got_artist :
15151522 dx = evt .x - self .mouse_x
@@ -1536,16 +1543,12 @@ def on_pick(self, evt):
15361543 self .ref_artist .draw (
15371544 self .ref_artist .figure ._get_renderer ())
15381545 self .canvas .blit ()
1539- self ._c1 = self .canvas .callbacks ._connect_picklable (
1540- "motion_notify_event" , self .on_motion )
15411546 self .save_offset ()
15421547
15431548 def on_release (self , event ):
15441549 if self ._check_still_parented () and self .got_artist :
15451550 self .finalize_offset ()
15461551 self .got_artist = False
1547- self .canvas .mpl_disconnect (self ._c1 )
1548-
15491552 if self ._use_blit :
15501553 self .ref_artist .set_animated (False )
15511554
@@ -1558,14 +1561,8 @@ def _check_still_parented(self):
15581561
15591562 def disconnect (self ):
15601563 """Disconnect the callbacks."""
1561- for cid in self .cids :
1562- self .canvas .mpl_disconnect (cid )
1563- try :
1564- c1 = self ._c1
1565- except AttributeError :
1566- pass
1567- else :
1568- self .canvas .mpl_disconnect (c1 )
1564+ for disconnector in self ._disconnectors :
1565+ disconnector ()
15691566
15701567 def save_offset (self ):
15711568 pass
0 commit comments