a XC?hK.@sdZddlmZddlmZmZmZmZddlm Z ddl m Z m Z m Z ddlmZmZmZmZddl mZddlmZGd d d eZGd d d e ZGd ddeZGddde ZddZddZedkrddlmZeddddddl 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: 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#1/opt/alt/python39/lib64/python3.9/idlelib/help.pyr3szHelpParser.__init__cCs0|j|7_|jdkrdn dt|j|_dS)z#Change indent (+1, 0, -1) and tags.rrlN)rstrr)r"Zamtr#r#r$indentCszHelpParser.indentcCs8d}|D]\}}|dkr|}qd}|dkr<|dkr|dkr||_ n,|d vr |jrd|_|j dd ||_ |jr*|j d||j |jfd|f|_d!S)"zHandle starttags in help.html.rclassZdivZsectionTZ sphinxsidebarFprzend-1c linestartzend-1cz  spanrZversionmodifiedem)ulolsimpleZdlZliz * z * ZdtddendpreblockaZ headerlinkh1)h2h3N)rr!rgetisspacerfindrr(rrrinsertrrr )r"tagattrsZclass_r5vsZlastliner#r#r$handle_starttagHsh                zHelpParser.handle_starttagcCs|dvr^|jdksJ|jrV|dkr(dn|dkr4dnd}|j||j|jdfd|_nH|d vrnd|_n8|d kr~d |_ n(|d krd |_ d|_n|d vr| dd |f|_ dS)zHandle endtags in help.html.r6r7r8rr8z r7z rr<)r,r-r5Fr)r.r2r/r1N) rrrappendr rindexrrrrr(r!)r"r=r(r#r#r$ handle_endtags&   zHelpParser.handle_endtagcCs|jr|js|jr|n |dd}|jdkr^z|d|d|_Wnty\d|_Yn0|jdvr|jdkr|dt|j|jkr|t|jd}|j | 7_ |j d||j|j fdS) z"Handle date segments in help.html.r+ r6rrrBNr3)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@s 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/n1sf0Y|j |d0|d1<d/S)2z'Configure tags and feed file to parser.mainZ EditorWindowwidthint)typeheightZwordr)ZwrapZhighlightthicknessZpadx borderwidthrTrW)Z TkDefaultFontZarialZ helvetica)Z TkFixedFontZmonacoZcourier rr-Zitalicrr6Zboldr7r8rz#f6f6ff)r backgroundr4 r%Zsolidz#eeffcc)rlmargin1r[Zreliefr`l1)rcZlmargin2l22l3Kl4dzutf-8)encodingNZdisabledstate) rZ GetOptionr rfindfontZ tag_configurerparseropenreadZfeed) r"parentfilenameZuwideZuhighZ normalfontZ fixedfontfcontentsr#r#r$rs4    ( zHelpText.__init__cCsr|D]h}|ddtj|dDvrFtj|d|d}|dS|ddtj|dDvr|SqdS) z4Return name of first font family derived from names.css|]}|VqdSNlower.0xr#r#r$ z$HelpText.findfont..)rootT)nameexistsr}Zfamilycss|]}|VqdSrurvrxr#r#r$r{sN)rwtkfontnamesZFontZactualZfamilies)r"rr~rr#r#r$rms  zHelpText.findfontN)rNrOrPrQrrmr#r#r#r$rRsrRc@s eZdZdZddZddZdS) 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.TFramestyler`)r`)commandZyscrollcommandrr%ZweightZnw)rowcolumnstickynsewns)r rrRrrrZ configuretoc_menurr yviewscrollsetZ rowconfigureZcolumnconfiguregrid)r"rqrrrrrr#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 |Sru)r)dexrr#r$r|z$HelpFrame.toc_menu..)ZlabelrZmenu)r r rnrZ add_command)r"rrZdropZlblrr#rr$rs   zHelpFrame.toc_menuN)rNrOrPrQrrr#r#r#r$rsrc@seZdZdZddZdS) HelpWindowz!Display frame with rendered html.cCsZt|||||d|jt||jdddd|jddd|jddddS)NZWM_DELETE_WINDOWrr)rrrr%r) rrZwm_titleZprotocolZdestroyrrZgrid_columnconfigureZgrid_rowconfigure)r"rqrrtitler#r#r$rs   zHelpWindow.__init__N)rNrOrPrQrr#r#r#r$rsrc Csttttttddddd}ttttd}t|dV}t|d,}|D]}||d qPWd n1s|0YWd n1s0Yt|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__rowriterstripprint)srcZdstZinnoutliner#r#r$ copy_strips  PrcCs4ttttd}t|sdSt||dtdS)z7Create HelpWindow; called from Idle Help event handler.rNzIDLE Help (%s))rrrrrrr)rqrrr#r#r$ show_idlehelpsr__main__)rSzidlelib.idle_test.test_helprF) verbosityexit)runN)"rQZ html.parserrZos.pathrrrrplatformrZtkinterrr r Z tkinter.ttkr r r rrrZidlelib.configrrrRrrrrrNZunittestrSZidlelib.idle_test.htestrr#r#r#r$s$    ~*