@@ -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`.
@@ -2914,7 +2932,7 @@ def __init__(self, canvas):
2914
2932
canvas .toolbar = self
2915
2933
self ._nav_stack = cbook .Stack ()
2916
2934
# This cursor will be set after the initial draw.
2917
- self ._lastCursor = cursors .POINTER
2935
+ self ._lastCursor = tools . Cursors .POINTER
2918
2936
2919
2937
self ._id_press = self .canvas .mpl_connect (
2920
2938
'button_press_event' , self ._zoom_pan_handler )
@@ -2983,16 +3001,16 @@ def _update_cursor(self, event):
2983
3001
"""
2984
3002
if self .mode and event .inaxes and event .inaxes .get_navigate ():
2985
3003
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
2989
3007
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
2996
3014
2997
3015
@contextmanager
2998
3016
def _wait_cursor_for_draw_cm (self ):
@@ -3009,10 +3027,10 @@ def _wait_cursor_for_draw_cm(self):
3009
3027
time .time (), getattr (self , "_draw_time" , - np .inf ))
3010
3028
if self ._draw_time - last_draw_time > 1 :
3011
3029
try :
3012
- self .set_cursor (cursors .WAIT )
3030
+ self .canvas . set_cursor (tools . Cursors .WAIT )
3013
3031
yield
3014
3032
finally :
3015
- self .set_cursor (self ._lastCursor )
3033
+ self .canvas . set_cursor (self ._lastCursor )
3016
3034
else :
3017
3035
yield
3018
3036
0 commit comments