32
32
import matplotlib .path as mpath
33
33
import matplotlib .text as mtext
34
34
import matplotlib .transforms as mtransforms
35
+ from matplotlib .backend_tools import Cursors
35
36
from matplotlib .font_manager import FontProperties
36
37
from matplotlib .image import BboxImage
37
38
from matplotlib .patches import (
@@ -1489,6 +1490,7 @@ def __init__(self, ref_artist, use_blit=False):
1489
1490
if not ref_artist .pickable ():
1490
1491
ref_artist .set_picker (True )
1491
1492
self .got_artist = False
1493
+ self ._hover = False
1492
1494
self ._use_blit = use_blit and self .canvas .supports_blit
1493
1495
callbacks = ref_artist .figure ._canvas_callbacks
1494
1496
self ._disconnectors = [
@@ -1508,7 +1510,33 @@ def __init__(self, ref_artist, use_blit=False):
1508
1510
disconnect .args [0 ] for disconnect in self ._disconnectors [:2 ]])
1509
1511
1510
1512
def on_motion (self , evt ):
1511
- if self ._check_still_parented () and self .got_artist :
1513
+ # Only check if the widget lock is available, setting it would prevent
1514
+ # picking.
1515
+ if not (
1516
+ self ._check_still_parented ()
1517
+ and self .canvas .widgetlock .available (self )
1518
+ and self .ref_artist .pickable ()
1519
+ ):
1520
+ return
1521
+
1522
+ picker = self .ref_artist .get_picker ()
1523
+ if callable (picker ):
1524
+ inside , _ = picker (self , evt )
1525
+ else :
1526
+ inside , _ = self .ref_artist .contains (evt )
1527
+
1528
+ # If the mouse is moving quickly while dragging, it may leave the artist,
1529
+ # but should still use the move cursor.
1530
+ if inside or self .got_artist :
1531
+ self ._hover = True
1532
+ self .canvas .set_cursor (Cursors .MOVE )
1533
+ elif self ._hover :
1534
+ # Only change the cursor back if this is the widget that set it, to
1535
+ # avoid multiple draggable widgets fighting over the cursor.
1536
+ self ._hover = False
1537
+ self .canvas .set_cursor (Cursors .POINTER )
1538
+
1539
+ if self .got_artist :
1512
1540
dx = evt .x - self .mouse_x
1513
1541
dy = evt .y - self .mouse_y
1514
1542
self .update_offset (dx , dy )
@@ -1554,6 +1582,10 @@ def disconnect(self):
1554
1582
for disconnector in self ._disconnectors :
1555
1583
disconnector ()
1556
1584
1585
+ if self ._hover :
1586
+ self ._hover = False
1587
+ self .canvas .set_cursor (Cursors .POINTER )
1588
+
1557
1589
def save_offset (self ):
1558
1590
pass
1559
1591
0 commit comments