@@ -231,6 +231,7 @@ class NavigationToolbar2QT( NavigationToolbar2, qt.QWidget ):
231
231
232
232
def __init__ ( self , parent , canvas ):
233
233
self .canvas = canvas
234
+ self .buttons = {}
234
235
qt .QWidget .__init__ ( self , parent )
235
236
236
237
# Layout toolbar buttons horizontally.
@@ -254,6 +255,8 @@ def _init_toolbar( self ):
254
255
button = qt .QPushButton ( qt .QIconSet ( image ), "" , self )
255
256
qt .QToolTip .add ( button , tooltip_text )
256
257
258
+ self .buttons [ text ] = button
259
+
257
260
# The automatic layout doesn't look that good - it's too close
258
261
# to the images so add a margin around it.
259
262
margin = 4
@@ -263,13 +266,24 @@ def _init_toolbar( self ):
263
266
getattr ( self , callback ) )
264
267
self .layout .addWidget ( button )
265
268
269
+ self .buttons [ 'Pan' ].setToggleButton ( True )
270
+ self .buttons [ 'Zoom' ].setToggleButton ( True )
271
+
266
272
# Add the x,y location widget at the right side of the toolbar
267
273
# The stretch factor is 1 which means any resizing of the toolbar
268
274
# will resize this label instead of the buttons.
269
275
self .locLabel = qt .QLabel ( "" , self )
270
276
self .locLabel .setAlignment ( qt .Qt .AlignRight | qt .Qt .AlignVCenter )
271
277
self .layout .addWidget ( self .locLabel , 1 )
272
278
279
+ def pan ( self , * args ):
280
+ self .buttons [ 'Zoom' ].setOn ( False )
281
+ NavigationToolbar2 .pan ( self , * args )
282
+
283
+ def zoom ( self , * args ):
284
+ self .buttons [ 'Pan' ].setOn ( False )
285
+ NavigationToolbar2 .zoom ( self , * args )
286
+
273
287
def dynamic_update ( self ):
274
288
self .canvas .draw ()
275
289
@@ -297,6 +311,12 @@ def save_figure( self ):
297
311
if fname :
298
312
self .canvas .print_figure ( fname .latin1 () )
299
313
314
+ def set_history_buttons ( self ):
315
+ canBackward = ( self ._views ._pos > 0 )
316
+ canForward = ( self ._views ._pos < len ( self ._views ._elements ) - 1 )
317
+ self .buttons [ 'Back' ].setEnabled ( canBackward )
318
+ self .buttons [ 'Forward' ].setEnabled ( canForward )
319
+
300
320
# set icon used when windows are minimized
301
321
try :
302
322
qt .window_set_default_icon_from_file (
0 commit comments