@@ -2011,6 +2011,24 @@ def release_mouse(self, ax):
20112011 if self .mouse_grabber is ax :
20122012 self .mouse_grabber = None
20132013
2014+ def set_cursor (self , cursor ):
2015+ """
2016+ Set the current cursor.
2017+
2018+ This may have no effect if the backend does not display anything.
2019+
2020+ If required by the backend, this method should trigger an update in
2021+ the backend event loop after the cursor is set, as this method may be
2022+ called e.g. before a long-running task during which the GUI is not
2023+ updated.
2024+
2025+ Parameters
2026+ ----------
2027+ cursor : `.Cursors`
2028+ The cursor to dispay over the canvas. Note: some backends may
2029+ change the cursor for the entire window.
2030+ """
2031+
20142032 def draw (self , * args , ** kwargs ):
20152033 """
20162034 Render the `.Figure`.
@@ -2914,7 +2932,7 @@ def __init__(self, canvas):
29142932 canvas .toolbar = self
29152933 self ._nav_stack = cbook .Stack ()
29162934 # This cursor will be set after the initial draw.
2917- self ._lastCursor = cursors .POINTER
2935+ self ._lastCursor = tools . Cursors .POINTER
29182936
29192937 self ._id_press = self .canvas .mpl_connect (
29202938 'button_press_event' , self ._zoom_pan_handler )
@@ -2983,16 +3001,16 @@ def _update_cursor(self, event):
29833001 """
29843002 if self .mode and event .inaxes and event .inaxes .get_navigate ():
29853003 if (self .mode == _Mode .ZOOM
2986- and self ._lastCursor != cursors .SELECT_REGION ):
2987- self .set_cursor (cursors .SELECT_REGION )
2988- self ._lastCursor = cursors .SELECT_REGION
3004+ and self ._lastCursor != tools . Cursors .SELECT_REGION ):
3005+ self .canvas . set_cursor (tools . Cursors .SELECT_REGION )
3006+ self ._lastCursor = tools . Cursors .SELECT_REGION
29893007 elif (self .mode == _Mode .PAN
2990- and self ._lastCursor != cursors .MOVE ):
2991- self .set_cursor (cursors .MOVE )
2992- self ._lastCursor = cursors .MOVE
2993- elif self ._lastCursor != cursors .POINTER :
2994- self .set_cursor (cursors .POINTER )
2995- self ._lastCursor = cursors .POINTER
3008+ and self ._lastCursor != tools . Cursors .MOVE ):
3009+ self .canvas . set_cursor (tools . Cursors .MOVE )
3010+ self ._lastCursor = tools . Cursors .MOVE
3011+ elif self ._lastCursor != tools . Cursors .POINTER :
3012+ self .canvas . set_cursor (tools . Cursors .POINTER )
3013+ self ._lastCursor = tools . Cursors .POINTER
29963014
29973015 @contextmanager
29983016 def _wait_cursor_for_draw_cm (self ):
@@ -3009,10 +3027,10 @@ def _wait_cursor_for_draw_cm(self):
30093027 time .time (), getattr (self , "_draw_time" , - np .inf ))
30103028 if self ._draw_time - last_draw_time > 1 :
30113029 try :
3012- self .set_cursor (cursors .WAIT )
3030+ self .canvas . set_cursor (tools . Cursors .WAIT )
30133031 yield
30143032 finally :
3015- self .set_cursor (self ._lastCursor )
3033+ self .canvas . set_cursor (self ._lastCursor )
30163034 else :
30173035 yield
30183036
0 commit comments