
ΆIX*                 @   sH  d  Z  d d l m Z d d l m Z m Z m Z m Z m Z d d l	 m
 Z
 m Z m Z m Z m Z m Z m Z d d l	 m Z d d l m Z d Z e r d d l m Z Gd	 d
   d
 e  Z Gd d   d e  Z Gd d   d e  Z Gd d   d e  Z d d   Z d d   Z e d k rDd d l m Z e e  d S)a   help.py: Implement the Idle help menu.
Contents are subject to revision at any time, without notice.


Help => About IDLE: diplay About Idle dialog

<to be moved here from aboutDialog.py>


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)abspathdirnameisdirisfilejoin)TkToplevelFrameText	ScrollbarMenu
Menubutton)font)idleConfF)r   c               @   sU   e  Z d  Z d Z d d   Z d d d  Z d d   Z d	 d
   Z d d   Z d 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.
    c             C   s   t  j |  d d | |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _	 d |  _
 d |  _ g  |  _ d |  _ d  S)NZconvert_charrefsT Fr   )r   __init__texttagschartagsshowhdrlinklevelprehprefix	nested_dl
simplelisttocheader)selfr    r!   B/afs/.cs.wisc.edu/s/python-3.5.2/amd64_ubu16/lib/python3.5/help.pyr   3   s    											zHelpParser.__init__   c             C   s>   |  j  | 7_  |  j  d k r$ d n d t |  j   |  _ d  S)Nr   r   l)r   strr   )r    amtr!   r!   r"   indentB   s    zHelpParser.indentc             C   s  d } x& | D] \ } } | d k r | } q Wd } | d k rY | d k rY d |  _  n8| d k r} | d k r} d |  _  n| d k r | d	 k r d
 } n| d k r | d k r d |  _ n| d k r | d k r d |  _ n| d k r d |  _ n| d# k rG| j d  d$ k r1d } d |  _ n	 d |  _ |  j   nJ| d k rn|  j d k rd |  _ n#| d k r|  j rd n d } n | d k r|  j sd
 n d } d |  _ n | d k r|  j   d } n | d k rd |  _ |  j  r|  j j	 d d
  d |  _
 nv | d k r?| d k r?d |  _ nR | d k rW| |  _
 n: | d% k r|  j  rd |  _ |  j j	 d d
  | |  _
 |  j  r|  j j	 d | |  j
 |  j f  d" S)&zHandle starttags in help.html.r   classZdivsectionTZsphinxsidebarFpfirstz

spanr   ZversionmodifiedemulolZsimpler#   
Zdlr   Zliz
* z

* ZdtddendpreblockaZ
headerlinkh1h2h3N)r.   r/   )r6   r7   )r   r   findr   r'   r   r   r   r   insertr   r   r   )r    tagZattrsclass_r4   vsr!   r!   r"   handle_starttagF   sd    
		
							zHelpParser.handle_starttagc             C   s   | d k rJ |  j  d  |  j r |  j j |  j |  j j d  f  nm | d k rb d |  _ nU | d	 k rz d
 |  _ n= | d k r d
 |  _	 d |  _
 n | d k r |  j  d d  d S)zHandle endtags in help.html.r5   r6   r7   r   r:   r,   r-   r   r4   Fr   r.   r1   r/   r&   r#   N)zh1zh2zh3)zspanzem)zulzddzolr8   )r'   r   r   appendr   r   indexr   r   r   r   )r    r;   r!   r!   r"   handle_endtag|   s    	(	zHelpParser.handle_endtagc             C   s   |  j  r |  j r |  j r" | n | j d d  } |  j d k r_ | d | j d   |  _ |  j d
 k r |  j d k r | d t |  j   |  j k r | t |  j  d  j   } |  j	 | 7_	 |  j
 j d	 | |  j |  j f  d S)z"Handle date segments in help.html.r0    r5   r   r6   r7   r   Nr2   )zh1zh2zh3)r   r   r   replacer   rA   r   lenstripr   r   r:   r   )r    datadr!   r!   r"   handle_data   s    !"zHelpParser.handle_dataN)	__name__
__module____qualname____doc__r   r'   r?   rB   rI   r!   r!   r!   r"   r   *   s   6r   c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)HelpTextzDisplay help.html.c       	      C   s1  t  j d d d d d } t  j d d d d d } d | d } t j |  | d	 d
 d d d d d d d | d | |  j d d d g  } |  j d d d g  } | d f |  d <|  j d d | d d f |  j d d | d d f |  j d d | d d f |  j d d | d  d f |  j d! d | d f d" d# |  j d$ d | d% f d& d' d d( d) d* d" d+ |  j d, d& d' d- d' |  j d. d& d/ d- d/ |  j d0 d& d1 d- d1 |  j d2 d& d3 d- d3 t |   |  _ t | d4 d5  } | j	   } Wd6 QRX|  j j
 |  d7 |  d8 <d6 S)9z'Configure tags and feed file to parser.mainZEditorWindowwidthtypeintZheight      wrapZwordZhighlightthicknessr   Zpadx   ZborderwidthZTkDefaultFontZarialZ	helveticaZTkFixedFontZmonacoZcourier   r   r-   Zitalicr5      Zboldr6      r7      r   
