a
    zef                     @   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 u 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.9/idlelib/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   sL   |d u rt j}g }|r&|jd u r&|j}|d urH||j|jf |j}q&|S r   )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 u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 r   )r   r   r   r   r   GetText1   s    zStackTreeItem.GetTextc                 C   s*   g }| j D ]}t|| j}|| q
|S r   )r   FrameTreeItemr   r#   )r   sublistinfor   r   r   r   
GetSubList4   s
    
zStackTreeItem.GetSubList)NN)r%   
__module____qualname__r   r   r   r.   r2   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 r   )r1   r   )r   r1   r   r   r   r   r   >   s    zFrameTreeItem.__init__c           	      C   s|   | j \}}z|jd }W n   d}Y n0 |j}|j}|j}t||}| }|dv rhd|||f }nd||||f }|S )Nr%   ?)r5    Nz%s, line %d: %sz%s.%s(...), line %d: %s)r1   	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ur4td|j| j}|| td|j| j}|| |S )Nz<locals>z	<globals>)r1   r7   f_localsVariablesTreeItemr   r#   )r   r   r>   r0   r   r   r   r   r2   T   s    


zFrameTreeItem.GetSubListc                 C   s6   | j r2| j\}}|jj}tj|r2| j || d S r   )r   r1   r8   r9   ospathisfileZgotofileline)r   r   r>   rA   r   r   r   OnDoubleClick^   s
    
zFrameTreeItem.OnDoubleClickN)r%   r3   r4   r   r.   r2   rH   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 )
rD   c                 C   s   | j S r   )Z	labeltextr-   r   r   r   r.   h   s    zVariablesTreeItem.GetTextc                 C   s   d S r   r   r-   r   r   r   GetLabelTextk   s    zVariablesTreeItem.GetLabelTextc                 C   s   t | jdkS )Nr   )lenobjectr-   r   r   r   IsExpandablen   s    zVariablesTreeItem.IsExpandablec              	   C   sh   g }| j  D ]T}z| j | }W n ty6   Y qY n0 || j fdd}t|d ||}|| q|S )Nc                 S   s   | ||< d S r   r   )r+   keyrK   r   r   r   setfunctionx   s    z1VariablesTreeItem.GetSubList.<locals>.setfunctionz =)rK   keysKeyErrorr   r#   )r   r0   rM   r+   rN   r   r   r   r   r2   q   s    
zVariablesTreeItem.GetSubListN)r%   r3   r4   r.   rI   rL   r2   r   r   r   r   rD   f   s   rD   c           	      C   s   ddl m} t| }|d tt|  ddd  \}}|d|d |d f  ||}zt	 W n  t
y   t \}}}Y n0 |t_|t_|t_t||||d	 t`t`t`d S )
Nr   )PyShellFileListzTest StackViewer+r   z+%d+%d2      )r   r   r   )Zidlelib.pyshellrQ   r   r   titlemapintZgeometrysplitZintentional_name_error	NameErrorr   exc_infor&   r'   r    r   )	parentrQ   r   xyr   exc_type	exc_valueexc_tbr   r   r   _stack_viewer   s"    

 ra   __main__)mainz"idlelib.idle_test.test_stackviewer   F)	verbosityexit)run)NNN)r;   rE   r   tkinterr   Zidlelib.debugobjr   r   Zidlelib.treer   r   r   r   r   r/   rD   ra   r%   Zunittestrc   Zidlelib.idle_test.htestrg   r   r   r   r   <module>   s   
'*