Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0375315

Browse files
authored
Merge pull request#18235 from tacaswell/tk_no_back_button
FIX: check we have a back button in tk toolbar before we touch it
2 parentsefb93ba +f2b870e commit0375315

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

‎lib/matplotlib/backends/_backend_tk.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,15 @@ def save_figure(self, *args):
637637
tkinter.messagebox.showerror("Error saving file",str(e))
638638

639639
defset_history_buttons(self):
640-
ifself._nav_stack._pos>0:
641-
self._buttons['Back']['state']=tk.NORMAL
642-
else:
643-
self._buttons['Back']['state']=tk.DISABLED
644-
ifself._nav_stack._pos<len(self._nav_stack._elements)-1:
645-
self._buttons['Forward']['state']=tk.NORMAL
646-
else:
647-
self._buttons['Forward']['state']=tk.DISABLED
640+
state_map= {True:tk.NORMAL,False:tk.DISABLED}
641+
can_back=self._nav_stack._pos>0
642+
can_forward=self._nav_stack._pos<len(self._nav_stack._elements)-1
643+
644+
if"Back"inself._buttons:
645+
self._buttons['Back']['state']=state_map[can_back]
646+
647+
if"Forward"inself._buttons:
648+
self._buttons['Forward']['state']=state_map[can_forward]
648649

649650

650651
classToolTip:

‎lib/matplotlib/tests/test_backend_tk.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,16 @@ def target():
100100
exceptsubprocess.CalledProcessError:
101101
pytest.fail("Subprocess failed to test intended behavior")
102102
assertproc.stdout.count("success")==1
103+
104+
105+
@pytest.mark.backend('TkAgg',skip_on_importerror=True)
106+
deftest_missing_back_button():
107+
frommatplotlib.backends.backend_tkaggimportNavigationToolbar2Tk
108+
classToolbar(NavigationToolbar2Tk):
109+
# only display the buttons we need
110+
toolitems= [tfortinNavigationToolbar2Tk.toolitemsif
111+
t[0]in ('Home','Pan','Zoom')]
112+
113+
fig=plt.figure()
114+
# this should not raise
115+
Toolbar(fig.canvas,fig.canvas.manager.window)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp