\dO.TdZddlmZddlmZmZmZmZddlm Z ddl m Z m Z m Z ddlmZmZmZmZddl mZddlmZGd d eZGd d e ZGd deZGdde ZdZdZedkr'ddlmZedddddl 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)idleConfc2eZdZdZdZd dZdZdZdZdS) 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|_ d|_ g|_ d|_ d|_dS)NT)convert_charrefsFr)r__init__texttagschartagsshowhdrlinklevelprehprefix nested_dl simplelisttocheaderprevtag)selfrs ..\python\lib\idlelib\help.pyrzHelpParser.__init__3swD48888         cx|xj|z c_|jdkrdndt|jz|_dS)z#Change indent (+1, 0, -1) and tags.rrlN)rstrr)r&amts r'indentzHelpParser.indentCs8 c *//BBs3tz??/B r(cjd}|D] \}}|dkr|}d}|dkr|dgkr d|_n|dkr|dkr d|_n|d krK|jrD|jd s7|jd d }|r|sd nd}nj|dkr|dkr d|_nU|dkr|dkr d|_n@|dkr d|_n1|dvr?|ddkr d}d|_nd|_|n|dkr|j d krd|_ n|dkr |jrdnd}n|dkr|j sd nd}d|_ n|dkr|d}n|dkr1d|_ |jr|j dd d|_ nV|dkr|dkrd|_nB|d kr||_ n4|d!vr0|jr"d|_|j dd ||_ |jr(|j d||j |jfd|f|_d"S)#zHandle starttags in help.html.rclasssection)ididleTdivclearerFprzend-1c linestartzend-1cz  spanrversionmodifiedem)ulolsimpledlliz * z * dtddendpreblocka headerlinkh1)h2h3N)rr%rgetisspacerfindr"r.rr!rinsertrrr$)r&tagattrsclass_rEvslastlines r'handle_starttagzHelpParser.handle_starttagHs  DAqG||  )  .)9 9 9DII E\\f 11DII CZZDLZaZy}}%7BBH"G8+;+;+=+=G4AA F]]v!DMM F]]v)::: DMM D[[ DMM L {{8$$**"&"' KKMMMM D[[zA~~!% D[[/7xAA D[["n6$A"DNN D[[ KKMMMAA E\\DHy 0   ///"DII CZZFl22DLL D[[DII L y 0     ///DI 9 C I  UA 4='A B B Bc{ r(c|dvrj|jdksJ|jrN|dkrdn |dkrdnd}|j||jz|jdfd|_nH|d vrd|_n<|d krd |_ n.|d krd |_ d|_n|d vr| dd |f|_ dS)zHandle endtags in help.html.rGrHrIrrIz rHz rrM)r8r:rEFr)r;rBr<r>N) rrr#appendr$rindexrrrrr.r%)r&rNr.s r' handle_endtagzHelpParser.handle_endtags $ $ $:????y Q(+t **$'4KK&& !3TY__X5N5N OPPPDII N " "DMM CZZ DLL E\\DHDII & & & KKOOOs| r(c6|jr|js|jr|n|dd}|jdkr; |d|d|_n#t$r d|_YnwxYw|jdvrn|jdkrA|dt|j|jkr|t|jd}|xj | z c_ |j d||j|j fdSdSdS) z"Handle date segments in help.html.r7 rGrrrVNrC)rrrreplacerrXr ValueErrorlenr$striprrMr)r&datads r' handle_datazHelpParser.handle_datas8 9 CT\ C=dll4&=&=AyD  &#$Qqwws||^#4DLL!&&&#%DLLL&y...LB&&aDL)))*dl::#dl++,,-A qwwyy( I  UA 4='A B B B B B C C C Cs"AA32A3N)r)) __name__ __module__ __qualname____doc__rr.rTrYrbr(r'rr*sx CCCC 8#8#8#t$$$*CCCCCr(rceZdZdZdZdZdS)HelpTextzDisplay help.html.c tjdddd}tjdddd}d|zdz}tj||d d d d || |gd }|gd}|df|d<|d|ddf|d|ddf|d|ddf|d|ddf|d|dfd|d|dfd d!d"d#$|d%d d &|d'd(d(&|d)d*d*&|d+d,d,&t ||_t|d-.5}| }d/d/d/n #1swxYwY|j |d0|d1<d/S)2z'Configure tags and feed file to parser.main EditorWindowwidthint)typeheightwordr)wraphighlightthicknesspadx borderwidthrmrp) TkDefaultFontarial helvetica) TkFixedFontmonacocourier rr:italicrrGboldrHrIrz#f6f6ff)r backgroundrD r)solidz#eeffcc)rlmargin1rxreliefrl1)rlmargin2l22l3Kl4dzutf-8)encodingNdisabledstate) r GetOptionr rfindfont tag_configurerparseropenreadfeed) r&parentfilenameuwideuhigh normalfont fixedfontfcontentss r'rzHelpText.__init__s"6>7OOO"6>8%PPPE Q dFA!5 H H H H]]#J#J#JKK MM"F"F"FGG "B'V  4z2x&@AAA 4z2v&>??? 4z2v&>??? 4z2v&>??? 5 29MMM :YObg)  E E E 4"r::: 4"r::: 4"r::: 4#<<< && (W - - - vvxxH                """"W s.GGGcJ|D]}|dtj|Dvr3tj|d|}|dcS|dtj|Dvr|cSdS)z4Return name of first font family derived from names.c3>K|]}|VdSNlower.0xs r' z$HelpText.findfont..s*KKa KKKKKKr()rootT)nameexistsrfamilyc3>K|]}|VdSrrrs r'rz$HelpText.findfont..sF"G"G&'#$''))"G"G"G"G"G"Gr(N)rtkfontnamesFontactualfamilies)r&rrrs r'rzHelpText.findfonts  Dzz||KK6z$HelpFrame.toc_menu..stzz#r()labelrmenu)r r rr# add_command)r&rr#droplblrs ` r'rzHelpFrame.toc_menusyE***C'''  P PHC   330N0N0N0N0N  O O O OF  r(N)rcrdrerfrrrgr(r'rrs8,,222 r(rceZdZdZdZdS) HelpWindowz!Display frame with rendered html.c8tj|||||d|jt ||ddd|dd|dddS)NWM_DELETE_WINDOWrr)rrrr)r) r rwm_titleprotocoldestroyrrgrid_columnconfiguregrid_rowconfigure)r&rrtitles r'rzHelpWindow.__init__s$''' e ($,777$!!&&aQv&FFF !!!A!... q+++++r(N)rcrdrerfrrgr(r'rrs)'',,,,,r(rc &ttttttddddd}ttttd}t |d5}t |d5}|D],}||d z- d d d n #1swxYwYd d d n #1swxYwYt|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. Docbuildhtmllibraryz idle.html help.htmlrbwb Nz copied to )rrr__file__rwriterstripprint)srcdstinnoutlines r' copy_striprsz. wwwwx'8'899::;; 7FI{ < rs4#"""""222222222222######((((((((((;;;;;;;;;;;;""""""######{C{C{C{C{C{C{C{C|'''''t'''T8,,,,,,,,$$$@FFF zD &!%@@@@++++++C  r(