1717
1818import  matplotlib  as  mpl 
1919from  matplotlib  import  docstring 
20- from  . import  _api , cbook , colors , ticker 
20+ from  . import  _api , backend_tools ,  cbook , colors , ticker 
2121from  .lines  import  Line2D 
2222from  .patches  import  Circle , Rectangle , Ellipse 
2323
@@ -2192,8 +2192,26 @@ def _setup_edge_handle(self, props):
21922192                                             useblit = self .useblit )
21932193        self .artists .extend ([line  for  line  in  self ._edge_handles .artists ])
21942194
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+ 
21952212    def  _press (self , event ):
21962213        """Button press event handler.""" 
2214+         self ._set_cursor (True )
21972215        if  self ._interactive  and  self ._rect .get_visible ():
21982216            self ._set_active_handle (event )
21992217        else :
@@ -2248,6 +2266,7 @@ def direction(self, direction):
22482266
22492267    def  _release (self , event ):
22502268        """Button release event handler.""" 
2269+         self ._set_cursor (False )
22512270        if  not  self ._interactive :
22522271            self ._rect .set_visible (False )
22532272
@@ -2264,8 +2283,23 @@ def _release(self, event):
22642283        # self._pressv is deprecated but we still need to maintain it 
22652284        self ._pressv  =  None 
22662285
2286+         self ._active_handle  =  None 
2287+ 
22672288        return  False 
22682289
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+ 
22692303    def  _onmove (self , event ):
22702304        """Motion notify event handler.""" 
22712305
@@ -2805,6 +2839,7 @@ def _release(self, event):
28052839        # call desired function 
28062840        self .onselect (self ._eventpress , self ._eventrelease )
28072841        self .update ()
2842+         self ._active_handle  =  None 
28082843
28092844        return  False 
28102845
0 commit comments