|
14 | 14 | from matplotlib import backend_tools, cbook, _c_internal_utils
|
15 | 15 | from matplotlib.backend_bases import (
|
16 | 16 | _Backend, FigureCanvasBase, FigureManagerBase, NavigationToolbar2,
|
17 |
| - StatusbarBase, TimerBase, ToolContainerBase, cursors) |
| 17 | + StatusbarBase, TimerBase, ToolContainerBase, cursors, _Mode) |
18 | 18 | from matplotlib._pylab_helpers import Gcf
|
19 | 19 | from matplotlib.figure import Figure
|
20 | 20 | from matplotlib.widgets import SubplotTool
|
@@ -544,6 +544,23 @@ def __init__(self, canvas, window, *, pack_toolbar=True):
|
544 | 544 | if pack_toolbar:
|
545 | 545 | self.pack(side=tk.BOTTOM, fill=tk.X)
|
546 | 546 |
|
| 547 | + def _update_buttons_checked(self): |
| 548 | + # sync button checkstates to match active mode |
| 549 | + for text, mode in [('Zoom', _Mode.ZOOM), ('Pan', _Mode.PAN)]: |
| 550 | + if text in self._buttons: |
| 551 | + if self.mode == mode: |
| 552 | + self._buttons[text].select() # NOT .invoke() |
| 553 | + else: |
| 554 | + self._buttons[text].deselect() |
| 555 | + |
| 556 | + def pan(self, *args): |
| 557 | + super().pan(*args) |
| 558 | + self._update_buttons_checked() |
| 559 | + |
| 560 | + def zoom(self, *args): |
| 561 | + super().zoom(*args) |
| 562 | + self._update_buttons_checked() |
| 563 | + |
547 | 564 | def set_message(self, s):
|
548 | 565 | self.message.set(s)
|
549 | 566 |
|
|
0 commit comments