@@ -2011,6 +2011,24 @@ def release_mouse(self, ax):
2011
2011
if self .mouse_grabber is ax :
2012
2012
self .mouse_grabber = None
2013
2013
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
+
2014
2032
def draw (self , * args , ** kwargs ):
2015
2033
"""
2016
2034
Render the `.Figure`.
@@ -2864,9 +2882,6 @@ class NavigationToolbar2:
2864
2882
:meth:`save_figure`
2865
2883
save the current figure
2866
2884
2867
- :meth:`set_cursor`
2868
- if you want the pointer icon to change
2869
-
2870
2885
:meth:`draw_rubberband` (optional)
2871
2886
draw the zoom to rect "rubberband" rectangle
2872
2887
@@ -2914,7 +2929,7 @@ def __init__(self, canvas):
2914
2929
canvas .toolbar = self
2915
2930
self ._nav_stack = cbook .Stack ()
2916
2931
# This cursor will be set after the initial draw.
2917
- self ._lastCursor = cursors .POINTER
2932
+ self ._lastCursor = tools . Cursors .POINTER
2918
2933
2919
2934
self ._id_press = self .canvas .mpl_connect (
2920
2935
'button_press_event' , self ._zoom_pan_handler )
@@ -2983,16 +2998,16 @@ def _update_cursor(self, event):
2983
2998
"""
2984
2999
if self .mode and event .inaxes and event .inaxes .get_navigate ():
2985
3000
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
2989
3004
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
2996
3011
2997
3012
@contextmanager
2998
3013
def _wait_cursor_for_draw_cm (self ):
@@ -3009,10 +3024,10 @@ def _wait_cursor_for_draw_cm(self):
3009
3024
time .time (), getattr (self , "_draw_time" , - np .inf ))
3010
3025
if self ._draw_time - last_draw_time > 1 :
3011
3026
try :
3012
- self .set_cursor (cursors .WAIT )
3027
+ self .canvas . set_cursor (tools . Cursors .WAIT )
3013
3028
yield
3014
3029
finally :
3015
- self .set_cursor (self ._lastCursor )
3030
+ self .canvas . set_cursor (self ._lastCursor )
3016
3031
else :
3017
3032
yield
3018
3033
@@ -3230,6 +3245,7 @@ def save_figure(self, *args):
3230
3245
"""Save the current figure."""
3231
3246
raise NotImplementedError
3232
3247
3248
+ @_api .deprecated ("3.5" , alternative = "canvas.set_cursor" )
3233
3249
def set_cursor (self , cursor ):
3234
3250
"""
3235
3251
Set the current cursor to one of the :class:`Cursors` enums values.
@@ -3239,6 +3255,7 @@ def set_cursor(self, cursor):
3239
3255
called e.g. before a long-running task during which the GUI is not
3240
3256
updated.
3241
3257
"""
3258
+ self .canvas .set_cursor (cursor )
3242
3259
3243
3260
def update (self ):
3244
3261
"""Reset the axes stack."""
0 commit comments