Skip to content

Commit 12cbd87

Browse files
authored
[3.6] bpo-30290: IDLE - pep8 names and tests for help-about (#2070)
(cherry picked from commit 054e091) * bpo-30290: IDLE: Refactor help_about to PEP8 names (#1714) Patch by Cheryl Sabella. (cherry picked from commit 5a346d5) * IDLE test_help_about: edit and add test. (#1838) Coverage is now 100% (cherry picked from commit eca7da0)
1 parent 361362f commit 12cbd87

File tree

2 files changed

+222
-99
lines changed

2 files changed

+222
-99
lines changed

Lib/idlelib/help_about.py

Lines changed: 121 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
import os
55
from sys import version
66

7-
from tkinter import *
7+
from tkinter import Toplevel, Frame, Label, Button
8+
from tkinter import SUNKEN, TOP, BOTTOM, LEFT, X, BOTH, W, EW, NSEW
89

910
from idlelib import textview
1011

@@ -13,9 +14,13 @@ class AboutDialog(Toplevel):
1314
"""Modal about dialog for idle
1415
1516
"""
16-
def __init__(self, parent, title, _htest=False):
17-
"""
17+
def __init__(self, parent, title, _htest=False, _utest=False):
18+
"""Create popup, do not return until tk widget destroyed.
19+
20+
parent - parent of this dialog
21+
title - string which is title of popup dialog
1822
_htest - bool, change box location when running htest
23+
_utest - bool, don't wait_window when running unittest
1924
"""
2025
Toplevel.__init__(self, parent)
2126
self.configure(borderwidth=5)
@@ -25,125 +30,152 @@ def __init__(self, parent, title, _htest=False):
2530
parent.winfo_rooty()+(30 if not _htest else 100)))
2631
self.bg = "#707070"
2732
self.fg = "#ffffff"
28-
self.CreateWidgets()
29-
self.resizable(height=FALSE, width=FALSE)
33+
self.create_widgets()
34+
self.resizable(height=False, width=False)
3035
self.title(title)
3136
self.transient(parent)
3237
self.grab_set()
33-
self.protocol("WM_DELETE_WINDOW", self.Ok)
38+
self.protocol("WM_DELETE_WINDOW", self.ok)
3439
self.parent = parent
35-
self.buttonOk.focus_set()
36-
self.bind('<Return>',self.Ok) #dismiss dialog
37-
self.bind('<Escape>',self.Ok) #dismiss dialog
38-
self.wait_window()
40+
self.button_ok.focus_set()
41+
self.bind('<Return>', self.ok) # dismiss dialog
42+
self.bind('<Escape>', self.ok) # dismiss dialog
43+
self._current_textview = None
44+
self._utest = _utest
3945

40-
def CreateWidgets(self):
46+
if not _utest:
47+
self.deiconify()
48+
self.wait_window()
49+
50+
def create_widgets(self):
4151
release = version[:version.index(' ')]
42-
frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
43-
frameButtons = Frame(self)
44-
frameButtons.pack(side=BOTTOM, fill=X)
45-
frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
46-
self.buttonOk = Button(frameButtons, text='Close',
47-
command=self.Ok)
48-
self.buttonOk.pack(padx=5, pady=5)
49-
#self.picture = Image('photo', data=self.pictureData)
50-
frameBg = Frame(frameMain, bg=self.bg)
51-
frameBg.pack(expand=TRUE, fill=BOTH)
52-
labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg,
53-
font=('courier', 24, 'bold'))
54-
labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10)
55-
#labelPicture = Label(frameBg, text='[picture]')
56-
#image=self.picture, bg=self.bg)
57-
#labelPicture.grid(row=1, column=1, sticky=W, rowspan=2,
58-
# padx=0, pady=3)
59-
byline = "Python's Integrated DeveLopment Environment" + 5*'\n'
60-
labelDesc = Label(frameBg, text=byline, justify=LEFT,
61-
fg=self.fg, bg=self.bg)
62-
labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
63-
labelEmail = Label(frameBg, text='email: [email protected]',
64-
justify=LEFT, fg=self.fg, bg=self.bg)
65-
labelEmail.grid(row=6, column=0, columnspan=2,
66-
sticky=W, padx=10, pady=0)
67-
labelWWW = Label(frameBg, text='https://docs.python.org/' +
68-
version[:3] + '/library/idle.html',
69-
justify=LEFT, fg=self.fg, bg=self.bg)
70-
labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
71-
Frame(frameBg, borderwidth=1, relief=SUNKEN,
52+
frame = Frame(self, borderwidth=2, relief=SUNKEN)
53+
frame_buttons = Frame(self)
54+
frame_buttons.pack(side=BOTTOM, fill=X)
55+
frame.pack(side=TOP, expand=True, fill=BOTH)
56+
self.button_ok = Button(frame_buttons, text='Close',
57+
command=self.ok)
58+
self.button_ok.pack(padx=5, pady=5)
59+
60+
frame_background = Frame(frame, bg=self.bg)
61+
frame_background.pack(expand=True, fill=BOTH)
62+
63+
header = Label(frame_background, text='IDLE', fg=self.fg,
64+
bg=self.bg, font=('courier', 24, 'bold'))
65+
header.grid(row=0, column=0, sticky=W, padx=10, pady=10)
66+
byline_text = "Python's Integrated DeveLopment Environment" + 5*'\n'
67+
byline = Label(frame_background, text=byline_text, justify=LEFT,
68+
fg=self.fg, bg=self.bg)
69+
byline.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
70+
email = Label(frame_background, text='email: [email protected]',
71+
justify=LEFT, fg=self.fg, bg=self.bg)
72+
email.grid(row=6, column=0, columnspan=2, sticky=W, padx=10, pady=0)
73+
docs = Label(frame_background, text='https://docs.python.org/' +
74+
version[:3] + '/library/idle.html',
75+
justify=LEFT, fg=self.fg, bg=self.bg)
76+
docs.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
77+
78+
Frame(frame_background, borderwidth=1, relief=SUNKEN,
7279
height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
7380
columnspan=3, padx=5, pady=5)
74-
labelPythonVer = Label(frameBg, text='Python version: ' +
75-
release, fg=self.fg, bg=self.bg)
76-
labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0)
77-
tkVer = self.tk.call('info', 'patchlevel')
78-
labelTkVer = Label(frameBg, text='Tk version: '+
79-
tkVer, fg=self.fg, bg=self.bg)
80-
labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
81-
py_button_f = Frame(frameBg, bg=self.bg)
82-
py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW)
83-
buttonLicense = Button(py_button_f, text='License', width=8,
84-
highlightbackground=self.bg,
85-
command=self.ShowLicense)
86-
buttonLicense.pack(side=LEFT, padx=10, pady=10)
87-
buttonCopyright = Button(py_button_f, text='Copyright', width=8,
81+
82+
pyver = Label(frame_background, text='Python version: ' + release,
83+
fg=self.fg, bg=self.bg)
84+
pyver.grid(row=9, column=0, sticky=W, padx=10, pady=0)
85+
tk_patchlevel = self.tk.call('info', 'patchlevel')
86+
tkver = Label(frame_background, text='Tk version: ' + tk_patchlevel,
87+
fg=self.fg, bg=self.bg)
88+
tkver.grid(row=9, column=1, sticky=W, padx=2, pady=0)
89+
py_buttons = Frame(frame_background, bg=self.bg)
90+
py_buttons.grid(row=10, column=0, columnspan=2, sticky=NSEW)
91+
self.py_license = Button(py_buttons, text='License', width=8,
92+
highlightbackground=self.bg,
93+
command=self.show_py_license)
94+
self.py_license.pack(side=LEFT, padx=10, pady=10)
95+
self.py_copyright = Button(py_buttons, text='Copyright', width=8,
96+
highlightbackground=self.bg,
97+
command=self.show_py_copyright)
98+
self.py_copyright.pack(side=LEFT, padx=10, pady=10)
99+
self.py_credits = Button(py_buttons, text='Credits', width=8,
88100
highlightbackground=self.bg,
89-
command=self.ShowCopyright)
90-
buttonCopyright.pack(side=LEFT, padx=10, pady=10)
91-
buttonCredits = Button(py_button_f, text='Credits', width=8,
92-
highlightbackground=self.bg,
93-
command=self.ShowPythonCredits)
94-
buttonCredits.pack(side=LEFT, padx=10, pady=10)
95-
Frame(frameBg, borderwidth=1, relief=SUNKEN,
101+
command=self.show_py_credits)
102+
self.py_credits.pack(side=LEFT, padx=10, pady=10)
103+
104+
Frame(frame_background, borderwidth=1, relief=SUNKEN,
96105
height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
97106
columnspan=3, padx=5, pady=5)
98-
idle_v = Label(frameBg, text='IDLE version: ' + release,
99-
fg=self.fg, bg=self.bg)
100-
idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0)
101-
idle_button_f = Frame(frameBg, bg=self.bg)
102-
idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW)
103-
idle_about_b = Button(idle_button_f, text='README', width=8,
104-
highlightbackground=self.bg,
105-
command=self.ShowIDLEAbout)
106-
idle_about_b.pack(side=LEFT, padx=10, pady=10)
107-
idle_news_b = Button(idle_button_f, text='NEWS', width=8,
108-
highlightbackground=self.bg,
109-
command=self.ShowIDLENEWS)
110-
idle_news_b.pack(side=LEFT, padx=10, pady=10)
111-
idle_credits_b = Button(idle_button_f, text='Credits', width=8,
112-
highlightbackground=self.bg,
113-
command=self.ShowIDLECredits)
114-
idle_credits_b.pack(side=LEFT, padx=10, pady=10)
115107

116-
# License, et all, are of type _sitebuiltins._Printer
117-
def ShowLicense(self):
108+
idlever = Label(frame_background, text='IDLE version: ' + release,
109+
fg=self.fg, bg=self.bg)
110+
idlever.grid(row=12, column=0, sticky=W, padx=10, pady=0)
111+
idle_buttons = Frame(frame_background, bg=self.bg)
112+
idle_buttons.grid(row=13, column=0, columnspan=3, sticky=NSEW)
113+
self.readme = Button(idle_buttons, text='README', width=8,
114+
highlightbackground=self.bg,
115+
command=self.show_readme)
116+
self.readme.pack(side=LEFT, padx=10, pady=10)
117+
self.idle_news = Button(idle_buttons, text='NEWS', width=8,
118+
highlightbackground=self.bg,
119+
command=self.show_idle_news)
120+
self.idle_news.pack(side=LEFT, padx=10, pady=10)
121+
self.idle_credits = Button(idle_buttons, text='Credits', width=8,
122+
highlightbackground=self.bg,
123+
command=self.show_idle_credits)
124+
self.idle_credits.pack(side=LEFT, padx=10, pady=10)
125+
126+
# License, copyright, and credits are of type _sitebuiltins._Printer
127+
def show_py_license(self):
128+
"Handle License button event."
118129
self.display_printer_text('About - License', license)
119130

120-
def ShowCopyright(self):
131+
def show_py_copyright(self):
132+
"Handle Copyright button event."
121133
self.display_printer_text('About - Copyright', copyright)
122134

123-
def ShowPythonCredits(self):
135+
def show_py_credits(self):
136+
"Handle Python Credits button event."
124137
self.display_printer_text('About - Python Credits', credits)
125138

126139
# Encode CREDITS.txt to utf-8 for proper version of Loewis.
127140
# Specify others as ascii until need utf-8, so catch errors.
128-
def ShowIDLECredits(self):
141+
def show_idle_credits(self):
142+
"Handle Idle Credits button event."
129143
self.display_file_text('About - Credits', 'CREDITS.txt', 'utf-8')
130144

131-
def ShowIDLEAbout(self):
145+
def show_readme(self):
146+
"Handle Readme button event."
132147
self.display_file_text('About - Readme', 'README.txt', 'ascii')
133148

134-
def ShowIDLENEWS(self):
149+
def show_idle_news(self):
150+
"Handle News button event."
135151
self.display_file_text('About - NEWS', 'NEWS.txt', 'utf-8')
136152

137153
def display_printer_text(self, title, printer):
154+
"""Create textview for built-in constants.
155+
156+
Built-in constants have type _sitebuiltins._Printer. The
157+
text is extracted from the built-in and then sent to a text
158+
viewer with self as the parent and title as the title of
159+
the popup.
160+
"""
138161
printer._Printer__setup()
139162
text = '\n'.join(printer._Printer__lines)
140-
textview.view_text(self, title, text)
163+
self._current_textview = textview.view_text(
164+
self, title, text, _utest=self._utest)
141165

142166
def display_file_text(self, title, filename, encoding=None):
167+
"""Create textview for filename.
168+
169+
The filename needs to be in the current directory. The path
170+
is sent to a text viewer with self as the parent, title as
171+
the title of the popup, and the file encoding.
172+
"""
143173
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
144-
textview.view_file(self, title, fn, encoding)
174+
self._current_textview = textview.view_file(
175+
self, title, fn, encoding, _utest=self._utest)
145176

146-
def Ok(self, event=None):
177+
def ok(self, event=None):
178+
"Dismiss help_about dialog."
147179
self.destroy()
148180

149181

0 commit comments

Comments
 (0)