@@ -501,11 +501,15 @@ def _init_toolbar(self):
501
501
image = Gtk .Image ()
502
502
image .set_from_file (
503
503
str (cbook ._get_data_path ('images' , image_file + '.png' )))
504
- self ._gtk_ids [text ] = tbutton = Gtk .ToolButton ()
504
+ self ._gtk_ids [text ] = tbutton = (
505
+ Gtk .ToggleToolButton () if callback in ['zoom' , 'pan' ] else
506
+ Gtk .ToolButton ())
505
507
tbutton .set_label (text )
506
508
tbutton .set_icon_widget (image )
507
509
self .insert (tbutton , - 1 )
508
- tbutton .connect ('clicked' , getattr (self , callback ))
510
+ # Save the handler id, so that we can block it as needed.
511
+ tbutton ._signal_handler = tbutton .connect (
512
+ 'clicked' , getattr (self , callback ))
509
513
tbutton .set_tooltip_text (tooltip_text )
510
514
511
515
toolitem = Gtk .SeparatorToolItem ()
@@ -520,6 +524,21 @@ def _init_toolbar(self):
520
524
521
525
self .show_all ()
522
526
527
+ def _update_buttons_checked (self ):
528
+ for name , active in [("Pan" , "PAN" ), ("Zoom" , "ZOOM" )]:
529
+ button = self ._gtk_ids .get (name )
530
+ if button :
531
+ with button .handler_block (button ._signal_handler ):
532
+ button .set_active (self ._active == active )
533
+
534
+ def pan (self , * args ):
535
+ super ().pan (* args )
536
+ self ._update_buttons_checked ()
537
+
538
+ def zoom (self , * args ):
539
+ super ().zoom (* args )
540
+ self ._update_buttons_checked ()
541
+
523
542
@cbook .deprecated ("3.1" )
524
543
def get_filechooser (self ):
525
544
fc = FileChooserDialog (
0 commit comments