o =?hO.@sdZddlmZddlmZmZmZmZddlm Z ddl m Z m Z m Z ddlmZmZmZmZddl mZddlmZGd d d eZGd d d e ZGd ddeZGddde ZddZddZedkrddlmZeddddddl m!Z!e!edSdS)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)ToplevelTextMenu)Frame Menubutton ScrollbarStylefont)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#3/opt/alt/python310/lib64/python3.10/idlelib/help.pyr3s zHelpParser.__init__cCs6|j|7_|jdkrd|_dSdt|j|_dS)z#Change indent (+1, 0, -1) and tags.rrlN)rstrr)r"Zamtr#r#r$indentCs(zHelpParser.indentcCsd}|D] \}}|dkr|}qd}|dkr|dgkrd|_n|dkr*|dkr*d|_n|d krH|jrH|jd sH|jd d }|rE|sEd nd}n|dkrT|dkrTd|_n|dkr`|dkr`d|_n|dkrhd|_n|dvr|ddkryd}d|_nd|_|np|dkr|j d krd|_ nc|dkr|jrdnd}nW|dkr|j sd nd}d|_ nH|dkr|d}n=|dkrd|_ |jr|j dd d|_ n(|dkr|dkrd|_n|d kr||_ n|d!vr|jrd|_|j dd ||_ |jr|j d||j |jfd|f|_d"S)#zHandle starttags in help.html.rclassZsection)idZidleTZdivZclearerFprzend-1c linestartzend-1cz  spanrZversionmodifiedem)ulolsimpleZdlZliz * z * ZdtddendpreblockaZ headerlinkh1)h2h3N)rr!rgetisspacerfindrr(rrrinsertrrr )r"tagZattrsZclass_r6vsZlastliner#r#r$handle_starttagHsl   zHelpParser.handle_starttagcCs|dvr/|jdks J|jr+|dkrdn|dkrdnd}|j||j|jdfd|_n$|d vr7d|_n|d kr?d |_ n|d krJd |_ d|_n |d vrS| dd |f|_ dS)zHandle endtags in help.html.r7r8r9rr9z r8z rr=)r-r.r6Fr)r/r3r0r2N) rrrappendr rindexrrrrr(r!)r"r>r(r#r#r$ handle_endtags&   zHelpParser.handle_endtagcCs|jre|jsg|jr |n|dd}|jdkr/z |d|d|_Wn ty.d|_Ynw|jdvrW|jdkrN|dt|j|jkrN|t|jd}|j | 7_ |j d||j|j fdSdSdS) z"Handle date segments in help.html.r, r7rrrBNr4)rrrreplacerrDr ValueErrorlenr striprr=r)r"datadr#r#r$ handle_datas      zHelpParser.handle_dataN)r%) __name__ __module__ __qualname____doc__rr(rArErMr#r#r#r$r*s : rc@ eZdZdZddZddZdS)HelpTextzDisplay help.html.c Cstjddddd}tjddddd}d|d}tj||d d d d ||d |gd }|gd}|df|d<|jd|ddfd|jd|ddfd|jd|ddfd|jd|ddfd|jd|dfdd|jd|dfd d!d"d#d$|jd%d d d&|jd'd(d(d&|jd)d*d*d&|jd+d,d,d&t||_t|d-d. }| }Wd/n1swY|j |d0|d1<d/S)2z'Configure tags and feed file to parser.mainZ EditorWindowwidthint)typeheightZwordr)ZwrapZhighlightthicknessZpadx borderwidthrUrX)Z TkDefaultFontZarialZ helvetica)Z TkFixedFontZmonacoZcourier rr.Zitalicrr7Zboldr8r9rz#f6f6ff)r backgroundr5 r%Zsolidz#eeffcc)rlmargin1r\Zreliefral1)rdZlmargin2l22l3Kl4dzutf-8)encodingNZdisabledstate) rZ GetOptionr rfindfontZ tag_configurerparseropenreadZfeed) r"parentfilenameZuwideZuhighZ normalfontZ fixedfontfcontentsr#r#r$rs6       zHelpText.__init__cCsr|D]4}|ddtj|dDvr#tj|d|d}|dS|ddtj|dDvr6|SqdS) z4Return name of first font family derived from names.cs|]}|VqdSNlower.0xr#r#r$ sz$HelpText.findfont..)rootT)nameexistsr~Zfamilycsrvrwrxrzr#r#r$r}sN)rytkfontnamesZFontZactualZfamilies)r"rrrr#r#r$rns  zHelpText.findfontN)rNrOrPrQrrnr#r#r#r$rSs rSc@rR) HelpFramez&Display html text, scrollbar, and toc.cCst||t|||_}t||_d|d<|jjd|dd|||_}t ||j d|_ }|j |d<|j ddd |jddd |jddd d |jddd d |jdd dd dS)Nzhelpframe.TFramestylera)ra)commandZyscrollcommandrr%ZweightZnw)rowcolumnstickynsewns)r rrSrrrZ configuretoc_menurr yviewscrollsetZ rowconfigureZcolumnconfiguregrid)r"rrrsrrrr#r#r$rs   zHelpFrame.__init__csPt|dd}t|dd}jjD]\}}|j||ffdd dq||d<|S) z+Create table of contents as drop-down menu.ZTOCrF)Ztearoffcs |Srw)r)dexrr#r$s z$HelpFrame.toc_menu..)ZlabelrZmenu)r r rorZ add_command)r"rrZdropZlblrr#rr$rs  zHelpFrame.toc_menuN)rNrOrPrQrrr#r#r#r$rs rc@seZdZdZddZdS) HelpWindowz!Display frame with rendered html.cCsZt|||||d|jt||jdddd|jddd|jddddS)NZWM_DELETE_WINDOWrr)rrrr%r) rrZwm_titleZprotocolZdestroyrrZgrid_columnconfigureZgrid_rowconfigure)r"rrrstitler#r#r$rs  zHelpWindow.__init__N)rNrOrPrQrr#r#r#r$rs rc Csttttttddddd}ttttd}t|d+}t|d}|D] }||d q(Wd n1s>wYWd n1sMwYt|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.htmlrbwb Nz copied to )rrr__file__rpwriterstripprint)srcZdstZinnoutliner#r#r$ copy_strips  rcCs4ttttd}t|sdSt||dtdS)z7Create HelpWindow; called from Idle Help event handler.rNzIDLE Help (%s))rrrrrrr)rrrsr#r#r$ show_idlehelpsr__main__)rTzidlelib.idle_test.test_helprF) verbosityexit)runN)"rQZ html.parserrZos.pathrrrrplatformrZtkinterrr r Z tkinter.ttkr r r rrrZidlelib.configrrrSrrrrrNZunittestrTZidlelib.idle_test.htestrr#r#r#r$s(    ~*