Skip to content

Commit 284577f

Browse files
committed
Turn gtk3 pan/zoom button into togglable buttons.
... similar to the qt5 ones.
1 parent 2aba5aa commit 284577f

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

lib/matplotlib/backends/backend_gtk3.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,11 +501,15 @@ def _init_toolbar(self):
501501
image = Gtk.Image()
502502
image.set_from_file(
503503
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())
505507
tbutton.set_label(text)
506508
tbutton.set_icon_widget(image)
507509
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))
509513
tbutton.set_tooltip_text(tooltip_text)
510514

511515
toolitem = Gtk.SeparatorToolItem()
@@ -520,6 +524,21 @@ def _init_toolbar(self):
520524

521525
self.show_all()
522526

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+
523542
@cbook.deprecated("3.1")
524543
def get_filechooser(self):
525544
fc = FileChooserDialog(

0 commit comments

Comments
 (0)