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,25 @@ 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
+ self .connect_event ('motion_notify_event' , self ._hover )
2210
+
2195
2211
def _press (self , event ):
2196
2212
"""Button press event handler."""
2213
+ self ._set_cursor (True )
2197
2214
if self ._interactive and self ._rect .get_visible ():
2198
2215
self ._set_active_handle (event )
2199
2216
else :
@@ -2248,6 +2265,7 @@ def direction(self, direction):
2248
2265
2249
2266
def _release (self , event ):
2250
2267
"""Button release event handler."""
2268
+ self ._set_cursor (False )
2251
2269
if not self ._interactive :
2252
2270
self ._rect .set_visible (False )
2253
2271
@@ -2268,6 +2286,18 @@ def _release(self, event):
2268
2286
2269
2287
return False
2270
2288
2289
+ def _hover (self , event ):
2290
+ """Update the canvas cursor if it's over a handle."""
2291
+ if self .ignore (event ):
2292
+ return
2293
+
2294
+ if self ._active_handle is not None :
2295
+ # Do nothing if button is pressed and a handle is active.
2296
+ return
2297
+
2298
+ _ , e_dist = self ._edge_handles .closest (event .x , event .y )
2299
+ self ._set_cursor (e_dist <= self .grab_range )
2300
+
2271
2301
def _onmove (self , event ):
2272
2302
"""Motion notify event handler."""
2273
2303
0 commit comments