@@ -2697,11 +2697,9 @@ def __init__(self, canvas):
26972697 # This cursor will be set after the initial draw.
26982698 self ._lastCursor = cursors .POINTER
26992699 self ._init_toolbar ()
2700- self ._idDrag = self .canvas .mpl_connect (
2700+ self ._id_drag = self .canvas .mpl_connect (
27012701 'motion_notify_event' , self .mouse_move )
2702-
2703- self ._ids_zoom = []
2704- self ._zoom_mode = None
2702+ self ._id_zoom = None
27052703
27062704 self ._button_pressed = None # determined by button pressed at start
27072705
@@ -2904,23 +2902,22 @@ def press_pan(self, event):
29042902 a .get_navigate () and a .can_pan ()):
29052903 a .start_pan (x , y , event .button )
29062904 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 )
29102908 self .press (event )
29112909
29122910 def press_zoom (self , event ):
29132911 """Callback for mouse button press in zoom to rect mode."""
29142912 # If we're already in the middle of a zoom, pressing another
29152913 # 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 )
29192916 self .release (event )
29202917 self .draw ()
29212918 self ._xypress = None
29222919 self ._button_pressed = None
2923- self ._ids_zoom = []
2920+ self ._id_zoom = None
29242921 return
29252922
29262923 if event .button in [1 , 3 ]:
@@ -2935,30 +2932,16 @@ def press_zoom(self, event):
29352932
29362933 x , y = event .x , event .y
29372934 self ._xypress = []
2938- for i , a in enumerate ( self .canvas .figure .get_axes () ):
2935+ for a in self .canvas .figure .get_axes ():
29392936 if (x is not None and y is not None and a .in_axes (event ) and
29402937 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 ))
29482939
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 )
29512942
29522943 self .press (event )
29532944
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-
29622945 def push_current (self ):
29632946 """Push the current view limits and position onto the stack."""
29642947 self ._nav_stack .push (
@@ -2978,8 +2961,8 @@ def release_pan(self, event):
29782961
29792962 if self ._button_pressed is None :
29802963 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 (
29832966 'motion_notify_event' , self .mouse_move )
29842967 for a , ind in self ._xypress :
29852968 a .end_pan ()
@@ -3003,20 +2986,20 @@ def drag_zoom(self, event):
30032986 """Callback for dragging in zoom mode."""
30042987 if self ._xypress :
30052988 x , y = event .x , event .y
3006- lastx , lasty , a , ind , view = self ._xypress [0 ]
2989+ lastx , lasty , a = self ._xypress [0 ]
30072990 (x1 , y1 ), (x2 , y2 ) = np .clip (
30082991 [[lastx , lasty ], [x , y ]], a .bbox .min , a .bbox .max )
3009- if self . _zoom_mode == "x" :
2992+ if event . key == "x" :
30102993 y1 , y2 = a .bbox .intervaly
3011- elif self . _zoom_mode == "y" :
2994+ elif event . key == "y" :
30122995 x1 , x2 = a .bbox .intervalx
30132996 self .draw_rubberband (event , x1 , y1 , x2 , y2 )
30142997
30152998 def release_zoom (self , event ):
30162999 """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
30203003
30213004 self .remove_rubberband ()
30223005
@@ -3025,14 +3008,13 @@ def release_zoom(self, event):
30253008
30263009 last_a = []
30273010
3028- for cur_xypress in self ._xypress :
3011+ for lastx , lasty , a in self ._xypress :
30293012 x , y = event .x , event .y
3030- lastx , lasty , a , ind , view = cur_xypress
30313013 # ignore singular clicks - 5 pixels is a threshold
30323014 # allows the user to "cancel" a zoom action
30333015 # 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" )):
30363018 self ._xypress = None
30373019 self .release (event )
30383020 self .draw ()
@@ -3056,14 +3038,12 @@ def release_zoom(self, event):
30563038 continue
30573039
30583040 a ._set_view_from_bbox ((lastx , lasty , x , y ), direction ,
3059- self . _zoom_mode , twinx , twiny )
3041+ event . key , twinx , twiny )
30603042
30613043 self .draw ()
30623044 self ._xypress = None
30633045 self ._button_pressed = None
30643046
3065- self ._zoom_mode = None
3066-
30673047 self .push_current ()
30683048 self .release (event )
30693049
0 commit comments