Fa*@sXdZddlmZddlmZmZmZmZmZddl m Z ddl m Z m Z mZmZmZmZmZddl mZddlmZdZerdd lmZGd d d eZGd d d eZGdddeZGddde ZddZddZedkrTddl m!Z!e!edS)a help.py: Implement the Idle help menu. Contents are subject to revision at any time, without notice. Help => About IDLE: diplay About Idle dialog Help => IDLE Help: Display help.html with proper formatting. Doc/library/idle.rst (Sphinx)=> Doc/build/html/library/idle.html (help.copy_strip)=> Lib/idlelib/help.html HelpParser - Parse help.html and render to tk Text. HelpText - Display formatted help.html. HelpFrame - Contain text, scrollbar, and table-of-contents. (This will be needed for display in a future tabbed 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. ) HTMLParser)abspathdirnameisdirisfilejoin)python_version)TkToplevelFrameText ScrollbarMenu Menubutton)font)idleConfF)rc@sUeZdZdZddZdddZddZd d Zd d Zd S) HelpParsera~Render help.html into a text widget. The overridden handle_xyz methods handle a subset of html tags. The supplied text should have the needed tag configurations. The behavior for unsupported tags, such as table, is undefined. If the tags generated by Sphinx change, this class, especially the handle_starttag and handle_endtags methods, might have to also. cCstj|dd||_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ g|_ d|_ dS)NZconvert_charrefsTFr)r__init__texttagschartagsshowhdrlinklevelprehprefix nested_dl simplelisttocheader)selfrr""/usr/lib/python3.5/idlelib/help.pyr4s           zHelpParser.__init__cCs>|j|7_|jdkr$dndt|j|_dS)Nrrl)rstrr)r!amtr"r"r#indentCszHelpParser.indentcCsd}x&|D]\}}|dkr |}q Wd}|dkrY|dkrYd|_n8|dkr}|dkr}d|_n|dkr|d krd }n|d kr|d krd |_n|d kr|d krd|_n|dkrd|_n|d#krG|jdd$kr1d}d|_n d|_|jnJ|dkrn|jdkrd|_n#|dkr|jrdnd}n|dkr|jsd nd}d|_n|dkr|jd}n|d krd|_|jr|jj dd d|_ nv|dkr?|dkr?d|_ nR|dkrW||_ n:|d%kr|jrd|_ |jj dd ||_ |jr|jj d||j |jfd"S)&zHandle starttags in help.html.rclassZdivZsectionTZ sphinxsidebarFpfirstz spanrZversionmodifiedemulolZsimpler$ ZdlrZliz * z * ZdtddendpreblockaZ headerlinkh1h2h3N)r.r/)r6r7) rrfindrr(rrrrinsertrrr )r!tagZattrsZclass_r4vsr"r"r#handle_starttagGsd                                 zHelpParser.handle_starttagcCs|dkrJ|jd|jr|jj|j|jjdfnm|dkrbd|_nU|d krzd |_n=|d krd |_ d|_ n|dkr|jdddS)zHandle endtags in help.html.r5r6r7rr:r,r-rr4Frr.r1r/r'r$N)r5r6r7)r,r-)r.r1r/r8) r(rrappendr rindexrrrr)r!r;r"r"r# handle_endtag}s   (        zHelpParser.handle_endtagcCs|jr|j r|jr"|n|jdd}|jdkr_|d|jd|_|jd kr|jdkr|dt|j|jkr|t|jdj}|j |7_ |j j d ||j|j fdS) z"Handle date segments in help.html.r0 r5rr6r7rNr2)r5r6r7) rrrreplacerr@rlenstripr rr:r)r!datadr"r"r# handle_datas!"zHelpParser.handle_dataN) __name__ __module__ __qualname____doc__rr(r>rArHr"r"r"r#r+s   6 rc@s.eZdZdZddZddZdS)HelpTextzDisplay help.html.c Cs1tjddddd}tjddddd}d|d}tj||d d d d d ddd d|d||jdddg}|jdddg}|df|d<|jdd|ddf|jdd|ddf|jdd|ddf|jdd|d df|jd!d|dfd"d#|jd$d|d%fd&d'dd(d)d*d"d+|jd,d&d'd-d'|jd.d&d/d-d/|jd0d&d1d-d1|jd2d&d3d-d3t||_t|d4d5}|j }Wd6QRX|jj |d7|d8sz$HelpText.findfont..rootnameexistsTZfamilycss|]}|jVqdS)N)rm)rnror"r"r#rpsN)rmtkfontnamesZFontZactualZfamilies)r!rurrrr"r"r#res +zHelpText.findfontN)rIrJrKrLrrer"r"r"r#rMs  rMc@s.eZdZdZddZddZdS) HelpFramez&Display html text, scrollbar, and toc.cCstj||t||}|d|dsz$HelpFrame.toc_menu..Zmenu)rrrfrZ add_command)r!rrZdropZlblrr")rr#rs ) zHelpFrame.toc_menuN)rIrJrKrLrrr"r"r"r#rvs  rvc@s"eZdZdZddZdS) HelpWindowz!Display frame with rendered html.cCstj|||j||jd|jt||jdddddd|jddd|jddddS) NZWM_DELETE_WINDOWryrrzr{r|rxr$) r rZwm_titleZprotocolZdestroyrvrZgrid_columnconfigureZgrid_rowconfigure)r!rirjtitler"r"r#rs  %zHelpWindow.__init__N)rIrJrKrLrr"r"r"r#rs rcCsttttttddddd}ttttd}t|dH}t|d/}x%|D]}|j|jd qyWWd QRXWd QRXtd d S) a_Copy idle.html to idlelib/help.html, stripping trailing whitespace. Files with trailing whitespace cannot be pushed to the hg cpython repository. For 3.x (on Windows), help.html is generated, after editing idle.rst in the earliest maintenance version, with sphinx-build -bhtml . build/html python_d.exe -c "from idlelib.help import copy_strip; copy_strip()" After refreshing TortoiseHG workshop to generate a diff, check both the diff and displayed text. Push the diff along with the idle.rst change and merge both into default (or an intermediate maintenance version). When the 'earlist' version gets its final maintenance release, do an update as described above, without editing idle.rst, to rebase help.html on the next version of idle.rst. Do not worry about version changes as version is not displayed. Examine other changes and the result of Help -> IDLE Help. If maintenance and default versions of idle.rst diverge, and merging does not go smoothly, then consider generating separate help.html files from separate idle.htmls. ZDocZbuildZhtmlZlibraryz idle.htmlz help.htmlrbwbs Nzidle.html copied to help.html)rrr__file__rgwriterstripprint)srcZdstZinnoutliner"r"r# copy_strips )rcCsFttttd}t|s+dSt||dtdS)z7Create HelpWindow; called from Idle Help event handler.z help.htmlNzIDLE Help (%s))rrrrrrr)rirjr"r"r# show_idlehelps r__main__)runN)"rLZ html.parserros.pathrrrrrplatformrZtkinterr r r r r rrrrtZidlelib.configHandlerrZuse_ttkZ tkinter.ttkrrMrvrrrrIZidlelib.idle_test.htestrr"r"r"r#s$(4o*