Skip to content

Commit

Permalink
Merge pull request #18240 from QuLogic/auto-backport-of-pr-18235-on-v…
Browse files Browse the repository at this point in the history
…3.3.x

Backport PR #18235 on branch v3.3.x
  • Loading branch information
tacaswell authored Aug 13, 2020
2 parents 4e940b6 + 22ccf4a commit 3a30505
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
17 changes: 9 additions & 8 deletions lib/matplotlib/backends/_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,15 @@ def save_figure(self, *args):
tkinter.messagebox.showerror("Error saving file", str(e))

def set_history_buttons(self):
if self._nav_stack._pos > 0:
self._buttons['Back']['state'] = tk.NORMAL
else:
self._buttons['Back']['state'] = tk.DISABLED
if self._nav_stack._pos < len(self._nav_stack._elements) - 1:
self._buttons['Forward']['state'] = tk.NORMAL
else:
self._buttons['Forward']['state'] = tk.DISABLED
state_map = {True: tk.NORMAL, False: tk.DISABLED}
can_back = self._nav_stack._pos > 0
can_forward = self._nav_stack._pos < len(self._nav_stack._elements) - 1

if "Back" in self._buttons:
self._buttons['Back']['state'] = state_map[can_back]

if "Forward" in self._buttons:
self._buttons['Forward']['state'] = state_map[can_forward]


class ToolTip:
Expand Down
13 changes: 13 additions & 0 deletions lib/matplotlib/tests/test_backend_tk.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ def evil_blit(photoimage, aggimage, offsets, bboxptr):
np.ones((4, 4, 4)),
(0, 1, 2, 3),
bad_boxes)


@pytest.mark.backend('TkAgg', skip_on_importerror=True)
def test_missing_back_button():
from matplotlib.backends.backend_tkagg import NavigationToolbar2Tk
class Toolbar(NavigationToolbar2Tk):
# only display the buttons we need
toolitems = [t for t in NavigationToolbar2Tk.toolitems if
t[0] in ('Home', 'Pan', 'Zoom')]

fig = plt.figure()
# this should not raise
Toolbar(fig.canvas, fig.canvas.manager.window)

0 comments on commit 3a30505

Please sign in to comment.