a
    zeK.                     @   s   d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
mZmZ d dlmZmZmZmZ d dl	mZ d dlmZ G dd	 d	eZG d
d deZG dd deZG dd de
Zdd Zdd Zedkrd dlmZ edddd d dlm Z  e e dS )    )
HTMLParser)abspathdirnameisfilejoin)python_version)ToplevelTextMenu)Frame
Menubutton	ScrollbarStylefont)idleConfc                   @   s6   e Zd Zdd ZdddZdd Zdd	 Zd
d ZdS )
HelpParserc                 C   s`   t j| dd || _d| _d| _d| _d| _d| _d| _d| _	d| _
d| _g | _d| _d | _d S )NT)Zconvert_charrefs Fr   )r   __init__texttagschartagsshowhdrlinklevelprehprefix	nested_dl
simplelisttocheaderprevtag)selfr    r#   "/usr/lib/python3.9/idlelib/help.pyr   3   s    zHelpParser.__init__   c                 C   s0   |  j |7  _ | j dkrdndt| j  | _d S )Nr   r   l)r   strr   )r"   Zamtr#   r#   r$   indentC   s    zHelpParser.indentc                 C   s8  d}|D ]\}}|dkr|}qd}|dkr<|dkr<d| _ n|dkrV|dkrVd| _ n|dkr| jr| jd	 s| jd
d}|r| sdnd}nv|dkr|dkrd| _n\|dkr|dkrd| _nB|dkrd| _n0|dv r|ddkrd}d| _nd| _|   n|dkr,| j	d	kr
d| _
n|dkrH| jrBdnd}n|dkrj| j
s^dnd}d| _
n|dkr|   d}n|dkrd| _| j r| jdd d| _nZ|dkr|dkrd| _n>|dkr|| _n,|d v r
| j rd| _| jdd || _| j r*| jd|| j| jf d|f| _d S )!Nr   classZdivsectionTZsphinxsidebarFpr   zend-1c linestartzend-1cz


spanr   Zversionmodifiedem)ulolsimpleZdlZliz
* z

* ZdtddendpreblockaZ
headerlinkh1)h2h3)r   r!   r   getisspacer   findr   r(   r   r   r   insertr   r   r    )r"   tagattrsclass_r6   vsZlastliner#   r#   r$   handle_starttagH   sh    













zHelpParser.handle_starttagc                 C   s   |dv rP| j rH|dkrdn|dkr&dnd}| j|| j | jdf d| _nH|dv r`d| _n8|d	krpd
| _n(|dkrd
| _	d| _n|dv r| 
d d
|f| _d S )Nr7   r8   r9   r9   z        r8   z    r   r=   )r-   r.   r6   Fr   )r/   r3   r0   r2   )r   r   appendr    r   indexr   r   r   r   r(   r!   )r"   r>   r(   r#   r#   r$   handle_endtag   s$    
zHelpParser.handle_endtagc                 C   s   | j r| js| jr|n
|dd}| jdkr^z|d|d | _W n ty\   d| _Y n0 | jdv r| jdkr|dt| j | jkr|t| jd  }|  j	|
 7  _	| jd|| j| jf d S )Nr,    r7   r   r   rD   r4   )r   r   r   replacer   rF   r   
ValueErrorlenr    stripr   r=   r   )r"   datadr#   r#   r$   handle_data   s    


zHelpParser.handle_dataN)r%   )__name__
__module____qualname__r   r(   rC   rG   rO   r#   r#   r#   r$   r   *   s
   	
:r   c                   @   s   e Zd Zdd Zdd ZdS )HelpTextc           	   
   C   s  t jddddd}t jddddd}d| d }tj| |d	d
