a
    zez                      @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlmZ dadddZG dd	 d	ZG d
d de	ZG dd de	Zdd Zedkreejdkrd dlmZ edddd d dlmZ ee dS )    N)idleConf)pyshell)TreeNodeTreeItemScrolledCanvas)ListedToplevelc                 C   s   g }|   D ]\}}|d u s&|j|krt|dr|jr|j|krg }|jD ]F}t|tdu rd|}n"|j}|j|jkr|j d| }|| qJ| jdd|7  _|| q|S )Nsuper .z({})z, )	itemsmodulehasattrr   nametypeappendformatjoin)Z
child_dictmodnameZobskeyobjZsuperssupZsname r   %/usr/lib/python3.9/idlelib/browser.pytransform_children   s    
r   c                   @   s>   e Zd ZdddddZdddZdd	 Zd
d Zdd ZdS )ModuleBrowserF)_htest_utestc                C   s$   || _ || _|| _|| _|   d S N)masterpathr   r   init)selfr   r   r   r   r   r   r   __init__A   s
    zModuleBrowser.__init__Nc                 C   s   | j   | j  d S r   )topZdestroynode)r!   eventr   r   r   closeY   s    
zModuleBrowser.closec           	      C   s   | j }| js| jstjnt|}|jatj	
  t| | _}|d| j |d| j | jr|d| | d f  |   |  t }t|dd }t||ddd	}|jjdd
d |  }t|jd | | _}| js|  |   d S )NZWM_DELETE_WINDOWz<Escape>z+%d+%d   Znormal
backgroundr      )bgZhighlightthicknessZ	takefocusZboth)expandfill)!r   r   r   r   flistZPyShellFileListopen	file_openpyclbrZ_modulesclearr   r#   protocolr&   bindZgeometryZwinfo_rootxZwinfo_rootysettitleZ	focus_setr   ZCurrentThemeZGetHighlightr   framepackrootnoder   Zcanvasr$   updater+   )	r!   rootr-   r#   Zthemer(   Zscitemr$   r   r   r   r    ^   s4    
zModuleBrowser.initc                 C   s*   | j dtj| j  | j d d S )NzModule Browser - zModule Browser)r#   Zwm_titleosr   basenameZwm_iconnamer!   r   r   r   r4   }   s    zModuleBrowser.settitlec                 C   s
   t | jS r   )ModuleBrowserTreeItemr   r=   r   r   r   r7      s    zModuleBrowser.rootnode)N)__name__
__module____qualname__r"   r&   r    r4   r7   r   r   r   r   r   :   s
   
r   c                   @   sD   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd Zdd Z	dS )r>   c                 C   s
   || _ d S r   )file)r!   rB   r   r   r   r"      s    zModuleBrowserTreeItem.__init__c                 C   s   t j| jS r   )r;   r   r<   rB   r=   r   r   r   GetText   s    zModuleBrowserTreeItem.GetTextc                 C   s   dS )Npythonr   r=   r   r   r   GetIconName   s    z!ModuleBrowserTreeItem.GetIconNamec                 C   s   dd |   D S )Nc                 S   s   g | ]}t |qS r   ChildBrowserTreeItem.0r   r   r   r   
<listcomp>       z4ModuleBrowserTreeItem.GetSubList.<locals>.<listcomp>)listchildrenr=   r   r   r   
GetSubList   s    z ModuleBrowserTreeItem.GetSubListc                 C   s>   t j| jdd  dkrd S t j| js0d S t| j d S N.py)r;   r   normcaserB   existsr/   r=   r   r   r   OnDoubleClick   s
    z#ModuleBrowserTreeItem.OnDoubleClickc                 C   s   t j| jdd  dkS rN   )r;   r   rQ   rB   r=   r   r   r   IsExpandable   s    z"ModuleBrowserTreeItem.IsExpandablec                 C   sp   t j| j\}}t j|\}}t j|dkr6g S zt||gtj }W n t	yd   g  Y S 0 t
||S )NrP   )r;   r   splitrB   splitextrQ   r0   Zreadmodule_exsysImportErrorr   )r!   dirbaser   extZtreer   r   r   rL      s    
z"ModuleBrowserTreeItem.listchildrenN)
r?   r@   rA   r"   rC   rE   rM   rS   rT   rL   r   r   r   r   r>      s   r>   c                   @   s<   e Zd Zdd Zdd Zdd Zdd Zd	d
 Zdd ZdS )rG   c                 C   s    || _ |j| _t|tj| _d S r   )r   r   
isinstancer0   ZFunction
isfunction)r!   r   r   r   r   r"      s    zChildBrowserTreeItem.__init__c                 C   s$   | j }| jrd| d S d| S d S )Nzdef z(...)zclass )r   r]   )r!   r   r   r   r   rC      s    zChildBrowserTreeItem.GetTextc                 C   s   | j r
dS dS d S )NrD   Zfolder)r]   r=   r   r   r   rE      s    z ChildBrowserTreeItem.GetIconNamec                 C   s   | j ji kS r   )r   childrenr=   r   r   r   rT      s    z!ChildBrowserTreeItem.IsExpandablec                 C   s   dd t | jjD S )Nc                 S   s   g | ]}t |qS r   rF   rH   r   r   r   rJ      s   z3ChildBrowserTreeItem.GetSubList.<locals>.<listcomp>)r   r   r^   r=   r   r   r   rM      s    
zChildBrowserTreeItem.GetSubListc              	   C   s:   zt | jj}|| jj W n ttfy4   Y n0 d S r   )r/   r   rB   ZgotolinelinenoOSErrorAttributeError)r!   Zeditr   r   r   rS      s
    z"ChildBrowserTreeItem.OnDoubleClickN)	r?   r@   rA   r"   rC   rE   rT   rM   rS   r   r   r   r   rG      s   rG   c                 C   sH   t tjdkrtjd }nt}G dd dt}dd }t| |dd d S )Nr)   c                   @   s   e Zd Zdd ZdS )z'_module_browser.<locals>.Nested_in_funcc                   S   s   d S r   r   r   r   r   r   nested_in_class   rK   z7_module_browser.<locals>.Nested_in_func.nested_in_classN)r?   r@   rA   rb   r   r   r   r   Nested_in_func   s   rc   c                  S   s   G dd d} d S )Nc                   @   s   e Zd ZdS )z;_module_browser.<locals>.closure.<locals>.Nested_in_closureN)r?   r@   rA   r   r   r   r   Nested_in_closure   rK   rd   r   )rd   r   r   r   closure   s    z _module_browser.<locals>.closureT)r   )lenrW   argv__file__r   r   )parentrB   rc   re   r   r   r   _module_browser   s    rj   __main__r)   )mainzidlelib.idle_test.test_browser   F)	verbosityexit)run)N)r;   r0   rW   Zidlelib.configr   Zidlelibr   Zidlelib.treer   r   r   Zidlelib.windowr   r/   r   r   r>   rG   rj   r?   rf   rg   Zunittestrl   Zidlelib.idle_test.htestrp   r   r   r   r   <module>   s$   
 M4-