backgroundz#f6f6ffr3   
   Zlmargin1   r#   ZreliefZsolidz#eeffccl1Zlmargin2l22   l3K   l4d   encodingzutf-8Ndisabledstate)r   Z	GetOptionr   r   findfontZtag_configurer   parseropenreadZfeed)	r    parentfilenameZuwideZuhighZ
normalfontZ	fixedfontfcontentsr!   r!   r"   r      s0    zHelpText.__init__c             C   s   x | D] } | j    d d   t j d |   D k rd t j d | d d d |   } | j   d S| j    d d   t j d |   D k r | Sq Wd	 S)
z4Return name of first font family derived from names.c             s   s   |  ] } | j    Vq d  S)N)lower).0xr!   r!   r"   	<genexpr>   s    z$HelpText.findfont.<locals>.<genexpr>rootnameexistsTfamilyc             s   s   |  ] } | j    Vq d  S)N)rp   )rq   rr   r!   r!   r"   rs      s   N)rp   tkfontnamesZFontactualfamilies)r    ry   ru   r   r!   r!   r"   rh      s    +zHelpText.findfontN)rJ   rK   rL   rM   r   rh   r!   r!   r!   r"   rN      s   rN   c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)	HelpFramez&Display html text, scrollbar, and toc.c             C   s   t  j |  |  t |  |  } | d |  d <t |  d | j } | j | d <|  j d d d |  j d d d |  j |  j	 d d d d d	 d
  | j	 d d d d d	 d  | j	 d d d d d	 d  d  S)Nr[   commandZyscrollcommandr   weightr#   columnrowstickyZnwnsew   ns)
r
   r   rN   r   yviewsetZrowconfigureZcolumnconfiguretoc_menugrid)r    rl   rm   r   Zscrollr!   r!   r"   r      s    %zHelpFrame.__init__c          	      st   t  |  d d } t | d d } x?   j j D]1 \ } } | j d | d |   f d d   q1 W| | d	 <| S)
z+Create table of contents as drop-down menu.r   ZTOCZtearoffFZlabelr}   c                s     j  |   S)N)r   )dex)r   r!   r"   <lambda>   s    z$HelpFrame.toc_menu.<locals>.<lambda>Zmenu)r   r   ri   r   Zadd_command)r    r   r   ZdropZlblr   r!   )r   r"   r      s    )
zHelpFrame.toc_menuN)rJ   rK   rL   rM   r   r   r!   r!   r!   r"   r|      s   r|   c               @   s"   e  Z d  Z d Z d d   Z d S)
HelpWindowz!Display frame with rendered html.c             C   s   t  j |  |  |  j |  |  j d |  j  t |  |  j d d d d d d  |  j d d d |  j d d d d  S)	NZWM_DELETE_WINDOWr   r   r   r   r   r~   r#   )	r	   r   Zwm_titleprotocolZdestroyr|   r   Zgrid_columnconfigureZgrid_rowconfigure)r    rl   rm   titler!   r!   r"   r      s    %zHelpWindow.__init__N)rJ   rK   rL   rM   r   r!   r!   r!   r"   r      s   r   c              C   s   t  t t t t t     d d d d d  }  t  t t t   d  } t |  d  H } t | d  / } x% | D] } | j | j   d	  qy WWd
 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 hg cpython
    repository.  For 3.x (on Windows), help.html is generated, after
    editing idle.rst in the earliest maintenance version, with
      sphinx-build -bhtml . build/html
      python_d.exe -c "from idlelib.help import copy_strip; copy_strip()"
    After refreshing TortoiseHG workshop to generate a diff,
    check  both the diff and displayed text.  Push the diff along with
    the idle.rst change and merge both into default (or an intermediate
    maintenance version).

    When the 'earlist' version gets its final maintenance release,
    do an update as described above, without editing idle.rst, to
    rebase help.html on the next version of idle.rst.  Do not worry
    about version changes as version is not displayed.  Examine other
    changes and the result of Help -> IDLE Help.

    If maintenance and default versions of idle.rst diverge, and
    merging does not go smoothly, then consider generating
    separate help.html files from separate idle.htmls.
    ZDocZbuildZhtmlZlibraryz	idle.htmlz	help.htmlrbwbs   
Nzidle.html copied to help.html)r   r   r   __file__rj   writerstripprint)srcdstZinnoutliner!   r!   r"   
copy_strip   s    )r   c             C   s?   t  t t t   d  } t |  s+ d St |  | d  d S)z7Create HelpWindow; called from Idle Help event handler.z	help.htmlNz	IDLE Help)r   r   r   r   r   r   )rl   rm   r!   r!   r"   show_idlehelp  s    r   __main__)runN) rM   Zhtml.parserr   Zos.pathr   r   r   r   r   tkinterr   r	   r
   r   r   r   r   r   rx   Zidlelib.configHandlerr   Zuse_ttkZtkinter.ttkr   rN   r|   r   r   r   rJ   Zidlelib.idle_test.htestr   r!   r!   r!   r"   <module>   s"   (4o* 