10000 bpo-30290: IDLE: Refactor help_about to PEP8 names (#1714) · python/cpython@5a346d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5a346d5

Browse files
csabellaterryjreedy
authored andcommitted
bpo-30290: IDLE: Refactor help_about to PEP8 names (#1714)
Patch by Cheryl Sabella.
1 parent c0364fc commit 5a346d5

File tree

2 files changed

+119
-95
lines changed

2 files changed

+119
-95
lines changed

Lib/idlelib/help_about.py

Lines changed: 110 additions & 86 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

@@ -14,7 +15,10 @@ class AboutDialog(Toplevel):
1415
1516
"""
1617
def __init__(self, parent, title, _htest=False, _utest=False):
17-
"""
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
1923
_utest - bool, don't wait_window when running unittest
2024
"""
@@ -26,132 +30,152 @@ def __init__(self, parent, title, _htest=False, _utest=False):
2630
parent.winfo_rooty()+(30 if not _htest else 100)))
2731
self.bg = "#707070"
2832
self.fg = "#ffffff"
29-
self.CreateWidgets()
30-
self.resizable(height=FALSE, width=FALSE)
33+
self.create_widgets()
34+
self.resizable(height=False, width=False)
3135
self.title(title)
3236
self.transient(parent)
3337
self.grab_set()
34-
self.protocol("WM_DELETE_WINDOW", self.Ok)
38+
self.protocol("WM_DELETE_WINDOW", self.ok)
3539
self.parent = parent
36-
self.buttonOk.focus_set()
37-
self.bind('<Return>',self.Ok) #dismiss dialog
38-
self.bind('<Escape>',self.Ok) #dismiss dialog
40+
self.button_ok.focus_set()
41+
self.bind('<Return>', self.ok) # dismiss dialog
42+
self.bind('<Escape>', self.ok) # dismiss dialog
3943
self._current_textview = None
4044
self._utest = _utest
4145

4246
if not _utest:
4347
self.deiconify()
4448
self.wait_window()
4549

46-
def CreateWidgets(self):
50+
def create_widgets(self):
4751
release = version[:version.index(' ')]
48-
frameMain = Frame(self, borderwidth=2, relief=SUNKEN)
49-
frameButtons = Frame(self)
50-
frameButtons.pack(side=BOTTOM, fill=X)
51-
frameMain.pack(side=TOP, expand=TRUE, fill=BOTH)
52-
self.buttonOk = Button(frameButtons, text='Close',
53-
command=self.Ok)
54-
self.buttonOk.pack(padx=5, pady=5)
55-
#self.picture = Image('photo', data=self.pictureData)
56-
frameBg = Frame(frameMain, bg=self.bg)
57-
frameBg.pack(expand=TRUE, fill=BOTH)
58-
labelTitle = Label(frameBg, text='IDLE', fg=self.fg, bg=self.bg,
59-
font=('courier', 24, 'bold'))
60-
labelTitle.grid(row=0, column=0, sticky=W, padx=10, pady=10)
61-
#labelPicture = Label(frameBg, text='[picture]')
62-
#image=self.picture, bg=self.bg)
63-
#labelPicture.grid(row=1, column=1, sticky=W, rowspan=2,
64-
# padx=0, pady=3)
65-
byline = "Python's Integrated DeveLopment Environment" + 5*'\n'
66-
labelDesc = Label(frameBg, text=byline, justify=LEFT,
67-
fg=self.fg, bg=self.bg)
68-
labelDesc.grid(row=2, column=0, sticky=W, columnspan=3, padx=10, pady=5)
69-
labelEmail = Label(frameBg, text='email: idle-dev@python.org',
70-
justify=LEFT, fg=self.fg, bg=self.bg)
71-
labelEmail.grid(row=6, column=0, columnspan=2,
72-
sticky=W, padx=10, pady=0)
73-
labelWWW = Label(frameBg, text='https://docs.python.org/' +
74-
version[:3] + '/library/idle.html',
75-
justify=LEFT, fg=self.fg, bg=self.bg)
76-
labelWWW.grid(row=7, column=0, columnspan=2, sticky=W, padx=10, pady=0)
77-
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: idle-dev@python.org',
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,
7879
height=2, bg=self.bg).grid(row=8, column=0, sticky=EW,
7980
columnspan=3, padx=5, pady=5)
80-
labelPythonVer = Label(frameBg, text='Python version: ' +
81-
release, fg=self.fg, bg=self.bg)
82-
labelPythonVer.grid(row=9, column=0, sticky=W, padx=10, pady=0)
83-
tkVer = self.tk.call('info', 'patchlevel')
84-
labelTkVer = Label(frameBg, text='Tk version: '+
85-
tkVer, fg=self.fg, bg=self.bg)
86-
labelTkVer.grid(row=9, column=1, sticky=W, padx=2, pady=0)
87-
py_button_f = Frame(frameBg, bg=self.bg)
88-
py_button_f.grid(row=10, column=0, columnspan=2, sticky=NSEW)
89-
self.buttonLicense = Button(py_button_f, text='License', width=8,
90-
highlightbackground=self.bg,
91-
command=self.ShowLicense)
92-
self.buttonLicense.pack(side=LEFT, padx=10, pady=10)
93-
self.buttonCopyright = Button(py_button_f, text='Copyright', width=8,
94-
highlightbackground=self.bg,
95-
command=self.ShowCopyright)
96-
self.buttonCopyright.pack(side=LEFT, padx=10, pady=10)
97-
self.buttonCredits = Button(py_button_f, text='Credits', width=8,
98-
highlightbackground=self.bg,
99-
command=self.ShowPythonCredits)
100-
self.buttonCredits.pack(side=LEFT, padx=10, pady=10)
101-
Frame(frameBg, borderwidth=1, relief=SUNKEN,
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,
100+
highlightbackground=self.bg,
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,
102105
height=2, bg=self.bg).grid(row=11, column=0, sticky=EW,
103106
columnspan=3, padx=5, pady=5)
104-
idle_v = Label(frameBg, text='IDLE version: ' + release,
105-
fg=self.fg, bg=self.bg)
106-
idle_v.grid(row=12, column=0, sticky=W, padx=10, pady=0)
107-
idle_button_f = Frame(frameBg, bg=self.bg)
108-
idle_button_f.grid(row=13, column=0, columnspan=3, sticky=NSEW)
109-
self.idle_about_b = Button(idle_button_f, text='README', width=8,
107+
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,
110122
highlightbackground=self.bg,
111-
command=self.ShowIDLEAbout)
112-
self.idle_about_b.pack(side=LEFT, padx=10, pady=10)
113-
self.idle_news_b = Button(idle_button_f, text='NEWS', width=8,
114-
highlightbackground=self.bg,
115-
command=self.ShowIDLENEWS)
116-
self.idle_news_b.pack(side=LEFT, padx=10, pady=10)
117-
self.idle_credits_b = Button(idle_button_f, text='Credits', width=8,
118-
highlightbackground=self.bg,
119-
command=self.ShowIDLECredits)
120-
self.idle_credits_b.pack(side=LEFT, padx=10, pady=10)
121-
122-
# License, et all, are of type _sitebuiltins._Printer
123-
def ShowLicense(self):
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."
124129
self.display_printer_text('About - License', license)
125130

126-
def ShowCopyright(self):
131+
def show_py_copyright(self):
132+
"Handle Copyright button event."
127133
self.display_printer_text('About - Copyright', copyright)
128134

129-
def ShowPythonCredits(self):
135+
def show_py_credits(self):
136+
"Handle Python Credits button event."
130137
self.display_printer_text('About - Python Credits', credits)
131138

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

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

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

143153
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+
"""
144161
printer._Printer__setup()
145162
text = '\n'.join(printer._Printer__lines)
146163
self._current_textview = textview.view_text(
147164
self, title, text, _utest=self._utest)
148165

149166
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+
"""
150173
fn = os.path.join(os.path.abspath(os.path.dirname(__file__)), filename)
151174
self._current_textview = textview.view_file(
152175
self, title, fn, encoding, _utest=self._utest)
153176

154-
def Ok(self, event=None):
177+
def ok(self, event=None):
178+
"Dismiss help_about dialog."
155179
self.destroy()
156180

157181

Lib/idlelib/idle_test/test_help_about.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
About = help_about.AboutDialog
1616
class Dummy_about_dialog():
1717
# Dummy class for testing file display functions.
18-
idle_credits = About.ShowIDLECredits
19-
idle_readme = About.ShowIDLEAbout
20-
idle_news = About.ShowIDLENEWS
18+
idle_credits = About.show_idle_credits
19+
idle_readme = About.show_readme
20+
idle_news = About.show_idle_news
2121
# Called by the above
2222
display_file_text = About.display_file_text
2323
_utest = True
@@ -47,9 +47,9 @@ def test_dialog_title(self):
4747

4848
def test_printer_dialog(self):
4949
"""This will test dialog which using printer"""
50-
buttons = [(license, self.dialog.buttonLicense),
51-
(copyright, self.dialog.buttonCopyright),
52-
(credits, self.dialog.buttonCredits)]
50+
buttons = [(license, self.dialog.py_license),
51+
(copyright, self.dialog.py_copyright),
52+
(credits, self.dialog.py_credits)]
5353

5454
for printer, button in buttons:
5555
dialog = self.dialog
@@ -64,9 +64,9 @@ def test_printer_dialog(self):
6464

6565
def test_file_dialog(self):
6666
"""This will test dialog which using file"""
67-
buttons = [('README.txt', self.dialog.idle_about_b),
68-
('NEWS.txt', self.dialog.idle_news_b),
69-
('CREDITS.txt', self.dialog.idle_credits_b)]
67+
buttons = [('README.txt', self.dialog.readme),
68+
('NEWS.txt', self.dialog.idle_news),
69+
('CREDITS.txt', self.dialog.idle_credits)]
7070

7171
for filename, button in buttons:
7272
dialog = self.dialog

0 commit comments

Comments
 (0)
0