@@ -2697,11 +2697,9 @@ def __init__(self, canvas):
2697
2697
# This cursor will be set after the initial draw.
2698
2698
self ._lastCursor = cursors .POINTER
2699
2699
self ._init_toolbar ()
2700
- self ._idDrag = self .canvas .mpl_connect (
2700
+ self ._id_drag = self .canvas .mpl_connect (
2701
2701
'motion_notify_event' , self .mouse_move )
2702
-
2703
- self ._ids_zoom = []
2704
- self ._zoom_mode = None
2702
+ self ._id_zoom = None
2705
2703
2706
2704
self ._button_pressed = None # determined by button pressed at start
2707
2705
@@ -2904,23 +2902,22 @@ def press_pan(self, event):
2904
2902
a .get_navigate () and a .can_pan ()):
2905
2903
a .start_pan (x , y , event .button )
2906
2904
self ._xypress .append ((a , i ))
2907
- self .canvas .mpl_disconnect (self ._idDrag )
2908
- self ._idDrag = self .canvas .mpl_connect ('motion_notify_event' ,
2909
- self .drag_pan )
2905
+ self .canvas .mpl_disconnect (self ._id_drag )
2906
+ self ._id_drag = self .canvas .mpl_connect (
2907
+ 'motion_notify_event' , self .drag_pan )
2910
2908
self .press (event )
2911
2909
2912
2910
def press_zoom (self , event ):
2913
2911
"""Callback for mouse button press in zoom to rect mode."""
2914
2912
# If we're already in the middle of a zoom, pressing another
2915
2913
# button works to "cancel"
2916
- if self ._ids_zoom :
2917
- for zoom_id in self ._ids_zoom :
2918
- self .canvas .mpl_disconnect (zoom_id )
2914
+ if self ._id_zoom is not None :
2915
+ self .canvas .mpl_disconnect (self ._id_zoom )
2919
2916
self .release (event )
2920
2917
self .draw ()
2921
2918
self ._xypress = None
2922
2919
self ._button_pressed = None
2923
- self ._ids_zoom = []
2920
+ self ._id_zoom = None
2924
2921
return
2925
2922
2926
2923
if event .button in [1 , 3 ]:
@@ -2935,30 +2932,16 @@ def press_zoom(self, event):
2935
2932
2936
2933
x , y = event .x , event .y
2937
2934
self ._xypress = []
2938
- for i , a in enumerate ( self .canvas .figure .get_axes () ):
2935
+ for a in self .canvas .figure .get_axes ():
2939
2936
if (x is not None and y is not None and a .in_axes (event ) and
2940
2937
a .get_navigate () and a .can_zoom ()):
2941
- self ._xypress .append ((x , y , a , i , a ._get_view ()))
2942
-
2943
- id1 = self .canvas .mpl_connect ('motion_notify_event' , self .drag_zoom )
2944
- id2 = self .canvas .mpl_connect ('key_press_event' ,
2945
- self ._switch_on_zoom_mode )
2946
- id3 = self .canvas .mpl_connect ('key_release_event' ,
2947
- self ._switch_off_zoom_mode )
2938
+ self ._xypress .append ((x , y , a ))
2948
2939
2949
- self ._ids_zoom = id1 , id2 , id3
2950
- self . _zoom_mode = event . key
2940
+ self ._id_zoom = self . canvas . mpl_connect (
2941
+ 'motion_notify_event' , self . drag_zoom )
2951
2942
2952
2943
self .press (event )
2953
2944
2954
- def _switch_on_zoom_mode (self , event ):
2955
- self ._zoom_mode = event .key
2956
- self .mouse_move (event )
2957
-
2958
- def _switch_off_zoom_mode (self , event ):
2959
- self ._zoom_mode = None
2960
- self .mouse_move (event )
2961
-
2962
2945
def push_current (self ):
2963
2946
"""Push the current view limits and position onto the stack."""
2964
2947
self ._nav_stack .push (
@@ -2978,8 +2961,8 @@ def release_pan(self, event):
2978
2961
2979
2962
if self ._button_pressed is None :
2980
2963
return
2981
- self .canvas .mpl_disconnect (self ._idDrag )
2982
- self ._idDrag = self .canvas .mpl_connect (
2964
+ self .canvas .mpl_disconnect (self ._id_drag )
2965
+ self ._id_drag = self .canvas .mpl_connect (
2983
2966
'motion_notify_event' , self .mouse_move )
2984
2967
for a , ind in self ._xypress :
2985
2968
a .end_pan ()
@@ -3003,20 +2986,20 @@ def drag_zoom(self, event):
3003
2986
"""Callback for dragging in zoom mode."""
3004
2987
if self ._xypress :
3005
2988
x , y = event .x , event .y
3006
- lastx , lasty , a , ind , view = self ._xypress [0 ]
2989
+ lastx , lasty , a = self ._xypress [0 ]
3007
2990
(x1 , y1 ), (x2 , y2 ) = np .clip (
3008
2991
[[lastx , lasty ], [x , y ]], a .bbox .min , a .bbox .max )
3009
- if self . _zoom_mode == "x" :
2992
+ if event . key == "x" :
3010
2993
y1 , y2 = a .bbox .intervaly
3011
- elif self . _zoom_mode == "y" :
2994
+ elif event . key == "y" :
3012
2995
x1 , x2 = a .bbox .intervalx
3013
2996
self .draw_rubberband (event , x1 , y1 , x2 , y2 )
3014
2997
3015
2998
def release_zoom (self , event ):
3016
2999
"""Callback for mouse button release in zoom to rect mode."""
3017
- for zoom_id in self ._ids_zoom :
3018
- self .canvas .mpl_disconnect (zoom_id )
3019
- self ._ids_zoom = []
3000
+ if self ._id_zoom is not None :
3001
+ self .canvas .mpl_disconnect (self . _id_zoom )
3002
+ self ._id_zoom = None
3020
3003
3021
3004
self .remove_rubberband ()
3022
3005
@@ -3025,14 +3008,13 @@ def release_zoom(self, event):
3025
3008
3026
3009
last_a = []
3027
3010
3028
- for cur_xypress in self ._xypress :
3011
+ for lastx , lasty , a in self ._xypress :
3029
3012
x , y = event .x , event .y
3030
- lastx , lasty , a , ind , view = cur_xypress
3031
3013
# ignore singular clicks - 5 pixels is a threshold
3032
3014
# allows the user to "cancel" a zoom action
3033
3015
# by zooming by less than 5 pixels
3034
- if ((abs (x - lastx ) < 5 and self . _zoom_mode != "y" ) or
3035
- (abs (y - lasty ) < 5 and self . _zoom_mode != "x" )):
3016
+ if ((abs (x - lastx ) < 5 and event . key != "y" ) or
3017
+ (abs (y - lasty ) < 5 and event . key != "x" )):
3036
3018
self ._xypress = None
3037
3019
self .release (event )
3038
3020
self .draw ()
@@ -3056,14 +3038,12 @@ def release_zoom(self, event):
3056
3038
continue
3057
3039
3058
3040
a ._set_view_from_bbox ((lastx , lasty , x , y ), direction ,
3059
- self . _zoom_mode , twinx , twiny )
3041
+ event . key , twinx , twiny )
3060
3042
3061
3043
self .draw ()
3062
3044
self ._xypress = None
3063
3045
self ._button_pressed = None
3064
3046
3065
- self ._zoom_mode = None
3066
-
3067
3047
self .push_current ()
3068
3048
self .release (event )
3069
3049
0 commit comments