@@ -2687,9 +2687,7 @@ def __init__(self, canvas):
2687
2687
self ._init_toolbar ()
2688
2688
self ._idDrag = self .canvas .mpl_connect (
2689
2689
'motion_notify_event' , self .mouse_move )
2690
-
2691
- self ._ids_zoom = []
2692
- self ._zoom_mode = None
2690
+ self ._id_zoom = None
2693
2691
2694
2692
self ._button_pressed = None # determined by button pressed at start
2695
2693
@@ -2901,14 +2899,13 @@ def press_zoom(self, event):
2901
2899
"""Callback for mouse button press in zoom to rect mode."""
2902
2900
# If we're already in the middle of a zoom, pressing another
2903
2901
# button works to "cancel"
2904
- if self ._ids_zoom :
2905
- for zoom_id in self ._ids_zoom :
2906
- self .canvas .mpl_disconnect (zoom_id )
2902
+ if self ._id_zoom is not None :
2903
+ self .canvas .mpl_disconnect (self ._id_zoom )
2907
2904
self .release (event )
2908
2905
self .draw ()
2909
2906
self ._xypress = None
2910
2907
self ._button_pressed = None
2911
- self ._ids_zoom = []
2908
+ self ._id_zoom = None
2912
2909
return
2913
2910
2914
2911
if event .button in [1 , 3 ]:
@@ -2923,30 +2920,16 @@ def press_zoom(self, event):
2923
2920
2924
2921
x , y = event .x , event .y
2925
2922
self ._xypress = []
2926
- for i , a in enumerate ( self .canvas .figure .get_axes () ):
2923
+ for a in self .canvas .figure .get_axes ():
2927
2924
if (x is not None and y is not None and a .in_axes (event ) and
2928
2925
a .get_navigate () and a .can_zoom ()):
2929
- self ._xypress .append ((x , y , a , i , a ._get_view ()))
2930
-
2931
- id1 = self .canvas .mpl_connect ('motion_notify_event' , self .drag_zoom )
2932
- id2 = self .canvas .mpl_connect ('key_press_event' ,
2933
- self ._switch_on_zoom_mode )
2934
- id3 = self .canvas .mpl_connect ('key_release_event' ,
2935
- self ._switch_off_zoom_mode )
2926
+ self ._xypress .append ((x , y , a ))
2936
2927
2937
- self ._ids_zoom = id1 , id2 , id3
2938
- self . _zoom_mode = event . key
2928
+ self ._id_zoom = self . canvas . mpl_connect (
2929
+ 'motion_notify_event' , self . drag_zoom )
2939
2930
2940
2931
self .press (event )
2941
2932
2942
- def _switch_on_zoom_mode (self , event ):
2943
- self ._zoom_mode = event .key
2944
- self .mouse_move (event )
2945
-
2946
- def _switch_off_zoom_mode (self , event ):
2947
- self ._zoom_mode = None
2948
- self .mouse_move (event )
2949
-
2950
2933
def push_current (self ):
2951
2934
"""Push the current view limits and position onto the stack."""
2952
2935
self ._nav_stack .push (
@@ -2991,20 +2974,20 @@ def drag_zoom(self, event):
2991
2974
"""Callback for dragging in zoom mode."""
2992
2975
if self ._xypress :
2993
2976
x , y = event .x , event .y
2994
- lastx , lasty , a , ind , view = self ._xypress [0 ]
2977
+ lastx , lasty , a = self ._xypress [0 ]
2995
2978
(x1 , y1 ), (x2 , y2 ) = np .clip (
2996
2979
[[lastx , lasty ], [x , y ]], a .bbox .min , a .bbox .max )
2997
- if self . _zoom_mode == "x" :
2980
+ if event . key == "x" :
2998
2981
y1 , y2 = a .bbox .intervaly
2999
- elif self . _zoom_mode == "y" :
2982
+ elif event . key == "y" :
3000
2983
x1 , x2 = a .bbox .intervalx
3001
2984
self .draw_rubberband (event , x1 , y1 , x2 , y2 )
3002
2985
3003
2986
def release_zoom (self , event ):
3004
2987
"""Callback for mouse button release in zoom to rect mode."""
3005
- for zoom_id in self ._ids_zoom :
3006
- self .canvas .mpl_disconnect (zoom_id )
3007
- self ._ids_zoom = []
2988
+ if self ._id_zoom is not None :
2989
+ self .canvas .mpl_disconnect (self . _id_zoom )
2990
+ self ._id_zoom = None
3008
2991
3009
2992
self .remove_rubberband ()
3010
2993
@@ -3013,14 +2996,13 @@ def release_zoom(self, event):
3013
2996
3014
2997
last_a = []
3015
2998
3016
- for cur_xypress in self ._xypress :
2999
+ for lastx , lasty , a in self ._xypress :
3017
3000
x , y = event .x , event .y
3018
- lastx , lasty , a , ind , view = cur_xypress
3019
3001
# ignore singular clicks - 5 pixels is a threshold
3020
3002
# allows the user to "cancel" a zoom action
3021
3003
# by zooming by less than 5 pixels
3022
- if ((abs (x - lastx ) < 5 and self . _zoom_mode != "y" ) or
3023
- (abs (y - lasty ) < 5 and self . _zoom_mode != "x" )):
3004
+ if ((abs (x - lastx ) < 5 and event . key != "y" ) or
3005
+ (abs (y - lasty ) < 5 and event . key != "x" )):
3024
3006
self ._xypress = None
3025
3007
self .release (event )
3026
3008
self .draw ()
@@ -3044,14 +3026,12 @@ def release_zoom(self, event):
3044
3026
continue
3045
3027
3046
3028
a ._set_view_from_bbox ((lastx , lasty , x , y ), direction ,
3047
- self . _zoom_mode , twinx , twiny )
3029
+ event . key , twinx , twiny )
3048
3030
3049
3031
self .draw ()
3050
3032
self ._xypress = None
3051
3033
self ._button_pressed = None
3052
3034
3053
- self ._zoom_mode = None
3054
-
3055
3035
self .push_current ()
3056
3036
self .release (event )
3057
3037
0 commit comments