Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Turn gtk3 pan/zoom button into togglable buttons.#15226

Merged
timhoffm merged 1 commit intomatplotlib:masterfrom
anntzer:gtk3actions
Sep 16, 2019
Merged

Turn gtk3 pan/zoom button into togglable buttons.#15226
timhoffm merged 1 commit intomatplotlib:masterfrom
anntzer:gtk3actions

Conversation

@anntzer
Copy link
Copy Markdown
Contributor

@anntzer anntzer commented Sep 8, 2019

... similar to the qt5 ones.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

Comment thread lib/matplotlib/backends/backend_gtk3.py Outdated
super().pan(*args)
self._updating_button_states = True
try:
if "Pan" in self._gtk_ids:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract method similar to _update_buttons_checked() in Qt backend?

Or maybe even better make a private context so that the whole method would be:

def pan(self, *args):
    with self._update_button_states('Pan'):
        super().pan(*args)

Copy link
Copy Markdown
Contributor Author

@anntzer anntzer Sep 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-triggering pan just to update the button state seems... confusing. perhaps @QuLogic knows if there's a gtk3 equivalent of qt's blockSignals? (which is the way this is implemented in qt)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even without, you can still extract a method:

def _update_buttom_states(self, active_tool):
    self._updating_button_states = True
    try:
        for button_id in ['Zoom', 'Pan']:
            if button_id in self._gtk_ids:
                self._gtk_ids[button_id].set_active(
                    button_id.upper() == active_tool == self._active)
    finally:
        self._updating_button_states = False


def pan(self, *args):
    if self._updating_button_states:
        return
    super().pan(*args)
    self._update_buttom_states(active_tool='PAN')


def zoom(self, *args):
    if self._updating_button_states:
        return
    super().zoom(*args)
    self._update_buttom_states(active_tool='ZOOM')

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually I finally found a more reasonable solution...

tbutton.set_icon_widget(image)
self.insert(tbutton, -1)
tbutton.connect('clicked', getattr(self, callback))
tbutton._signal_handler = tbutton.connect(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is _signal_handler an API of GTK or is it just some attibute that you invented to carry the signal handler around. If the latter, that should be documented in a commment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's just our own thing; comment added.

@timhoffm timhoffm added this to the v3.3.0 milestone Sep 16, 2019
@timhoffm timhoffm merged commit d706018 into matplotlib:master Sep 16, 2019
@anntzer anntzer deleted the gtk3actions branch September 16, 2019 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants