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

Skip to content

Commit 4d97b2c

Browse files
author
Chris Beaumont
committed
Checkable pan/zoom buttons for QT NavigationToolbar
1 parent 0ee82be commit 4d97b2c

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

lib/matplotlib/backends/backend_qt4.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,9 @@ def __init__(self, canvas, parent, coordinates=True):
497497
""" coordinates: should we show the coordinates on the right? """
498498
self.canvas = canvas
499499
self.coordinates = coordinates
500+
self._actions = {}
501+
"""A mapping of toolitem method names to their QActions"""
502+
500503
QtGui.QToolBar.__init__( self, parent )
501504
NavigationToolbar2.__init__( self, canvas )
502505

@@ -512,6 +515,9 @@ def _init_toolbar(self):
512515
else:
513516
a = self.addAction(self._icon(image_file + '.png'),
514517
text, getattr(self, callback))
518+
self._actions[callback] = a
519+
if callback in ['zoom', 'pan']:
520+
a.setCheckable(True)
515521
if tooltip_text is not None:
516522
a.setToolTip(tooltip_text)
517523

@@ -570,6 +576,18 @@ def edit_parameters(self):
570576

571577
figureoptions.figure_edit(axes, self)
572578

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

574592
def dynamic_update( self ):
575593
self.canvas.draw()

0 commit comments

Comments
 (0)