@@ -1500,16 +1500,23 @@ def __init__(self, ref_artist, use_blit=False):
1500
1500
ref_artist .set_picker (True )
1501
1501
self .got_artist = False
1502
1502
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
+ ]
1508
1512
]
1509
1513
1510
1514
# A property, not an attribute, to maintain picklability.
1511
1515
c
10000
anvas = property (lambda self : self .ref_artist .figure .canvas )
1512
1516
1517
+ cids = property (lambda self : [
1518
+ disconnect .args [0 ] for disconnect in self ._disconnectors [:2 ]])
1519
+
1513
1520
def on_motion (self , evt ):
1514
1521
if self ._check_still_parented () and self .got_artist :
1515
1522
dx = evt .x - self .mouse_x
@@ -1536,16 +1543,12 @@ def on_pick(self, evt):
1536
1543
self .ref_artist .draw (
1537
1544
self .ref_artist .figure ._get_renderer ())
1538
1545
self .canvas .blit ()
1539
- self ._c1 = self .canvas .callbacks ._connect_picklable (
1540
- "motion_notify_event" , self .on_motion )
1541
1546
self .save_offset ()
1542
1547
1543
1548
def on_release (self , event ):
1544
1549
if self ._check_still_parented () and self .got_artist :
1545
1550
self .finalize_offset ()
1546
1551
self .got_artist = False
1547
- self .canvas .mpl_disconnect (self ._c1 )
1548
-
1549
1552
if self ._use_blit :
1550
1553
self .ref_artist .set_animated (False )
1551
1554
@@ -1558,14 +1561,8 @@ def _check_still_parented(self):
1558
1561
1559
1562
def disconnect (self ):
1560
1563
"""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 ()
1569
1566
1570
1567
def save_offset (self ):
1571
1568
pass
0 commit comments