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

Skip to content

Commit 8ce6c89

Browse files
committed
Change cursor when hovering over draggable artists
1 parent 0b8bd96 commit 8ce6c89

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

lib/matplotlib/offsetbox.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import matplotlib.path as mpath
3333
import matplotlib.text as mtext
3434
import matplotlib.transforms as mtransforms
35+
from matplotlib.backend_tools import Cursors
3536
from matplotlib.font_manager import FontProperties
3637
from matplotlib.image import BboxImage
3738
from matplotlib.patches import (
@@ -1485,6 +1486,7 @@ def __init__(self, ref_artist, use_blit=False):
14851486
if not ref_artist.pickable():
14861487
ref_artist.set_picker(True)
14871488
self.got_artist = False
1489+
self._hover = False
14881490
self._use_blit = use_blit and self.canvas.supports_blit
14891491
callbacks = ref_artist.figure._canvas_callbacks
14901492
self._disconnectors = [
@@ -1504,7 +1506,31 @@ def __init__(self, ref_artist, use_blit=False):
15041506
disconnect.args[0] for disconnect in self._disconnectors[:2]])
15051507

15061508
def on_motion(self, evt):
1507-
if self._check_still_parented() and self.got_artist:
1509+
# Only check if the widget lock is available, setting it would prevent
1510+
# picking.
1511+
if not (
1512+
self._check_still_parented() and self.canvas.widgetlock.available(self)
1513+
):
1514+
return
1515+
1516+
picker = self.ref_artist.get_picker()
1517+
if callable(picker):
1518+
inside, _ = picker(self, evt)
1519+
else:
1520+
inside, _ = self.ref_artist.contains(evt)
1521+
1522+
# If the mouse is moving quickly while dragging, it may leave the artist,
1523+
# but should still use the move cursor.
1524+
if inside or self.got_artist:
1525+
self._hover = True
1526+
self.canvas.set_cursor(Cursors.MOVE)
1527+
elif self._hover:
1528+
# Only change the cursor back if this is the widget that set it, to
1529+
# avoid multiple draggable widgets fighting over the cursor.
1530+
self._hover = False
1531+
self.canvas.set_cursor(Cursors.POINTER)
1532+
1533+
if self.got_artist:
15081534
dx = evt.x - self.mouse_x
15091535
dy = evt.y - self.mouse_y
15101536
self.update_offset(dx, dy)
@@ -1550,6 +1576,9 @@ def disconnect(self):
15501576
for disconnector in self._disconnectors:
15511577
disconnector()
15521578

1579+
if self._hover:
1580+
self.canvas.set_cursor(Cursors.POINTER)
1581+
15531582
def save_offset(self):
15541583
pass
15551584

0 commit comments

Comments
 (0)