B
    v9af                 @   s   d dl Z d dlZd dlZd dlZd dlmZmZ d dlm	Z	m
Z
mZ dddZG dd de
ZG dd	 d	e
ZG d
d de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 )    N)ObjectTreeItemmake_objecttreeitem)TreeNodeTreeItemScrolledCanvasc             C   sT   |d krt | }t|dddatjjddd t||attj	d ta
t
  d S )NZwhiter   )bgZhighlightthickness   Zboth)expandfill)tkToplevelr   ZscframepackStackTreeItemitemr   ZcanvasZnoder	   )rootflisttbtop r   !/usr/lib/python3.7/stackviewer.pyStackBrowser
   s    

r   c               @   s6   e Zd ZdddZdd Zdd Zdd	 Zd
d ZdS )r   Nc             C   s    || _ | || _|  | _d S )N)r   	get_stackstackget_exceptiontext)selfr   r   r   r   r   __init__   s    zStackTreeItem.__init__c             C   sP   |d krt j}g }|r&|jd kr&|j}x$|d k	rJ||j|jf |j}q(W |S )N)syslast_tracebacktb_frametb_nextappend	tb_lineno)r   r   r   r   r   r   r      s    

zStackTreeItem.get_stackc             C   s@   t j}t j}t|dr|j}t|}|d k	r<|d t| }|S )N__name__z: )r   	last_type
last_valuehasattrr$   str)r   typevaluesr   r   r   r   '   s    
zStackTreeItem.get_exceptionc             C   s   | j S )N)r   )r   r   r   r   GetText1   s    zStackTreeItem.GetTextc             C   s.   g }x$| j D ]}t|| j}|| qW |S )N)r   FrameTreeItemr   r"   )r   sublistinfor   r   r   r   
GetSubList4   s
    zStackTreeItem.GetSubList)NN)r$   
__module____qualname__r   r   r   r,   r0   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	S )
r-   c             C   s   || _ || _d S )N)r/   r   )r   r/   r   r   r   r   r   >   s    zFrameTreeItem.__init__c       	      C   s|   | j \}}y|jd }W n   d}Y nX |j}|j}|j}t||}| }|dkrhd|||f }nd||||f }|S )Nr$   ?)r3    Nz%s, line %d: %sz%s.%s(...), line %d: %s)r/   	f_globalsf_codeco_filenameco_name	linecachegetlinestrip)	r   r   linenomodnamecodefilenamefuncnameZ
sourceliner   r   r   r   r,   B   s    


zFrameTreeItem.GetTextc             C   sR   | j \}}g }|j|jk	r4td|j| j}|| td|j| j}|| |S )Nz<locals>z	<globals>)r/   r5   f_localsVariablesTreeItemr   r"   )r   r   r<   r.   r   r   r   r   r0   T   s    


zFrameTreeItem.GetSubListc             C   s6   | j r2| j\}}|jj}tj|r2| j || d S )N)r   r/   r6   r7   ospathisfileZgotofileline)r   r   r<   r?   r   r   r   OnDoubleClick^   s
    
zFrameTreeItem.OnDoubleClickN)r$   r1   r2   r   r,   r0   rF   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	S )
rB   c             C   s   | j S )N)Z	labeltext)r   r   r   r   r,   h   s    zVariablesTreeItem.GetTextc             C   s   d S )Nr   )r   r   r   r   GetLabelTextk   s    zVariablesTreeItem.GetLabelTextc             C   s   t | jdkS )Nr   )lenobject)r   r   r   r   IsExpandablen   s    zVariablesTreeItem.IsExpandablec          	   C   sl   g }xb| j  D ]T}y| j | }W n tk
r8   wY nX || j fdd}t|d ||}|| qW |S )Nc             S   s   | ||< d S )Nr   )r*   keyrI   r   r   r   setfunctionx   s    z1VariablesTreeItem.GetSubList.<locals>.setfunctionz =)rI   keysKeyErrorr   r"   )r   r.   rK   r*   rL   r   r   r   r   r0   q   s    zVariablesTreeItem.GetSubListN)r$   r1   r2   r,   rG   rJ   r0   r   r   r   r   rB   f   s   rB   c       	      C   s   ddl m} t| }|d tt|  ddd  \}}|d|d |d f  ||}yt	 W n" t
k
r   t \}}}Y nX |t_|t_|t_t||||d	 t`t`t`d S )
Nr   )PyShellFileListzTest StackViewer+r   z+%d+%d2      )r   r   r   )Zidlelib.pyshellrO   r   r   titlemapintZgeometrysplitZintentional_name_error	NameErrorr   exc_infor%   r&   r   r   )	parentrO   r   xyr   exc_type	exc_valueZexc_tbr   r   r   _stack_viewer   s"    

 r^   __main__)mainz"idlelib.idle_test.test_stackviewer   F)	verbosityexit)run)NNN)r9   rC   r   Ztkinterr   Zidlelib.debugobjr   r   Zidlelib.treer   r   r   r   r   r-   rB   r^   r$   Zunittestr`   Zidlelib.idle_test.htestrd   r   r   r   r   <module>   s   
'*