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
65Help => 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
2225show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog.
2326"""
3639## IDLE Help ##
3740
3841class 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
151154class 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
190193class 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
213218class 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+
224240def 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
231248if __name__ == '__main__' :
0 commit comments