Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cba1a1a

Browse files
committed
Issue #16893: Add idlelib.help.copy_strip() to copy-rstrip Doc/.../idle.html.
Change destination to help.html. Adjust NEWS entries.
1 parent d9763c2 commit cba1a1a

4 files changed

Lines changed: 39 additions & 22 deletions

File tree

Lib/idlelib/NEWS.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ What's New in Idle 3.4.4?
77

88
- Issue #25199: Idle: add synchronization comments for future maintainers.
99

10-
- Issue #16893: Replace help.txt with idle.html for Idle doc display.
11-
The new idlelib/idle.html is copied from Doc/build/html/library/idle.html.
10+
- Issue #16893: Replace help.txt with help.html for Idle doc display.
11+
The new idlelib/help.html is rstripped Doc/build/html/library/idle.html.
1212
It looks better than help.txt and will better document Idle as released.
1313
The tkinter html viewer that works for this file was written by Mark Roseman.
1414
The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated.

Lib/idlelib/help.py

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
1-
"""
2-
help.py implements the Idle help menu and is subject to change.
1+
""" help.py: Implement the Idle help menu.
2+
Contents are subject to revision at any time, without notice.
33
4-
The contents are subject to revision at any time, without notice.
54
65
Help => About IDLE: diplay About Idle dialog
76
87
<to be moved here from aboutDialog.py>
98
10-
Help => IDLE Help: display idle.html with proper formatting
119
12-
HelpParser - Parses idle.html generated from idle.rst by Sphinx
13-
and renders to tk Text.
10+
Help => IDLE Help: Display help.html with proper formatting.
11+
Doc/library/idle.rst (Sphinx)=> Doc/build/html/library/idle.html
12+
(help.copy_strip)=> Lib/idlelib/help.html
13+
14+
HelpParser - Parse help.html and and render to tk Text.
1415
15-
HelpText - Displays formatted idle.html.
16+
HelpText - Display formatted help.html.
1617
17-
HelpFrame - Contains text, scrollbar, and table-of-contents.
18+
HelpFrame - Contain text, scrollbar, and table-of-contents.
1819
(This will be needed for display in a future tabbed window.)
1920
20-
HelpWindow - Display idleframe in a standalone window.
21+
HelpWindow - Display HelpFrame in a standalone window.
22+
23+
copy_strip - Copy idle.html to help.html, rstripping each line.
2124
2225
show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog.
2326
"""
@@ -36,7 +39,7 @@
3639
## IDLE Help ##
3740

3841
class HelpParser(HTMLParser):
39-
"""Render idle.html generated by Sphinx from idle.rst.
42+
"""Render help.html into a text widget.
4043
4144
The overridden handle_xyz methods handle a subset of html tags.
4245
The supplied text should have the needed tag configurations.
@@ -62,7 +65,7 @@ def indent(self, amt=1):
6265
self.tags = '' if self.level == 0 else 'l'+str(self.level)
6366

6467
def handle_starttag(self, tag, attrs):
65-
"Handle starttags in idle.html."
68+
"Handle starttags in help.html."
6669
class_ = ''
6770
for a, v in attrs:
6871
if a == 'class':
@@ -120,7 +123,7 @@ def handle_starttag(self, tag, attrs):
120123
self.text.insert('end', s, self.tags)
121124

122125
def handle_endtag(self, tag):
123-
"Handle endtags in idle.html."
126+
"Handle endtags in help.html."
124127
if tag in ['h1', 'h2', 'h3', 'span', 'em']:
125128
self.indent(0) # clear tag, reset indent
126129
if self.show and tag in ['h1', 'h2', 'h3']:
@@ -136,7 +139,7 @@ def handle_endtag(self, tag):
136139
self.indent(amt=-1)
137140

138141
def handle_data(self, data):
139-
"Handle date segments in idle.html."
142+
"Handle date segments in help.html."
140143
if self.show and not self.hdrlink:
141144
d = data if self.pre else data.replace('\n', ' ')
142145
if self.tags == 'h1':
@@ -149,7 +152,7 @@ def handle_data(self, data):
149152

150153

151154
class HelpText(Text):
152-
"Display idle.html."
155+
"Display help.html."
153156
def __init__(self, parent, filename):
154157
"Configure tags and feed file to parser."
155158
Text.__init__(self, parent, wrap='word', highlightthickness=0,
@@ -188,6 +191,7 @@ def findfont(self, names):
188191

189192

190193
class HelpFrame(Frame):
194+
"Display html text, scrollbar, and toc."
191195
def __init__(self, parent, filename):
192196
Frame.__init__(self, parent)
193197
text = HelpText(self, filename)
@@ -202,6 +206,7 @@ def __init__(self, parent, filename):
202206
toc.grid(column=0, row=0, sticky='nw')
203207

204208
def contents_widget(self, text):
209+
"Create table of contents."
205210
toc = Menubutton(self, text='TOC')
206211
drop = Menu(toc, tearoff=False)
207212
for tag, lbl in text.parser.contents:
@@ -211,7 +216,7 @@ def contents_widget(self, text):
211216

212217

213218
class HelpWindow(Toplevel):
214-
219+
"Display frame with rendered html."
215220
def __init__(self, parent, filename, title):
216221
Toplevel.__init__(self, parent)
217222
self.wm_title(title)
@@ -221,11 +226,23 @@ def __init__(self, parent, filename, title):
221226
self.grid_rowconfigure(0, weight=1)
222227

223228

229+
def copy_strip():
230+
"Copy idle.html to idlelib/help.html, stripping trailing whitespace."
231+
src = join(abspath(dirname(dirname(dirname(__file__)))),
232+
'Doc', 'build', 'html', 'library', 'idle.html')
233+
dst = join(abspath(dirname(__file__)), 'help.html')
234+
with open(src, 'rb') as inn,\
235+
open(dst, 'wb') as out:
236+
for line in inn:
237+
out.write(line.rstrip() + '\n')
238+
print('idle.html copied to help.html')
239+
224240
def show_idlehelp(parent):
225-
filename = join(abspath(dirname(__file__)), 'idle.html')
241+
"Create HelpWindow; called from Idle Help event handler."
242+
filename = join(abspath(dirname(__file__)), 'help.html')
226243
if not isfile(filename):
227-
dirpath = join(abspath(dirname(dirname(dirname(__file__)))),
228-
'Doc', 'build', 'html', 'library')
244+
# try copy_strip, present message
245+
return
229246
HelpWindow(parent, filename, 'IDLE Help')
230247

231248
if __name__ == '__main__':

Misc/NEWS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,8 +447,8 @@ IDLE
447447

448448
- Issue #25199: Idle: add synchronization comments for future maintainers.
449449

450-
- Issue #16893: Replace help.txt with idle.html for Idle doc display.
451-
The new idlelib/idle.html is copied from Doc/build/html/library/idle.html.
450+
- Issue #16893: Replace help.txt with help.html for Idle doc display.
451+
The new idlelib/help.html is rstripped Doc/build/html/library/idle.html.
452452
It looks better than help.txt and will better document Idle as released.
453453
The tkinter html viewer that works for this file was written by Mark Roseman.
454454
The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated.

0 commit comments

Comments
 (0)