17
17
18
18
import matplotlib as mpl
19
19
from matplotlib import docstring
20
- from . import _api , cbook , colors , ticker
20
+ from . import _api , backend_tools , cbook , colors , ticker
21
21
from .lines import Line2D
22
22
from .patches import Circle , Rectangle , Ellipse
23
23
@@ -2192,8 +2192,26 @@ def _setup_edge_handle(self, props):
2192
2192
useblit = self .useblit )
2193
2193
self .artists .extend ([line for line in self ._edge_handles .artists ])
2194
2194
2195
+ def _set_cursor (self , enabled ):
2196
+ """Update the canvas cursor based on direction of the selector."""
2197
+ if enabled :
2198
+ cursor = (backend_tools .Cursors .RESIZE_HORIZONTAL
2199
+ if self .direction == 'horizontal' else
2200
+ backend_tools .Cursors .RESIZE_VERTICAL )
2201
+ else :
2202
+ cursor = backend_tools .Cursors .POINTER
2203
+
2204
+ self .ax .figure .canvas .set_cursor (cursor )
2205
+
2206
+ def connect_default_events (self ):
2207
+ # docstring inherited
2208
+ super ().connect_default_events ()
2209
+ if getattr (self , '_interactive' , False ):
2210
+ self .connect_event ('motion_notify_event' , self ._hover )
2211
+
2195
2212
def _press (self , event ):
2196
2213
"""Button press event handler."""
2214
+ self ._set_cursor (True )
2197
2215
if self ._interactive and self ._rect .get_visible ():
2198
2216
self ._set_active_handle (event )
2199
2217
else :
@@ -2248,6 +2266,7 @@ def direction(self, direction):
2248
2266
2249
2267
def _release (self , event ):
2250
2268
"""Button release event handler."""
2269
+ self ._set_cursor (False )
2251
2270
if not self ._interactive :
2252
2271
self ._rect .set_visible (False )
2253
2272
@@ -2268,6 +2287,19 @@ def _release(self, event):
2268
2287
2269
2288
return False
2270
2289
2290
+ def _hover (self , event ):
2291
+ """Update the canvas cursor if it's over a handle."""
2292
+ if self .ignore (event ):
2293
+ return
2294
+
2295
+ if self ._active_handle is not None :
2296
+ # Do nothing if button is pressed and a handle is active, which may
2297
+ # occur with drag_from_anywhere=True.
2298
+ return
2299
+
2300
+ _ , e_dist = self ._edge_handles .closest (event .x , event .y )
2301
+ self ._set_cursor (e_dist <= self .grab_range )
2302
+
2271
2303
def _onmove (self , event ):
2272
2304
"""Motion notify event handler."""
2273
2305
0 commit comments