Skip to content

Commit 5864941

Browse files
committed
Merge pull request matplotlib#1152 from ChrisBeaumont/checkable_navbar
checkable pan/zoom buttons for QT NavigationToolbar
2 parents d2a1346 + 4d97b2c commit 5864941

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/matplotlib/backends/backend_qt4.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,9 @@ def __init__(self, canvas, parent, coordinates=True):
501501
""" coordinates: should we show the coordinates on the right? """
502502
self.canvas = canvas
503503
self.coordinates = coordinates
504+
self._actions = {}
505+
"""A mapping of toolitem method names to their QActions"""
506+
504507
QtGui.QToolBar.__init__( self, parent )
505508
NavigationToolbar2.__init__( self, canvas )
506509

@@ -516,6 +519,9 @@ def _init_toolbar(self):
516519
else:
517520
a = self.addAction(self._icon(image_file + '.png'),
518521
text, getattr(self, callback))
522+
self._actions[callback] = a
523+
if callback in ['zoom', 'pan']:
524+
a.setCheckable(True)
519525
if tooltip_text is not None:
520526
a.setToolTip(tooltip_text)
521527

@@ -574,6 +580,18 @@ def edit_parameters(self):
574580

575581
figureoptions.figure_edit(axes, self)
576582

583+
def _update_buttons_checked(self):
584+
#sync button checkstates to match active mode
585+
self._actions['pan'].setChecked(self._active == 'PAN')
586+
self._actions['zoom'].setChecked(self._active == 'ZOOM')
587+
588+
def pan(self, *args):
589+
super(NavigationToolbar2QT, self).pan(*args)
590+
self._update_buttons_checked()
591+
592+
def zoom(self, *args):
593+
super(NavigationToolbar2QT, self).zoom(*args)
594+
self._update_buttons_checked()
577595

578596
def dynamic_update( self ):
579597
self.canvas.draw()

0 commit comments

Comments
 (0)