
    e                     p    d dl Z d dlZddlmZmZ  G d dej
                        ZddZddZd Z	d	 Z
d
 Zy)    N   )	QtWidgetsQtGuic                   0    e Zd ZddZd Zd ZddZd	dZy)
StackWidgetNc                     t         j                  j                  | |       | j                  d       | j	                  d       y )NT)r   QTreeWidget__init__setAlternatingRowColorssetHeaderHidden)selfparents     ?/usr/lib/python3/dist-packages/pyqtgraph/console/stackwidget.pyr
   zStackWidget.__init__   s4    &&tV4$$T*T"    c                 ^    | j                         }t        |      dk(  ry|d   j                  S )zUReturn the currently selected stack frame (or None if there is no selection)
        r   N)selectedItemslenframe)r   sels     r   selectedFramezStackWidget.selectedFrame   s.       "s8q=q6<<r   c                 P    t         j                  j                  |        g | _        y N)r   r	   clearframes)r   s    r   r   zStackWidget.clear   s    ##D)r   c                 "   |t        j                         d   }| j                          t        |      }|D ]  \  }}t	        |j
                  |      \  }}t        d      }dj                  t        j                  t        |      |            j                         }	t        ||gz   |z   |	      }
| j                  |
d          ||dk(  rt        d      }n|d	k(  rt        d
      }| j                          
d   j                  d       y)zGDisplay an exception chain with its tracebacks and call stack.
        N   	lastFramezException caught here r   causezDThe above exception was the direct cause of the following exception:contextzCDuring handling of the above exception, another exception occurred:T)sysexc_infor   exceptionChainstacksFromTraceback__traceback__textItemjoin	tracebackformat_exception_onlytypestripmakeItemTreeaddTopLevelItemsetExpanded)r   excr   
exceptionsexr    stackFramestbFramescatchMsgexcStritems	causeItems               r   setExceptionzStackWidget.setException   s    ;,,.#C

#C(
# 	0IB$78H8HT]$^!K 78HWWY<<T"XrJKQQSF z!9H!DfME  q* G# ()o pIi' ()n oI$$Y/	0 	aT"r   c                     |t        j                         j                  }| j                          t	        ||      }t        |d      }| j                  |d          |r|d   j                  d       yy)a  Display a call stack and exception traceback.

        This allows the user to probe the contents of any frame in the given stack.

        *frame* may either be a Frame instance or None, in which case the current 
        frame is retrieved from ``sys._getframe()``. 

        If *tb* is provided then the frames in the traceback will be appended to 
        the end of the stack list. If *tb* is None, then sys.exc_info() will 
        be checked instead.
        Nr   z
Call stackr   T)r"   	_getframef_backr   stackFromFramer-   r.   r/   )r   r   expandr   stackr7   s         r   setStackzStackWidget.setStack0   sg     =MMO**E

u	:UL1U1X&!H  & r   r   )NN)NTN)__name__
__module____qualname__r
   r   r   r9   r@    r   r   r   r      s    #
 #0'r   r   c           	          t        j                  |       }g }| !|j                  d|        | j                  } | !|||v r|d|j	                  |      dz    }t        t        |dt        |       |            S )zReturn (text, stack_frame) for the entire stack ending at *frame*

    If *lastFrame* is given and present in the stack, then the stack is truncated 
    at that frame.
    Nr   r   )r)   format_stackinsertr<   indexlistzipr   )r   r   linesr   s       r   r=   r=   H   s     ""5)EF

a 
 f!42i023E,3v;'011r   c           
      P   t        | | j                  j                  n|      }| |g fS t        j                  |       }g }	 |j                  | j                         | j                  | j                  |u rn| j                  } C|t        t        |dt        |       |            fS )zReturn (text, stack_frame) for a traceback and the stack preceding it

    If *lastFrame* is given and present in the stack, then the stack is truncated 
    at that frame.
    N)
r=   tb_framer<   r)   	format_tbappendtb_nextrI   rJ   r   )tbr   r?   rK   r   s        r   r%   r%   Y   s     2;;--YOE	zby #EF
bkk"::	!9ZZ	  $s5#f+.7888r   c                    t        j                  |g      }d |_        |j                  d      }|j	                  |j
                  j                         |j                  d|       |g}| D ]q  }t        |t         j                        r|}n0|\  }}t        j                  |j                         g      }||_        |j                  |       |j                  |       s |S )Nr   )r   QTreeWidgetItemr   font	setWeightWeightBoldsetFont
isinstancerstripaddChildrO   )	r?   titletopItemrT   r7   entryitemtextr   s	            r   r-   r-   p   s    ''0GGM<<?DNN4;;##$OOAtIE eY667DKD%,,dkkm_=DDJT Lr   c                     | dfg}	 | j                   !| j                   } |j                  d| df       n>| j                  /| j                  du r!| j                  } |j                  d| df       n	 |S l)zaReturn a list of (exception, 'cause'|'context') pairs for exceptions
    leading up to *exc*
    Nr   r    Fr!   )	__cause__rG   __context____suppress_context__)r0   r1   s     r   r$   r$      s|     +J
==$--Ca#w0__(S-E-E-N//Ca#y!12 r   c           
      r   t        j                  | g      }d|_        |j                  dt	        j
                  t	        j                  ddd                   |j                  dt	        j
                  t	        j                  ddd                   |j                  |j                  j                         |S )zTReturn a tree item with no associated stack frame and a darker background color
    Nr      )r   rS   r   setBackgroundr   QBrushQColorsetForegroundsetChildIndicatorPolicyChildIndicatorPolicyDontShowIndicator)r`   r_   s     r   r'   r'      s     $$dV,DDJq%,,u||Cc'BCDq%,,u||Aq!'<=>  !:!:!L!LMKr   r   )r"   r)   Qtr   r   r	   r   r=   r%   r-   r$   r'   rD   r   r   <module>ro      s9     !@')'' @'F2"9.&$r   