dd
||d | g d}| g d}|df| d< | jd|ddfd | jd|ddfd | jd|ddfd | jd|ddfd | jd|dfdd | jd|dfd d!d"d#d$ | jd%d d d& | jd'd(d(d& | jd)d*d*d& | jd+d,d,d& t| | _t|d-d.}|	 }W d    n1 sf0    Y  | j
| d/| d0< d S )1NmainZEditorWindowwidthint)typeheight      Zwordr      )wrapZhighlightthicknessZpadxborderwidthrU   rX   )ZTkDefaultFontZarialZ	helvetica)ZTkFixedFontZmonacoZcourier   r   r.   Zitalicr   r7      Zboldr8      r9      r   z#f6f6ff)r   
backgroundr5   
      r%   Zsolidz#eeffcc)r   lmargin1r]   Zreliefrb   l1)re   Zlmargin2l22   l3K   l4d   zutf-8)encoding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      s4    
(zHelpText.__init__c                 C   sr   |D ]h}|  dd tj| dD v rFtj|d| d}| d   S |  dd tj| dD v r|  S qd S )Nc                 s   s   | ]}|  V  qd S Nlower.0xr#   r#   r$   	<genexpr>       z$HelpText.findfont.<locals>.<genexpr>)rootT)nameexistsr   familyc                 s   s   | ]}|  V  qd S rx   ry   r{   r#   r#   r$   r~      s   )rz   tkfontnamesZFontactualfamilies)r"   r   r   r   r#   r#   r$   rp      s    
zHelpText.findfontN)rP   rQ   rR   r   rp   r#   r#   r#   r$   rS      s   rS   c                   @   s   e Zd Zdd Zdd ZdS )	HelpFramec                 C   s   t | | t| | | _}t|| _d| d< | jjd|d d | | | _}t	| |j
d | _}|j|d< | jddd	 | jddd	 |jddd
d |jdddd |jdddd d S )Nzhelpframe.TFramestylerb   )rb   )commandZyscrollcommandr   r%   ZweightZnw)rowcolumnstickynsew   ns)r   r   rS   r   r   r   Z	configuretoc_menur   r   yviewscrollsetZrowconfigureZcolumnconfiguregrid)r"   rt   ru   r   r   r   r#   r#   r$   r      s    

zHelpFrame.__init__c                    sP   t | dd}t|dd} jjD ]"\}}|j||f fdd	d q ||d< |S )	NZTOCr   F)Ztearoffc                    s
     | S rx   )r   )dexr   r#   r$   <lambda>   r   z$HelpFrame.toc_menu.<locals>.<lambda>)Zlabelr   Zmenu)r   r
   rq   r   Zadd_command)r"   r   r   ZdropZlblr   r#   r   r$   r      s    zHelpFrame.toc_menuN)rP   rQ   rR   r   r   r#   r#   r#   r$   r      s   r   c                   @   s   e Zd Zdd ZdS )
HelpWindowc                 C   sZ   t | | | | | d| j t| |j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"   rt   ru   titler#   r#   r$   r      s    
zHelpWindow.__init__N)rP   rQ   rR   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V}t|d,}|D ]}|| d	  qPW d    n1 s|0    Y  W d    n1 s0    Y  t|  d
|  d S )NZDocZbuildZhtmlZlibraryz	idle.html	help.htmlrbwb   
z copied to )r   r   r   __file__rr   writerstripprint)srcdstZinnoutliner#   r#   r$   
copy_strip   s    
Pr   c                 C   s4   t tttd}t|sd S t| |dt   d S )Nr   zIDLE Help (%s))r   r   r   r   r   r   r   )rt   ru   r#   r#   r$   show_idlehelp  s    r   __main__)rT   zidlelib.idle_test.test_helpr   F)	verbosityexit)runN)!Zhtml.parserr   Zos.pathr   r   r   r   platformr   tkinterr   r	   r
   Ztkinter.ttkr   r   r   r   r   r   Zidlelib.configr   r   rS   r   r   r   r   rP   ZunittestrT   Zidlelib.idle_test.htestr   r#   r#   r#   r$   <module>   s"   ~* 