mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	Issue #16893: Add idlelib.help.copy_strip() to copy-rstrip Doc/.../idle.html.
Change destination to help.html. Adjust NEWS entries.
This commit is contained in:
		
							parent
							
								
									d9763c2ce4
								
							
						
					
					
						commit
						cba1a1a000
					
				
					 4 changed files with 39 additions and 22 deletions
				
			
		|  | @ -7,8 +7,8 @@ What's New in Idle 3.4.4? | ||||||
| 
 | 
 | ||||||
| - Issue #25199: Idle: add synchronization comments for future maintainers. | - Issue #25199: Idle: add synchronization comments for future maintainers. | ||||||
| 
 | 
 | ||||||
| - Issue #16893: Replace help.txt with idle.html for Idle doc display. | - Issue #16893: Replace help.txt with help.html for Idle doc display. | ||||||
|   The new idlelib/idle.html is copied from Doc/build/html/library/idle.html. |   The new idlelib/help.html is rstripped Doc/build/html/library/idle.html. | ||||||
|   It looks better than help.txt and will better document Idle as released. |   It looks better than help.txt and will better document Idle as released. | ||||||
|   The tkinter html viewer that works for this file was written by Mark Roseman. |   The tkinter html viewer that works for this file was written by Mark Roseman. | ||||||
|   The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated. |   The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated. | ||||||
|  |  | ||||||
|  | @ -1,23 +1,26 @@ | ||||||
| """ | """ help.py: Implement the Idle help menu. | ||||||
| help.py implements the Idle help menu and is subject to change. | Contents are subject to revision at any time, without notice. | ||||||
| 
 | 
 | ||||||
| The contents are subject to revision at any time, without notice. |  | ||||||
| 
 | 
 | ||||||
| Help => About IDLE: diplay About Idle dialog | Help => About IDLE: diplay About Idle dialog | ||||||
| 
 | 
 | ||||||
| <to be moved here from aboutDialog.py> | <to be moved here from aboutDialog.py> | ||||||
| 
 | 
 | ||||||
| Help => IDLE Help: display idle.html with proper formatting |  | ||||||
| 
 | 
 | ||||||
| HelpParser - Parses idle.html generated from idle.rst by Sphinx | Help => IDLE Help: Display help.html with proper formatting. | ||||||
| and renders to tk Text. | Doc/library/idle.rst (Sphinx)=> Doc/build/html/library/idle.html | ||||||
|  | (help.copy_strip)=> Lib/idlelib/help.html | ||||||
| 
 | 
 | ||||||
| HelpText - Displays formatted idle.html. | HelpParser - Parse help.html and and render to tk Text. | ||||||
| 
 | 
 | ||||||
| HelpFrame - Contains text, scrollbar, and table-of-contents. | HelpText - Display formatted help.html. | ||||||
|  | 
 | ||||||
|  | HelpFrame - Contain text, scrollbar, and table-of-contents. | ||||||
| (This will be needed for display in a future tabbed window.) | (This will be needed for display in a future tabbed window.) | ||||||
| 
 | 
 | ||||||
| HelpWindow - Display idleframe in a standalone window. | HelpWindow - Display HelpFrame in a standalone window. | ||||||
|  | 
 | ||||||
|  | copy_strip - Copy idle.html to help.html, rstripping each line. | ||||||
| 
 | 
 | ||||||
| show_idlehelp - Create HelpWindow.  Called in EditorWindow.help_dialog. | show_idlehelp - Create HelpWindow.  Called in EditorWindow.help_dialog. | ||||||
| """ | """ | ||||||
|  | @ -36,7 +39,7 @@ | ||||||
| ## IDLE Help ## | ## IDLE Help ## | ||||||
| 
 | 
 | ||||||
| class HelpParser(HTMLParser): | class HelpParser(HTMLParser): | ||||||
|     """Render idle.html generated by Sphinx from idle.rst. |     """Render help.html into a text widget. | ||||||
| 
 | 
 | ||||||
|     The overridden handle_xyz methods handle a subset of html tags. |     The overridden handle_xyz methods handle a subset of html tags. | ||||||
|     The supplied text should have the needed tag configurations. |     The supplied text should have the needed tag configurations. | ||||||
|  | @ -62,7 +65,7 @@ def indent(self, amt=1): | ||||||
|         self.tags = '' if self.level == 0 else 'l'+str(self.level) |         self.tags = '' if self.level == 0 else 'l'+str(self.level) | ||||||
| 
 | 
 | ||||||
|     def handle_starttag(self, tag, attrs): |     def handle_starttag(self, tag, attrs): | ||||||
|         "Handle starttags in idle.html." |         "Handle starttags in help.html." | ||||||
|         class_ = '' |         class_ = '' | ||||||
|         for a, v in attrs: |         for a, v in attrs: | ||||||
|             if a == 'class': |             if a == 'class': | ||||||
|  | @ -120,7 +123,7 @@ def handle_starttag(self, tag, attrs): | ||||||
|             self.text.insert('end', s, self.tags) |             self.text.insert('end', s, self.tags) | ||||||
| 
 | 
 | ||||||
|     def handle_endtag(self, tag): |     def handle_endtag(self, tag): | ||||||
|         "Handle endtags in idle.html." |         "Handle endtags in help.html." | ||||||
|         if tag in ['h1', 'h2', 'h3', 'span', 'em']: |         if tag in ['h1', 'h2', 'h3', 'span', 'em']: | ||||||
|             self.indent(0)  # clear tag, reset indent |             self.indent(0)  # clear tag, reset indent | ||||||
|             if self.show and tag in ['h1', 'h2', 'h3']: |             if self.show and tag in ['h1', 'h2', 'h3']: | ||||||
|  | @ -136,7 +139,7 @@ def handle_endtag(self, tag): | ||||||
|             self.indent(amt=-1) |             self.indent(amt=-1) | ||||||
| 
 | 
 | ||||||
