Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d706018

Browse filesBrowse files
authored
Merge pull request #15226 from anntzer/gtk3actions
Turn gtk3 pan/zoom button into togglable buttons.
2 parents 86778dc + 284577f commit d706018
Copy full SHA for d706018

File tree

Expand file treeCollapse file tree

1 file changed

+21
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+21
-2
lines changed

‎lib/matplotlib/backends/backend_gtk3.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_gtk3.py
+21-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.