B /g^-c@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: display 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 Scrollbarfont)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. cCs`tj|dd||_d|_d|_d|_d|_d|_d|_d|_ d|_ d|_ g|_ d|_ d|_dS)NT)Zconvert_charrefsFr)r__init__texttagschartagsshowhdrlinklevelprehprefix nested_dl simplelisttocheaderprevtag)selfrr!$/usr/lib64/python3.7/idlelib/help.pyr3szHelpParser.__init__cCs0|j|7_|jdkrdn dt|j|_dS)z#Change indent (+1, 0, -1) and tags.rrZlN)rZstrr)r Zamtr!r!r"indentCszHelpParser.indentcCs>d}x|D]\}}|dkr |}q Wd}|dkr@|dkr@d|_n|dkrZ|dkrZd|_n|dkr|jr|jd s|jd d }|r|sd nd }nx|dkr|dkrd|_n^|dkr|dkrd|_nD|dkrd|_n2|dkr|ddkrd }d|_nd|_|n|dkr2|j d krd|_ n|dkrN|jrHdnd}n|dkrp|j sdd nd }d|_ n|dkr|d }n|dkrd|_ |jr|j dd d|_ nZ|dkr|dkrd|_n>|dkr||_ n,|d kr|jr d|_|j dd ||_ |jr0|j d||j |jfd|f|_d!S)"zHandle starttags in help.html.rZclassZdivZsectionTZ sphinxsidebarFZprzend-1c linestartzend-1cz  spanrZversionmodifiedem)ulolZsimpleZdlZliz * z * ZdtddendpreblockaZ headerlinkh1)h2h3N)rrrZgetZisspacerZfindrr$rrrinsertrrr)r tagZattrsZclass_r.ZvZsZlastliner!r!r"handle_starttagHsh               zHelpParser.handle_starttagcCs|dkr^|jdkst|jrV|dkr(dn|dkr4dnd}|j||j|jdfd|_nH|d krnd|_ n8|d kr~d |_ n(|d krd |_ d|_n|d kr| dd |f|_ dS)zHandle endtags in help.html.r/r0r1rr1z r0z rr2)r&r'r.Fr)r(r+r)r*N)rZAssertionErrorrrZappendrrindexrrrrr$r)r r3r$r!r!r" handle_endtags$   zHelpParser.handle_endtagcCs|jr|js|jr|n |dd}|jdkr`y|d|d|_Wntk r^d|_YnX|jdkr|jdkr|dt|j|jkr|t|jd}|j | 7_ |j d||j|j fdS) z"Handle date segments in help.html.r%z r/rrr5Nr,)rrrZreplacerr6rZ ValueErrorZlenrZstriprr2r)r ZdataZdr!r!r" handle_datas     zHelpParser.handle_dataN)r#) __name__ __module__ __qualname____doc__rr$r4r7r8r!r!r!r"r*s  :rc@ eZdZdZddZddZdS)HelpTextzDisplay help.html.c Csvtjddddd}tjddddd}d|d}tj||d d d d ||d |d ddg}|dddg}|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}| }Wd3QRX|j |d4|d5<d3S)6z'Configure tags and feed file to parser.mainZ EditorWindowwidthZint)ZtypeheightiiZwordri)ZwrapZhighlightthicknessZpadx borderwidthr@rAZ TkDefaultFontZarialZ helveticaZ TkFixedFontZmonacoZcourieri rr'Zitalicr r/iZboldr0ir1irz#f6f6ff)r backgroundr-i ir#Zsolidz#eeffcc)rlmargin1rBZreliefrCZl1)rDZlmargin2Zl2i2Zl3iKZl4idzutf-8)ZencodingNZdisabledZstate) rZ GetOptionr rfindfontZ tag_configurerparseropenZreadZfeed) r parentfilenameZuwideZuhighZ normalfontZ fixedfontZfZcontentsr!r!r"rs0      zHelpText.__init__cCsnxh|D]`}|ddtj|dDkrDtj|d|d}|dS|ddtj|dDkr|SqWdS) z4Return name of first font family derived from names.cs|]}|VqdSNlowerZ.0Zxr!r!r" sz$HelpText.findfont..)rootT)nameZexistsrPZfamilycsrJrKrLrNr!r!r"rOsN)rMtkfontnamesZFontZactualZfamilies)r rSrQrr!r!r"rEs   zHelpText.findfontN)r9r:r;r<rrEr!r!r!r"r>sr>c@r=) HelpFramez&Display html text, scrollbar, and toc.cCst||t|||_}|d|d<|||_}t||jd|_}|j |d<|j ddd|j ddd|j dddd|j ddd d|j dd d ddS) NrC)commandZyscrollcommandrr#ZweightZnw)rowcolumnstickynsewZns) rrr>rtoc_menurr yviewscrollZsetZ rowconfigureZcolumnconfiguregrid)r rHrIrrr^r!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.ZTOCrF)Ztearoffcs |SrK)r])dexr`r!r"Zsz$HelpFrame.toc_menu..)ZlabelrUZmenu)r r rFrZ add_command)r rrZdropZlblrar!r`r"r\s   zHelpFrame.toc_menuN)r9r:r;r<rr\r!r!r!r"rTsrTc@seZdZdZddZdS) HelpWindowz!Display frame with rendered html.cCsZt|||||d|jt||jdddd|jddd|jddddS)NZWM_DELETE_WINDOWrrZ)rXrWrYr#rV) rrZwm_titleZprotocolZdestroyrTr_Zgrid_columnconfigureZgrid_rowconfigure)r rHrIZtitler!r!r"rs   zHelpWindow.__init__N)r9r:r;r<rr!r!r!r"rbsrbc Csttttttddddd}ttttd}t|d<}t|d&}x|D]}||d 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 procedure above to generate a maintenance version. ZDocZbuildZhtmlZlibraryz idle.html help.htmlZrbZwbs Nz copied to )rrr__file__rGZwriteZrstripZprint)ZsrcZdstZinnZoutZliner!r!r" copy_strips   *recCs4ttttd}t|sdSt||dtdS)z7Create HelpWindow; called from Idle Help event handler.rcNzIDLE Help (%s))rrrrdrrbr)rHrIr!r!r" show_idlehelpsrfZ__main__)r?zidlelib.idle_test.test_helpr[F)Z verbosityZexit)runN)!r<Z html.parserrZos.pathrrrrZplatformrZtkinterrrr r Z tkinter.ttkr r rrRZidlelib.configrrr>rTrbrerfr9Zunittestr?Zidlelib.idle_test.htestrgr!r!r!r"Zs$    ~*