Skip to content

checkable pan/zoom buttons for QT NavigationToolbar #1152

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/matplotlib/backends/backend_qt4.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,9 @@ def __init__(self, canvas, parent, coordinates=True):
""" coordinates: should we show the coordinates on the right? """
self.canvas = canvas
self.coordinates = coordinates
self._actions = {}
Copy link
Member

Choose a reason for hiding this comment

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

It's not immediately clear to a reader what this dictionary represents. A sphinx style docstring would be great here:

self._actions = {}
"""A dictionary mapping action names to button instances...."""

I leave the actual contents of the docstring to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback -- I've amended with a docstring

"""A mapping of toolitem method names to their QActions"""

QtGui.QToolBar.__init__( self, parent )
NavigationToolbar2.__init__( self, canvas )

Expand All @@ -512,6 +515,9 @@ def _init_toolbar(self):
else:
a = self.addAction(self._icon(image_file + '.png'),
text, getattr(self, callback))
self._actions[callback] = a
if callback in ['zoom', 'pan']:
a.setCheckable(True)
if tooltip_text is not None:
a.setToolTip(tooltip_text)

Expand Down Expand Up @@ -570,6 +576,18 @@ def edit_parameters(self):

figureoptions.figure_edit(axes, self)

def _update_buttons_checked(self):
#sync button checkstates to match active mode
self._actions['pan'].setChecked(self._active == 'PAN')
self._actions['zoom'].setChecked(self._active == 'ZOOM')

def pan(self, *args):
super(NavigationToolbar2QT, self).pan(*args)
self._update_buttons_checked()

def zoom(self, *args):
super(NavigationToolbar2QT, self).zoom(*args)
self._update_buttons_checked()

def dynamic_update( self ):
self.canvas.draw()
Expand Down