@@ -150,6 +150,10 @@ def ignore(self, event):
150
150
# docstring inherited
151
151
return super ().ignore (event ) or self .canvas is None
152
152
153
+ def _set_cursor (self , cursor ):
154
+ """Update the canvas cursor."""
155
+ self .ax .get_figure (root = True ).canvas .set_cursor (cursor )
156
+
153
157
154
158
class Button (AxesWidget ):
155
159
"""
@@ -2643,7 +2647,7 @@ def _handles_artists(self):
2643
2647
else :
2644
2648
return ()
2645
2649
2646
- def _set_cursor (self , enabled ):
2650
+ def _set_span_cursor (self , enabled ):
2647
2651
"""Update the canvas cursor based on direction of the selector."""
2648
2652
if enabled :
2649
2653
cursor = (backend_tools .Cursors .RESIZE_HORIZONTAL
@@ -2652,7 +2656,7 @@ def _set_cursor(self, enabled):
2652
2656
else :
2653
2657
cursor = backend_tools .Cursors .POINTER
2654
2658
2655
- self .ax . get_figure ( root = True ). canvas . set_cursor (cursor )
2659
+ self ._set_cursor (cursor )
2656
2660
2657
2661
def connect_default_events (self ):
2658
2662
# docstring inherited
@@ -2662,7 +2666,7 @@ def connect_default_events(self):
2662
2666
2663
2667
def _press (self , event ):
2664
2668
"""Button press event handler."""
2665
- self ._set_cursor (True )
2669
+ self ._set_span_cursor (True )
2666
2670
if self ._interactive and self ._selection_artist .get_visible ():
2667
2671
self ._set_active_handle (event )
2668
2672
else :
@@ -2712,7 +2716,7 @@ def direction(self, direction):
2712
2716
2713
2717
def _release (self , event ):
2714
2718
"""Button release event handler."""
2715
- self ._set_cursor (False )
2719
+ self ._set_span_cursor (False )
2716
2720
2717
2721
if not self ._interactive :
2718
2722
self ._selection_artist .set_visible (False )
@@ -2754,7 +2758,7 @@ def _hover(self, event):
2754
2758
return
2755
2759
2756
2760
_ , e_dist = self ._edge_handles .closest (event .x , event .y )
2757
- self ._set_cursor (e_dist <= self .grab_range )
2761
+ self ._set_span_cursor (e_dist <= self .grab_range )
2758
2762
2759
2763
def _onmove (self , event ):
2760
2764
"""Motion notify event handler."""
@@ -3278,10 +3282,24 @@ def _press(self, event):
3278
3282
self ._rotation_on_press = self ._rotation
3279
3283
self ._set_aspect_ratio_correction ()
3280
3284
3285
+ match self ._get_action ():
3286
+ case "rotate" :
3287
+ # TODO: set to a rotate cursor if possible?
3288
+ pass
3289
+ case "move" :
3290
+ self ._set_cursor (backend_tools .cursors .MOVE )
3291
+ case "resize" :
3292
+ # TODO: set to a resize cursor if possible?
3293
+ pass
3294
+ case "create" :
3295
+ self ._set_cursor (backend_tools .cursors .SELECT_REGION )
3296
+
3297
+
3281
3298
return False
3282
3299
3283
3300
def _release (self , event ):
3284
3301
"""Button release event handler."""
3302
+ self ._set_cursor (backend_tools .Cursors .POINTER )
3285
3303
if not self ._interactive :
3286
3304
self ._selection_artist .set_visible (False )
3287
3305
@@ -3325,9 +3343,23 @@ def _release(self, event):
3325
3343
self .update ()
3326
3344
self ._active_handle = None
3327
3345
self ._extents_on_press = None
3328
-
3329
3346
return False
3330
3347
3348
+ def _get_action (self ):
3349
+ """
3350
+ Return one of "rotate", "move", "resize", "create"
3351
+ """
3352
+ state = self ._state
3353
+ if 'rotate' in state and self ._active_handle in self ._corner_order :
3354
+ return 'rotate'
3355
+ elif self ._active_handle == 'C' :
3356
+ return 'move'
3357
+ elif self ._active_handle :
3358
+ return 'resize'
3359
+
3360
+ return 'create'
3361
+
3362
+
3331
3363
def _onmove (self , event ):
3332
3364
"""
3333
3365
Motion notify event handler.
@@ -3342,12 +3374,10 @@ def _onmove(self, event):
3342
3374
# The calculations are done for rotation at zero: we apply inverse
3343
3375
# transformation to events except when we rotate and move
3344
3376
state = self ._state
3345
- rotate = 'rotate' in state and self ._active_handle in self ._corner_order
3346
- move = self ._active_handle == 'C'
3347
- resize = self ._active_handle and not move
3377
+ action = self ._get_action ()
3348
3378
3349
3379
xdata , ydata = self ._get_data_coords (event )
3350
- if resize :
3380
+ if action == " resize" :
3351
3381
inv_tr = self ._get_rotation_transform ().inverted ()
3352
3382
xdata , ydata = inv_tr .transform ([xdata , ydata ])
3353
3383
eventpress .xdata , eventpress .ydata = inv_tr .transform (
@@ -3367,7 +3397,7 @@ def _onmove(self, event):
3367
3397
3368
3398
x0 , x1 , y0 , y1 = self ._extents_on_press
3369
3399
# rotate an existing shape
3370
- if rotate :
3400
+ if action == " rotate" :
3371
3401
# calculate angle abc
3372
3402
a = (eventpress .xdata , eventpress .ydata )
3373
3403
b = self .center
@@ -3376,7 +3406,7 @@ def _onmove(self, event):
3376
3406
np .arctan2 (a [1 ]- b [1 ], a [0 ]- b [0 ]))
3377
3407
self .rotation = np .rad2deg (self ._rotation_on_press + angle )
3378
3408
3379
- elif resize :
3409
+ elif action == " resize" :
3380
3410
size_on_press = [x1 - x0 , y1 - y0 ]
3381
3411
center = (x0 + size_on_press [0 ] / 2 , y0 + size_on_press [1 ] / 2 )
3382
3412
@@ -3427,7 +3457,7 @@ def _onmove(self, event):
3427
3457
sign = np .sign (xdata - x0 )
3428
3458
x1 = x0 + sign * abs (y1 - y0 ) * self ._aspect_ratio_correction
3429
3459
3430
- elif move :
3460
+ elif action == " move" :
3431
3461
x0 , x1 , y0 , y1 = self ._extents_on_press
3432
3462
dx = xdata - eventpress .xdata
3433
3463
dy = ydata - eventpress .ydata
0 commit comments