&l6dZddlmZddlmZmZmZmZddlm Z ddl m Z m Z m Z ddlmZmZmZmZddl mZddlmZdd lmZGd d eZGd d e ZGddeZGdde ZdZdZedk(r ddl m!Z!e!dddddl"m#Z#e#eyy)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 the text part of idle.html to help.html while rstripping each line. show_idlehelp - Create HelpWindow. Called in EditorWindow.help_dialog. ) HTMLParser)abspathdirnameisfilejoin)python_version)ToplevelTextMenu)Frame Menubutton ScrollbarStylefont)idleConf) color_configc0eZdZdZdZddZdZdZdZy) 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. ctj|d||_d|_d|_d|_d|_d|_d|_d|_ d|_ g|_ d|_ d|_ y)NT)convert_charrefsFr)r__init__texttagschartagshdrlinklevelprehprefix nested_dl simplelisttocheaderprevtag)selfrs 3/opt/alt/python312/lib64/python3.12/idlelib/help.pyrzHelpParser.__init__4sfD48        c|xj|z c_|jdk(rd|_ydt|jz|_y)z#Change indent (+1, 0, -1) and tags.rrlN)rstrr)r&amts r'indentzHelpParser.indentCs4 c **/B s3tzz?/B r(cd}|D] \}}|dk(s |}d}|dk(rO|jrC|jds4|jjdd}|r|jsdnd}nD|d k(r|d k(r d |_n1|d k(r|d k(r d |_n|d k(r d |_n|d vr6|j ddk7r d}d|_nd|_|jn|dk(r|jdkDrd|_ n|dk(rd}n|dk(r|jsdnd}d|_ n|dk(r|jd}n}|d k(r+d|_ |jjddd|_ nM|dk(r |dk(rd|_ n;|dk(r||_ n.|dvr*d|_|jjdd||_ |jjd||j|jfd|f|_y)zHandle starttags in help.html.rclassprzend-1c linestartzend-1cz  spanrversionmodifiedem)ulolsimpleTFdlliz * dtddendpreblocka headerlinkh1)h2h3N)r%rgetisspacerfindr"r-rr!rinsertrrr$)r&tagattrsclass_r?vslastlines r'handle_starttagzHelpParser.handle_starttagHsDAqG|  #:$,,t||Ayy}}%7BH"8+;+;+=4A F]v!DM F]v):: DM D[ DM L {{8$*"&"' KKM D[zzA~!% D[A D["nn$A"DN D[ KKMA E\DH II  UF +"DI CZFl2DL D[DI L DK II  UF +DI DIIt}}#=>c{ r(cz|dvrl|jdk(sJ|dk(rdn|dk(rdnd}|jj||jz|jj dfd|_nB|d vrd|_n6|d k(rd |_n)|d k(rd |_ d|_n|d vr|jdd |f|_ y)zHandle endtags in help.html.rArBrCrrCz rBz rrG)r2r4r?Fr)r5r<r6r8N) rr#appendr$rindexrrrrr-r%)r&rHr-s r' handle_endtagzHelpParser.handle_endtag{s $ $::? "?$'4Kj #t f  HHOOVDKK/1JK LDI N "DM CZ DL E\DHDI & & KKOs| r(c|js|jr|n|jdd}|jdk(r; |d|j d|_|j j sd|_|jdvro|j dk7r=|dt|j |j k(r|t|j d}|xj|jz c_ |jjd||j|jfyy#t$r d|_YwxYw) z"Handle date segments in help.html.r1 rANrrPrr=)rrreplacerrRr isdigit ValueErrorlenr$striprrGr)r&datads r' handle_datazHelpParser.handle_datas||dll4&=AyyD &#$]aggcl#3DL<<//1') yy..LLB&aDLL)*dll:#dll+,-A qwwy( II  UA 4=='A B"&#%DL&s:D**D=<D=N)) __name__ __module__ __qualname____doc__rr-rNrSr]r(r'rr+s# C 1#f$(Cr(rceZdZdZdZdZy)HelpTextzDisplay help.html.c tjdddd}tjdddd}d|zdz}tj||d d d d || |j gd }|j gd}t ||df|d<|j d|ddf|j d|ddf|j d|ddf|j d|ddf|j d|df|d}|j d|dfd| |j d!dd"|j d#d$d$"|j d%d&d&"|j d'd(d("t||_t|d)*5}|j} d+d+d+|jj d,|d-<y+#1swY*xYw).z'Configure tags and feed file to parser.main EditorWindowwidthint)typeheightwordr)wraphighlightthicknesspadx borderwidthrirl) TkDefaultFontarial helvetica) TkFixedFontmonacocourier rr4italicrrAboldrBrCrselectbackgroundr> )rlmargin1 backgroundl1)rlmargin2l22l3Kl4dutf-8encodingNdisabledstate) r GetOptionr rfindfontr tag_configurerparseropenreadfeed) r&parentfilenameuwideuhigh normalfont fixedfontprebackfcontentss r'rzHelpText.__init__s""6>7O""6>8%PE Q dFA!5 H]]#JK MM"FG T"B'V  4z2x&@A 4z2v&>? 4z2v&>? 4z2v&>? 5 27)* :YOb&-  / 4"r: 4"r: 4"r: 4#< & (W -vvxH. ""W . -s GG c(|D]}|jdtj|Dvr-tj|d|}|j dcS|jdtj |Dvs|cSy)z4Return name of first font family derived from names.c3<K|]}|jywNlower.0xs r' z$HelpText.findfont..sK3Ja 3J)rootT)nameexistsrfamilyc3<K|]}|jywrrrs r'rz$HelpText.findfont..s"G+Ea#$'')+ErN)rtkfontnamesFontactualfamilies)r&rrrs r'rzHelpText.findfontsxDzz|K6<r(receZdZdZdZdZy) HelpFramez&Display html text, scrollbar, and toc.ctj||t||x|_}t ||_d|d<|j j d|d|j|x|_}t||jx|_ }|j|d<|jdd |jdd |jddd |jddd |jdd d y)Nzhelpframe.TFramestyler)r)commandyscrollcommandrr^weightnw)rowcolumnstickynsewns)r rrerrr configuretoc_menur#ryviewscrollset rowconfigurecolumnconfiguregrid)r&rrrr#rs r'rzHelpFrame.__init__s tV$#D(33 D6] *W  /Dz$HelpFrame.toc_menu..s tzz#r()labelrmenu)r r rr# add_command)r&rr#droplblrs ` r'rzHelpFrame.toc_menusUE*C' HC   330N  O(F  r(N)r_r`rarbrrrcr(r'rrs,2 r(rceZdZdZdZy) HelpWindowz!Display frame with rendered html.c4tj|||j||jd|jt |||_|j jddd|jdd|jddy)NWM_DELETE_WINDOWrr)rrrr^r) r rwm_titleprotocoldestroyrframergrid_columnconfiguregrid_rowconfigure)r&rrtitles r'rzHelpWindow.__init__s{$' e ($,,7tX.  qa7 !!!A!. q+r(N)r_r`rarbrrcr(r'rrs ',r(rc ttttttddddd}ttttd}t |dd 5}t |d d 5}d }|D]3}d |vrd }d|vrn'|s|j |j dz5ddddddt|d|y#1swY"xYw#1swY&xYw)asCopy the text part of idle.html to idlelib/help.html while 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 change 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. Docbuildhtmllibraryz idle.html help.htmlrrrwFz
Tz
r1Nz copied to )rrr__file__rwriterZprint)srcdstinnoutcopylines r' copy_striprs. wwwwx'89:; 7FI{ rs4#22#((;;"#*tCtCn)t)X8 , ,"$JL z &!%@+  r(