|     def handle_data(self, data): |     def handle_data(self, data): | ||||||
|         "Handle date segments in idle.html." |         "Handle date segments in help.html." | ||||||
|         if self.show and not self.hdrlink: |         if self.show and not self.hdrlink: | ||||||
|             d = data if self.pre else data.replace('\n', ' ') |             d = data if self.pre else data.replace('\n', ' ') | ||||||
|             if self.tags == 'h1': |             if self.tags == 'h1': | ||||||
|  | @ -149,7 +152,7 @@ def handle_data(self, data): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class HelpText(Text): | class HelpText(Text): | ||||||
|     "Display idle.html." |     "Display help.html." | ||||||
|     def __init__(self, parent, filename): |     def __init__(self, parent, filename): | ||||||
|         "Configure tags and feed file to parser." |         "Configure tags and feed file to parser." | ||||||
|         Text.__init__(self, parent, wrap='word', highlightthickness=0, |         Text.__init__(self, parent, wrap='word', highlightthickness=0, | ||||||
|  | @ -188,6 +191,7 @@ def findfont(self, names): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class HelpFrame(Frame): | class HelpFrame(Frame): | ||||||
|  |     "Display html text, scrollbar, and toc." | ||||||
|     def __init__(self, parent, filename): |     def __init__(self, parent, filename): | ||||||
|         Frame.__init__(self, parent) |         Frame.__init__(self, parent) | ||||||
|         text = HelpText(self, filename) |         text = HelpText(self, filename) | ||||||
|  | @ -202,6 +206,7 @@ def __init__(self, parent, filename): | ||||||
|         toc.grid(column=0, row=0, sticky='nw') |         toc.grid(column=0, row=0, sticky='nw') | ||||||
| 
 | 
 | ||||||
|     def contents_widget(self, text): |     def contents_widget(self, text): | ||||||
|  |         "Create table of contents." | ||||||
|         toc = Menubutton(self, text='TOC') |         toc = Menubutton(self, text='TOC') | ||||||
|         drop = Menu(toc, tearoff=False) |         drop = Menu(toc, tearoff=False) | ||||||
|         for tag, lbl in text.parser.contents: |         for tag, lbl in text.parser.contents: | ||||||
|  | @ -211,7 +216,7 @@ def contents_widget(self, text): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class HelpWindow(Toplevel): | class HelpWindow(Toplevel): | ||||||
| 
 |     "Display frame with rendered html." | ||||||
|     def __init__(self, parent, filename, title): |     def __init__(self, parent, filename, title): | ||||||
|         Toplevel.__init__(self, parent) |         Toplevel.__init__(self, parent) | ||||||
|         self.wm_title(title) |         self.wm_title(title) | ||||||
|  | @ -221,11 +226,23 @@ def __init__(self, parent, filename, title): | ||||||
|         self.grid_rowconfigure(0, weight=1) |         self.grid_rowconfigure(0, weight=1) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | def copy_strip(): | ||||||
|  |     "Copy idle.html to idlelib/help.html, stripping trailing whitespace." | ||||||
|  |     src = join(abspath(dirname(dirname(dirname(__file__)))), | ||||||
|  |                'Doc', 'build', 'html', 'library', 'idle.html') | ||||||
|  |     dst = join(abspath(dirname(__file__)), 'help.html') | ||||||
|  |     with open(src, 'rb') as inn,\ | ||||||
|  |          open(dst, 'wb') as out: | ||||||
|  |         for line in inn: | ||||||
|  |             out.write(line.rstrip() + '\n') | ||||||
|  |     print('idle.html copied to help.html') | ||||||
|  | 
 | ||||||
| def show_idlehelp(parent): | def show_idlehelp(parent): | ||||||
|     filename = join(abspath(dirname(__file__)), 'idle.html') |     "Create HelpWindow; called from Idle Help event handler." | ||||||
|  |     filename = join(abspath(dirname(__file__)), 'help.html') | ||||||
|     if not isfile(filename): |     if not isfile(filename): | ||||||
|         dirpath = join(abspath(dirname(dirname(dirname(__file__)))), |         # try copy_strip, present message | ||||||
|                    'Doc', 'build', 'html', 'library') |         return  | ||||||
|     HelpWindow(parent, filename, 'IDLE Help') |     HelpWindow(parent, filename, 'IDLE Help') | ||||||
| 
 | 
 | ||||||
| if __name__ == '__main__': | if __name__ == '__main__': | ||||||
|  |  | ||||||
|  | @ -447,8 +447,8 @@ IDLE | ||||||
| 
 | 
 | ||||||
| - Issue #25199: Idle: add synchronization comments for future maintainers. | - Issue #25199: Idle: add synchronization comments for future maintainers. | ||||||
| 
 | 
 | ||||||
| - Issue #16893: Replace help.txt with idle.html for Idle doc display. | - Issue #16893: Replace help.txt with help.html for Idle doc display. | ||||||
|   The new idlelib/idle.html is copied from Doc/build/html/library/idle.html. |   The new idlelib/help.html is rstripped Doc/build/html/library/idle.html. | ||||||
|   It looks better than help.txt and will better document Idle as released. |   It looks better than help.txt and will better document Idle as released. | ||||||
|   The tkinter html viewer that works for this file was written by Mark Roseman. |   The tkinter html viewer that works for this file was written by Mark Roseman. | ||||||
|   The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated. |   The now unused EditorWindow.HelpDialog class and helt.txt file are deprecated. | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Terry Jan Reedy
						Terry Jan Reedy