@@ -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`.
@@ -2864,9 +2882,6 @@ class NavigationToolbar2:
28642882 :meth:`save_figure`
28652883 save the current figure
28662884
2867- :meth:`set_cursor`
2868- if you want the pointer icon to change
2869-
28702885 :meth:`draw_rubberband` (optional)
28712886 draw the zoom to rect "rubberband" rectangle
28722887
@@ -2914,7 +2929,7 @@ def __init__(self, canvas):
29142929 canvas .toolbar = self
29152930 self ._nav_stack = cbook .Stack ()
29162931 # This cursor will be set after the initial draw.
2917- self ._lastCursor = cursors .POINTER
2932+ self ._lastCursor = tools . Cursors .POINTER
29182933
29192934 self ._id_press = self .canvas .mpl_connect (
29202935 'button_press_event' , self ._zoom_pan_handler )
@@ -2983,16 +2998,16 @@ def _update_cursor(self, event):
29832998 """
29842999 if self .mode and event .inaxes and event .inaxes .get_navigate ():
29853000 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
3001+ and self ._lastCursor != tools . Cursors .SELECT_REGION ):
3002+ self .canvas . set_cursor (tools . Cursors .SELECT_REGION )
3003+ self ._lastCursor = tools . Cursors .SELECT_REGION
29893004 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
3005+ and self ._lastCursor != tools . Cursors .MOVE ):
3006+ self .canvas . set_cursor (tools . Cursors .MOVE )
3007+ self ._lastCursor = tools . Cursors .MOVE
3008+ elif self ._lastCursor != tools . Cursors .POINTER :
3009+ self .canvas . set_cursor (tools . Cursors .POINTER )
3010+ self ._lastCursor = tools . Cursors .POINTER
29963011
29973012 @contextmanager
29983013 def _wait_cursor_for_draw_cm (self ):
@@ -3009,10 +3024,10 @@ def _wait_cursor_for_draw_cm(self):
30093024 time .time (), getattr (self , "_draw_time" , - np .inf ))
30103025 if self ._draw_time - last_draw_time > 1 :
30113026 try :
3012- self .set_cursor (cursors .WAIT )
3027+ self .canvas . set_cursor (tools . Cursors .WAIT )
30133028 yield
30143029 finally :
3015- self .set_cursor (self ._lastCursor )
3030+ self .canvas . set_cursor (self ._lastCursor )
30163031 else :
30173032 yield
30183033
@@ -3230,6 +3245,7 @@ def save_figure(self, *args):
32303245 """Save the current figure."""
32313246 raise NotImplementedError
32323247
3248+ @_api .deprecated ("3.5" , alternative = "canvas.set_cursor" )
32333249 def set_cursor (self , cursor ):
32343250 """
32353251 Set the current cursor to one of the :class:`Cursors` enums values.
@@ -3239,6 +3255,7 @@ def set_cursor(self, cursor):
32393255 called e.g. before a long-running task during which the GUI is not
32403256 updated.
32413257 """
3258+ self .canvas .set_cursor (cursor )
32423259
32433260 def update (self ):
32443261 """Reset the axes stack."""
0 commit comments