3  f=,@sdZddlmZddlmZmZmZmZddlm Z ddl m Z m Z m Z mZddlmZmZddl mZddlmZGd d d eZGd d d e ZGd dde ZGddde ZddZddZedkrddlmZeddddddlm 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)abspathdirnameisfilejoin)python_version)ToplevelFrameTextMenu) Menubutton Scrollbar)font)idleConfc@s:eZdZdZddZdddZddZd 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. cCsZtj|dd||_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ g|_ d|_ dS)NT)Zconvert_charrefsFr)r__init__texttagschartagsshowhdrlinklevelprehprefix nested_dl simplelisttocheader)selfrr 1/opt/alt/python36/lib64/python3.6/idlelib/help.pyr3szHelpParser.__init__cCs0|j|7_|jdkrdn dt|j|_dS)Nrrl)rstrr)ramtr r r!indentBszHelpParser.indentcCs d}x|D]\}}|dkr |}q Wd}|dkr@|dkr@d|_n|dkrZ|dkrZd|_n|dkrr|d krrd }nv|d kr|d krd |_n\|d kr|d krd|_nB|dkrd|_n0|d#kr|jdd$krd}d|_nd|_|jn|dkr |jdkrd|_n|dkr&|jr dnd}n|dkrH|js|dkr||_ 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-)r4r5) rrfindrr&rrrrinsertrrr)rtagZattrsZclass_r2vsr r r!handle_starttagFsd              zHelpParser.handle_starttagcCs|dkrT|jd|jr|dkr$dn|dkr0dnd}|jj||j|jjdfnJ|dkrdd|_n:|d krtd |_n*|d krd |_ d|_ n|dkr|jdddS)zHandle endtags in help.html.r3r4r5rz z rr8r*r+r2Frr,r/r-r")r%N)r3r4r5)r*r+)r,r/r-r6) r&rrappendrrindexrrrr)rr9r&r r r! handle_endtag|s     zHelpParser.handle_endtagc Cs|jr|j r|jr|n |jdd}|jdkrby|d|jd|_Wntk r`d|_YnX|jd kr|jdkr|dt|j|jkr|t|jd}|j |j 7_ |j j d ||j|j fdS) z"Handle date segments in help.html.r. r3rrr4r5Nr0)r3r4r5)rrrreplacerr>r ValueErrorlenrstriprr8r)rdatadr r r! handle_datas    zHelpParser.handle_dataN)r") __name__ __module__ __qualname____doc__rr&r<r?rGr r r r!r*s  6rc@s eZdZdZddZddZdS)HelpTextzDisplay help.html.c Csvtjddddd}tjddddd}d|d}tj||d d d d ||d |jd ddg}|jdddg}|df|d<|jd|ddfd|jd|ddfd|jd|ddfd|jd|ddfd|jd|dfd d!|jd"|d#fd$d%d&d'd(|jd)d$d$d*|jd+d,d,d*|jd-d.d.d*|jd/d0d0d*t||_t|d1d2}|j }Wd3QRX|jj |d4|d5<d3S)6z'Configure tags and feed file to parser.mainZ EditorWindowwidthint)typeheightZwordr)ZwrapZhighlightthicknessZpadx borderwidthrNrQZ TkDefaultFontZarialZ helveticaZ TkFixedFontZmonacoZcourier rr+Zitalic)rr3Zboldr4r5rz#f6f6ff)r backgroundr1 r"Zsolidz#eeffcc)rlmargin1rUZreliefrZl1)r]Zlmargin2l22l3Kl4dzutf-8)encodingNZdisabledstate) rZ GetOptionr rfindfontZ tag_configurerparseropenreadZfeed) rparentfilenameZuwideZuhighZ normalfontZ fixedfontfcontentsr r r!rs0      zHelpText.__init__cCsnxh|D]`}|jddtj|dDkrDtj|d|d}|jdS|jddtj|dDkr|SqWdS) z4Return name of first font family derived from names.css|]}|jVqdS)N)lower).0xr r r! sz$HelpText.findfont..)rootT)nameexistsrsZfamilycss|]}|jVqdS)N)ro)rprqr r r!rrsN)rotkfontnamesZFontZactualZfamilies)rrwrtrr r r!rgs   zHelpText.findfontN)rHrIrJrKrrgr r r r!rLsrLc@s eZdZdZddZddZdS) HelpFramez&Display html text, scrollbar, and toc.cCstj||t|||_}|d|d<|j||_}t||jd|_}|j |d<|j ddd|j ddd|j dddd|j ddd d|j dd d ddS) NrZ)commandZyscrollcommandrr")weightZnw)rowcolumnstickynsewns) r rrLrtoc_menurr yviewscrollsetZ rowconfigureZcolumnconfiguregrid)rrkrlrrrr r r!rs   zHelpFrame.__init__csTt|dd}t|dd}x.jjD]"\}}|j||ffdd dq"W||d<|S) z+Create table of contents as drop-down menu.ZTOC)rF)Ztearoffcs j|S)N)r)dex)rr r!sz$HelpFrame.toc_menu..)ZlabelryZmenu)r r rhrZ add_command)rrrZdropZlblrr )rr!rs   zHelpFrame.toc_menuN)rHrIrJrKrrr r r r!rxsrxc@seZdZdZddZdS) HelpWindowz!Display frame with rendered html.cCsZtj|||j||jd|jt||jdddd|jddd|jddddS)NZWM_DELETE_WINDOWrr~)r|r{r}r")rz) rrZwm_titleZprotocolZdestroyrxrZgrid_columnconfigureZgrid_rowconfigure)rrkrltitler r r!rs   zHelpWindow.__init__N)rHrIrJrKrr r r r!rsrcCsttttttddddd}ttttd}t|d<}t|d&}x|D]}|j|jd qRWWd QRXWd QRXt|d |d S) a_Copy idle.html to idlelib/help.html, stripping trailing whitespace. Files with trailing whitespace cannot be pushed to the git cpython repository. For 3.x (on Windows), help.html is generated, after editing idle.rst on the master branch, with sphinx-build -bhtml . build/html python_d.exe -c "from idlelib.help import copy_strip; copy_strip()" Check build/html/library/idle.html, the help.html diff, and the text displayed by Help => IDLE Help. Add a blurb and create a PR. It can be worthwhile to occasionally generate help.html without touching idle.rst. Changes to the master version and to the doc build system may result in changes that should not changed the displayed text, but might break HelpParser. As long as master and maintenance versions of idle.rst remain the same, help.html can be backported. The internal Python version number is not displayed. If maintenance idle.rst diverges from the master version, then instead of backporting help.html from master, repeat the proceedure above to generate a maintenance version. ZDocZbuildZhtmlZlibraryz idle.htmlz help.htmlrbwb Nz copied to )rrr__file__riwriterstripprint)srcdstZinnoutliner r r! copy_strips   *rcCs4ttttd}t|sdSt||dtdS)z7Create HelpWindow; called from Idle Help event handler.z help.htmlNzIDLE Help (%s))rrrrrrr)rkrlr r r! show_idlehelpsr__main__)rMzidlelib.idle_test.test_helprF) verbosityexit)runN)!rKZ html.parserrZos.pathrrrrplatformrZtkinterrr r r Z tkinter.ttkr r rrvZidlelib.configrrrLrxrrrrHZunittestrMZidlelib.idle_test.htestrr r r r!s$    v*