B
    v9ay                  @   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 }x|   D ]\}}|d ks(|j|krt|dr|jr|j|krg }xP|jD ]F}t|tdkrh|}n"|j}|j|jkr|j d| }|| qNW | jdd|7  _|| qW |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.7/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 )N)topZdestroynode)r    Z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"   Zprotocolr$   Z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   ^   s.    

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   r0   }   s    zModuleBrowser.settitlec             C   s
   t | jS )N)ModuleBrowserTreeItemr   )r    r   r   r   r3      s    zModuleBrowser.rootnode)N)__name__
__module____qualname__r!   r$   r   r0   r3   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 )r9   c             C   s
   || _ d S )N)file)r    r=   r   r   r   r!      s    zModuleBrowserTreeItem.__init__c             C   s   t j| jS )N)r7   r   r8   r=   )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>   s    z4ModuleBrowserTreeItem.GetSubList.<locals>.<listcomp>)listchildren)r    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 )Nz.py)r7   r   normcaser=   existsr-   )r    r   r   r   OnDoubleClick   s
    z#ModuleBrowserTreeItem.OnDoubleClickc             C   s   t j| jdd  dkS )NrF   z.py)r7   r   rG   r=   )r    r   r   r   IsExpandable   s    z"ModuleBrowserTreeItem.IsExpandablec             C   sn   t j| j\}}t j|\}}t j|dkr6g S yt||gtj }W n t	k
rb   g S X t
||S )Nz.py)r7   r   splitr=   splitextrG   r.   Zreadmodule_exsysImportErrorr   )r    dirbaser   ZextZtreer   r   r   rD      s    z"ModuleBrowserTreeItem.listchildrenN)
r:   r;   r<   r!   r>   r@   rE   rI   rJ   rD   r   r   r   r   r9      s   r9   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 )rA   c             C   s    || _ |j| _t|tj| _d S )N)r   r   
isinstancer.   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   rR   )r    r   r   r   r   r>      s    zChildBrowserTreeItem.GetTextc             C   s   | j r
dS dS d S )Nr?   Zfolder)rR   )r    r   r   r   r@      s    z ChildBrowserTreeItem.GetIconNamec             C   s   | j ji kS )N)r   children)r    r   r   r   rJ      s    z!ChildBrowserTreeItem.IsExpandablec             C   s   dd t | jjD S )Nc             S   s   g | ]}t |qS r   )rA   )rB   r   r   r   r   rC      s   z3ChildBrowserTreeItem.GetSubList.<locals>.<listcomp>)r   r   rS   )r    r   r   r   rE      s    zChildBrowserTreeItem.GetSubListc          	   C   s<   yt | jj}|| jj W n ttfk
r6   Y nX d S )N)r-   r   r=   ZgotolinelinenoOSErrorAttributeError)r    Zeditr   r   r   rI      s
    z"ChildBrowserTreeItem.OnDoubleClickN)	r:   r;   r<   r!   r>   r@   rJ   rE   rI   r   r   r   r   rA      s   rA   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 )Nr   r   r   r   r   nested_in_class       z7_module_browser.<locals>.Nested_in_func.nested_in_classN)r:   r;   r<   rW   r   r   r   r   Nested_in_func   s   rY   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;   r<   r   r   r   r   Nested_in_closure   s    rZ   r   )rZ   r   r   r   closure   s    z _module_browser.<locals>.closureT)r   )lenrM   argv__file__r   r   )parentr=   rY   r[   r   r   r   _module_browser   s    r`   __main__r'   )mainzidlelib.idle_test.test_browser   F)	verbosityexit)run)N)r7   r.   rM   Zidlelib.configr   Zidlelibr   Zidlelib.treer   r   r   Zidlelib.windowr   r-   r   r   r9   rA   r`   r:   r\   r]   Zunittestrb   Zidlelib.idle_test.htestrf   r   r   r   r   <module>   s$   
 M4-