ó
‹²,]c           @€  sC  d  Z  d d l m Z d d l Z d d l j Z d d l m 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 m Z m Z d d l m Z d d l m Z m Z m Z m Z m Z m Z m Z m Z d d	 l  m! Z! m" 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 d l. m/ Z/ d d l0 m1 Z1 m2 Z2 d d l3 m4 Z4 y e" d d ƒ Z5 Wn( e6 k
 rÂZ7 d d l8 Z8 e8 j8 Z5 n Xd „  Z9 d e f d „  ƒ  YZ: d „  Z; d e f d „  ƒ  YZ< d e f d „  ƒ  YZ= d „  Z> d „  Z? e@ d k r?e? ƒ  n  d S(   su   
Profiler widget

See the official documentation on python profiling:
https://docs.python.org/3/library/profile.html
iÿÿÿÿ(   t   with_statementN(   t   islice(   t   getopenfilenamet   getsavefilename(   t
   QByteArrayt   QProcesst   QProcessEnvironmentt   Qtt   Signal(   t   QColor(   t   QApplicationt   QHBoxLayoutt   QLabelt   QMessageBoxt   QTreeWidgett   QTreeWidgetItemt   QVBoxLayoutt   QWidget(   t   get_conf_patht   get_translation(   t   to_text_string(   t   icon_manager(   t   create_toolbuttont   get_item_user_textt   set_item_user_text(   t   shell_split(   t   PythonModulesComboBox(   t   add_pathlist_to_PYTHONPATHt   getcwd_or_home(   t
   TextEditort   profilert   spyder_profilerc          C€  s&   d d l  m }  |  d ƒ o% |  d ƒ S(   Niÿÿÿÿ(   t   is_module_installedt   cProfilet   pstats(   t   spyder.utils.programsR    (   R    (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   is_profiler_installed3   s    t   ProfilerWidgetc           B€  sÑ   e  Z d  Z e d ƒ Z d Z e e ƒ Z d d „ Z	 d „  Z
 d „  Z d „  Z d d d d „ Z d	 „  Z d
 „  Z d „  Z d d d d „ Z d „  Z e d „ Z e d „ Z d „  Z d „  Z e d „ Z RS(   s   
    Profiler widget
    s   profiler.resultss   0.0.1id   c   
      €  s‚  t  j ˆ  | ƒ ˆ  j d ƒ d  ˆ  _ d  ˆ  _ d  ˆ  _ d  ˆ  _ d  ˆ  _ t	 ˆ  ƒ ˆ  _
 t ˆ  d t j d ƒ d t d ƒ d t d ƒ d ‡  f d	 †  d
 t ƒˆ  _ t ˆ  d t j d ƒ d t d ƒ d t d ƒ d
 t ƒˆ  _ ˆ  j
 j j ˆ  j j ƒ t ˆ  d t j d ƒ d t d ƒ d ˆ  j ƒ} t ƒ  ˆ  _ t ˆ  d t j d ƒ d t d ƒ d
 t d t d ƒ d ˆ  j ƒˆ  _ t ˆ  ƒ ˆ  _ t ˆ  d t j d ƒ d ‡  f d †  d t d ƒ ƒˆ  _ t ˆ  d t j d ƒ d ‡  f d †  d t d ƒ ƒˆ  _ t ˆ  d
 t d t d ƒ d t j d ƒ d ˆ  j d t d ƒ ƒˆ  _ t ˆ  d
 t d t d ƒ d t j d ƒ d ˆ  j  d t d ƒ ƒˆ  _! t ˆ  d
 t d t d ƒ d t j d  ƒ d ˆ  j" ƒˆ  _# t$ ƒ  } | j% ˆ  j
 ƒ | j% | ƒ | j% ˆ  j ƒ | j% ˆ  j ƒ t$ ƒ  } | j% ˆ  j ƒ | j% ˆ  j ƒ | j& ƒ  | j% ˆ  j ƒ | j& ƒ  | j% ˆ  j ƒ | j% ˆ  j ƒ | j% ˆ  j! ƒ | j% ˆ  j# ƒ t' ƒ  } | j( | ƒ | j( | ƒ | j% ˆ  j ƒ ˆ  j) | ƒ d  ˆ  _* ˆ  j+ t, ƒ ˆ  j j t, ƒ ˆ  j# j t, ƒ t- ƒ  s~x3 ˆ  j ˆ  j
 ˆ  j ˆ  j f D] } | j. t ƒ q/Wd! } d" t d# ƒ | t d$ ƒ f }	 ˆ  j j/ |	 ƒ n  d  S(%   Nt   Profilert   icont   runt   textt   Profilet   tips   Run profilert	   triggeredc           €  s
   ˆ  j  ƒ  S(   N(   t   start(    (   t   self(    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   <lambda>Q   t    t   text_beside_icont   stopt   Stops   Stop current profilingt   fileopens   Select Python scriptt   logt   Outputs   Show program's outputt   collapsec         €  s   ˆ  j  j d ƒ S(   Niÿÿÿÿ(   t   datatreet   change_view(   t   dD(   R.   (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR/   m   s    s   Collapse one level upt   expandc         €  s   ˆ  j  j d ƒ S(   Ni   (   R8   R9   (   R:   (   R.   (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR/   r   s    s   Expand one level downs	   Save datat   filesaves   Save profiling datas	   Load datat
   fileimports"   Load profiling data for comparisons   Clear comparisont
   editdeletes.   https://docs.python.org/3/library/profile.htmls   %s <a href=%s>%s</a>s   Please installs   the Python profiler modules(0   R   t   __init__t   setWindowTitlet   Nonet   outputt   error_outputt
   _last_wdirt
   _last_argst   _last_pythonpathR   t	   filecomboR   t   imaR'   t   _t   Truet   start_buttont   stop_buttont   validt   connectt
   setEnabledt   select_fileR   t	   datelabelt   show_logt
   log_buttont   ProfilerDataTreeR8   t   collapse_buttont   expand_buttont	   save_datat   save_buttont   comparet   load_buttont   cleart   clear_buttonR   t	   addWidgett
   addStretchR   t	   addLayoutt	   setLayoutt   processt   set_running_statet   FalseR$   t   setDisabledt   setText(
   R.   t   parentt   max_entriest   browse_buttont   hlayout1t   hlayout2t   layoutt   widgett   urlR)   (    (   R.   sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR?   @   s¨    												

			c         C€  sQ   t  d ƒ } t |  | t ƒ  t  d ƒ d ƒ \ } } | rM |  j j | ƒ n  d S(   s	   Save datas   Save profiler results   Profiler results    (*.Result)N(   RI   R   R   R8   RW   (   R.   t   titlet   filenamet
   _selfilter(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRW   ¯   s    c         C€  se   t  |  t d ƒ t ƒ  t d ƒ d ƒ \ } } | ra |  j j | ƒ |  j ƒ  |  j j t ƒ n  d  S(   Ns   Select script to compares   Profiler results    (*.Result)(	   R   RI   R   R8   RY   t	   show_dataR\   RO   RJ   (   R.   Ro   Rp   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRY   ¸   s    
c         C€  s>   |  j  j d  ƒ |  j  j t ƒ |  j ƒ  |  j j t ƒ d  S(   N(	   R8   RY   RA   t   hide_diff_colsRJ   Rq   R\   RO   Rc   (   R.   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR[   Á   s    
c         C€  sÉ   t  ƒ  s d  S|  j ƒ  d  } | d  k rY |  j j | ƒ |  j j |  j j ƒ  d ƒ n |  j j |  j j | ƒ ƒ |  j j ƒ  |  j j	 ƒ  rÅ | d  k r¯ t
 j | ƒ } n  |  j | | | ƒ n  d  S(   Ni   (   R$   t   kill_if_runningRA   RG   t   addItemt   setCurrentIndext   countt   findTextt   selectedt   is_validt   ospt   dirnameR-   (   R.   Ro   t   wdirt   argst
   pythonpatht   index(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   analyzeÇ   s    	
 c         C€  sh   |  j  j t ƒ t |  t d ƒ t ƒ  t d ƒ d ƒ \ } } |  j  j t ƒ | rd |  j | ƒ n  d  S(   Ns   Select Python scripts   Python scriptss    (*.py ; *.pyw)(   t   redirect_stdiot   emitRc   R   RI   R   RJ   R€   (   R.   Ro   Rp   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRP   Ø   s    c      	   C€  s;   |  j  r7 t |  j  d t d ƒ d t d d ƒj ƒ  n  d  S(   NRn   s   Profiler outputt   readonlyt   sizei¼  iô  (   i¼  iô  (   RB   R   RI   RJ   t   exec_(   R.   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRR   á   s    	c      	   C€  s;   |  j  r7 t |  j  d t d ƒ d t d d ƒj ƒ  n  d  S(   NRn   s   Profiler outputRƒ   R„   i¼  iô  (   i¼  iô  (   RC   R   RI   RJ   R…   (   R.   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   show_errorlogæ   s    	c         €  sÿ  t  ˆ  j j ƒ  ƒ } | d  k rK ˆ  j } | d  k rK t j | ƒ } qK n  | d  k rx ˆ  j } | d  k rx g  } qx n  | d  k r ˆ  j } n  | ˆ  _ | ˆ  _ | ˆ  _ ˆ  j	 j
 t d ƒ ƒ t ˆ  ƒ ˆ  _ ˆ  j j t j ƒ ˆ  j j | ƒ ˆ  j j j ˆ  j ƒ ˆ  j j j ‡  f d †  ƒ ˆ  j j j t j ‡  f d † ƒ ˆ  j j j ˆ  j ƒ | d  k	 róg  ˆ  j j ƒ  D] } t  | ƒ ^ qy} t | | ƒ t ƒ  } x6 | D]. } | j d ƒ \ }	 }
 } | j |	 | ƒ q®Wˆ  j j | ƒ n  d ˆ  _  d ˆ  _! t" ˆ  _# d d d ˆ  j$ g } t% j& d	 k rZ| j' t j( | ƒ j) t% j* d
 ƒ ƒ n | j' | ƒ | rƒ| j+ t, | ƒ ƒ n  t- j. } | j/ d ƒ r¤d } n  ˆ  j j0 | | ƒ ˆ  j j1 ƒ  } ˆ  j2 | ƒ | sût3 j4 ˆ  t d ƒ t d ƒ ƒ n  d  S(   Ns   Profiling, please wait...c           €  s   ˆ  j  d t ƒ S(   Nt   error(   t   read_outputRJ   (    (   R.   (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR/     R0   c         €  s   ˆ  j  |  | ƒ S(   N(   t   finished(   t   ect   es(   R.   (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR/     s    t   =R0   s   -mR!   s   -ot   ntt   /s
   spyder.exes
   python.exet   Errors   Process failed to start(5   R   RG   t   currentTextRA   RD   Rz   t   basenameRE   RF   RQ   Re   RI   R   Ra   t   setProcessChannelModet   SeparateChannelst   setWorkingDirectoryt   readyReadStandardOutputRN   Rˆ   t   readyReadStandardErrorR‰   t
   ExitStatusRL   t   clickedt   killt   systemEnvironmentR   R   t	   partitiont   insertt   setProcessEnvironmentRB   RC   Rc   t   stoppedt   DATAPATHt   ost   namet   appendt   normpatht   replacet   sept   extendR   t   syst
   executablet   endswithR-   t   waitForStartedRb   R   t   critical(   R.   R|   R}   R~   Ro   t   _ptht   envt   processEnvironmentt   envItemt   envNamet	   separatort   envValuet   p_argsR¨   t   running(    (   R.   sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR-   ë   sd    					"%				(		c         C€  s   |  j  j ƒ  t |  _ d S(   s   Stop button pressed.N(   Ra   R™   RJ   Rž   (   R.   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR™   +  s    c         C€  s%   |  j  j | ƒ |  j j | ƒ d  S(   N(   RK   RO   RL   (   R.   t   state(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRb   0  s    c         C€  sÀ   | r |  j  j t j ƒ n |  j  j t j ƒ t ƒ  } xB |  j  j ƒ  r| | rf | |  j  j ƒ  7} q; | |  j  j ƒ  7} q; Wt	 | j
 ƒ  d d ƒ} | r­ |  j | 7_ n |  j | 7_ d  S(   Nt   encodings   utf-8(   Ra   t   setReadChannelR   t   StandardErrort   StandardOutputR   t   bytesAvailablet   readAllStandardErrort   readAllStandardOutputR   t   dataRC   RB   (   R.   R‡   t   qbaR)   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRˆ   4  s    	c         C€  s>   |  j  t ƒ |  j ƒ  |  j |  j |  _ |  j d t ƒ d  S(   Nt   justanalyzed(   Rb   Rc   R†   RC   RB   Rq   RJ   (   R.   t	   exit_codet   exit_status(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR‰   E  s    
c         C€  sK   |  j  d  k	 rG |  j  j ƒ  t j k rG |  j  j ƒ  |  j  j ƒ  qG n  d  S(   N(   Ra   RA   Rµ   R   t   RunningR™   t   waitForFinished(   R.   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRs   M  s    c         C€  s  | s d  |  _ n  |  j j |  j d  k	 o< t |  j ƒ d k ƒ |  j ƒ  t |  j j ƒ  ƒ } | si d  S|  j	 r™ |  j
 j t d ƒ ƒ |  j j ƒ  d  S|  j
 j t d ƒ ƒ t j ƒ  |  j j |  j ƒ |  j j ƒ  d } | t j d t j ƒ  ƒ } |  j
 j | ƒ d  S(   Ni    s   Run stopped by user.s   Sorting data, please wait...s.   <span style='color: #444444'><b>%s </b></span>s   %d %b %Y %H:%M(   RA   RB   RS   RO   t   lenRs   R   RG   R   Rž   RQ   Re   RI   R8   t   initialize_viewR
   t   processEventst	   load_dataRŸ   t	   show_treet   timet   strftimet	   localtime(   R.   R¿   Ro   t
   text_stylet	   date_text(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRq   S  s(    
	
N(   t   __name__t
   __module__t   __doc__R   RŸ   t   VERSIONR   t   boolR   R?   RW   RY   R[   RA   R€   RP   RR   R†   R-   R™   RJ   Rb   Rc   Rˆ   R‰   Rs   Rq   (    (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR%   8   s&   o									@			c         C€  sô   d } t  j | |  ƒ } t | ƒ d k r. d Sd } x¹ | D]± } t | d ƒ } | d d k rn | d 9} nt | d d k r‹ | d 9} nW | d d	 k r¨ | d
 9} n: | d d k rÅ | d 9} n | d d k râ | d 9} n  | | 7} q; W| S(   sº   Parse text and returns a time in seconds
    
    The text is of the format 0h : 0.min:0.0s:0 ms:0us:0 ns. 
    Spaces are not taken into account and any of the specifiers can be ignoreds    ([+-]?\d+\.?\d*) ?([munsecinh]+)i    g        i   t   nsg•Ö&è.>t   usgíµ ÷Æ°>t   msgü©ñÒMbP?t   mini<   t   hi  N(   t   ret   findallRÄ   RA   t   float(   R)   t   patternt   matchesRÉ   t   rest   tmp(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt	   gettime_sm  s&    t   TreeWidgetItemc           B€  s   e  Z d d  „ Z d „  Z RS(   c         C€  s   t  j |  | ƒ d  S(   N(   R   R?   (   R.   Rf   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR?   ‡  s    c         C€  sÖ   |  j  ƒ  j ƒ  } y“ | d k s- | d k r| t |  j | ƒ ƒ } t | j | ƒ ƒ } | d  k	 r| | d  k	 r| | | k Sn  t |  j | ƒ ƒ t | j | ƒ ƒ k SWn* t k
 rÑ |  j | ƒ | j | ƒ k SXd  S(   Ni   i   (   t
   treeWidgett
   sortColumnRß   R)   RA   RÚ   t
   ValueError(   R.   t	   otherItemt   columnt   t0t   t1(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   __lt__Š  s    ,N(   RÎ   RÏ   RA   R?   Rè   (    (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRà   †  s   RT   c           B€  sã   e  Z d  Z d Z d d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z e d „  ƒ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   s  
    Convenience tree widget (with built-in model) 
    to store and view profiler data.

    The quantities calculated by the profiler are as follows 
    (from profile.Profile):
    [0] = The number of times this function was called, not counting direct
          or indirect recursion,
    [1] = Number of times this function appears on the stack, minus one
    [2] = Total time spent internal to this function
    [3] = Cumulative time that this function was present on the stack.  In
          non-recursive functions, this is the total execution time from start
          to finish of each invocation of a function, including time spent in
          all subfunctions.
    [4] = A dictionary indicating for each function name, the number of times
          it was called by us.
    s   <[=]>c      	   C€  sC  t  j |  | ƒ t d ƒ t d ƒ t d ƒ t d ƒ t d ƒ t d ƒ t d ƒ t d ƒ g |  _ i t j d ƒ d 6t j d	 ƒ d	 6t j d ƒ d
 6t j d ƒ d 6|  _ d  |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ d  |  _ |  j t |  j ƒ ƒ |  j |  j ƒ |  j ƒ  |  j j |  j ƒ |  j j |  j ƒ d  S(   Ns   Function/Modules
   Total Timet   Diffs
   Local Timet   Callss	   File:linet   pythont   modulet   functiont   builtint   classt   constructor(   R   R?   RI   t   header_listRH   R'   t	   icon_listRA   t   profdatat   statst
   item_deptht	   item_listt   items_to_be_shownt   current_view_deptht   compare_filet   setColumnCountRÄ   t   setHeaderLabelsRÅ   t   itemActivatedRN   t   item_activatedt   itemExpandedt   item_expanded(   R.   Rf   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR?   «  s(    $							
c         C€  s!   t  | d | |  j | f ƒ d S(   s@   Set tree item user data: filename (string) and line_number (int)s   %s%s%dN(   R   t   SEP(   R.   t   itemRo   t   line_number(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   set_item_dataÁ  s    c         C€  s.   t  | ƒ j |  j ƒ \ } } | t | ƒ f S(   s0   Get tree item user data: (filename, line_number)(   R   t   splitR   t   int(   R.   R  Ro   t   line_number_str(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   get_item_dataÅ  s    c         C€  s2   |  j  ƒ  d |  _ g  |  _ i  |  _ d |  _ d S(   s"   Clean the tree and view parametersi    N(   R[   Rõ   Rö   R÷   Rø   (   R.   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRÅ   Ê  s
    
			c         C€  s	  d d l  } y | j | ƒ g } Wn! t t f k
 rE d |  _ d SX| d |  _ |  j d k	 rÏ y | j | j |  j ƒ ƒ WqÏ t t f k
 rË } t j	 |  t
 d ƒ t
 d ƒ j | ƒ ƒ d |  _ qÏ Xn  t d „  | ƒ |  j j ƒ  | |  _ | d j |  _ d S(   s3   Load profiler data saved by profile/cProfile moduleiÿÿÿÿNi    R   sM   Error when trying to load profiler results. The error was<br><br><tt>{0}</tt>c         S€  s
   |  j  ƒ  S(   N(   t   calc_callees(   t   x(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR/   è  R0   (   R"   t   Statst   OSErrort   IOErrorRA   Ró   Rù   R¢   R   R«   RI   t   formatt   mapR  t   stats1Rô   (   R.   t   profdatafileR"   t
   stats_indit   e(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRÇ   Ò  s(    	
	c         C€  s   |  j  t ƒ | |  _ d  S(   N(   Rr   Rc   Rù   (   R.   Ro   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRY   í  s    c         C€  s%   x d D] } |  j  | | ƒ q Wd  S(   Ni   i   i   (   i   i   i   (   t   setColumnHidden(   R.   t   hidet   i(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRr   ñ  s    c         C€  s   |  j  d j | ƒ d S(   s   Save profiler data.i    N(   R  t
   dump_stats(   R.   Ro   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRW   õ  s    c         C€  sl   |  j  d k	 r" |  j  j d ƒ n d Sx? |  j  j D]1 } d | d d !k r3 | d j d ƒ r3 | Sq3 Wd S(   s    Find a function without a callert
   cumulativeNt   ~i    i   s   <built-in method exec>(   R  i    (   Ró   RA   t
   sort_statst   fcn_listt
   startswith(   R.   t   func(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt	   find_rootù  s    
c         C€  s   |  j  j | S(   s/   Find all functions called by (parent) function.(   Ró   t   all_callees(   R.   Rf   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   find_callees  s    c         C€  s–   |  j  ƒ  |  j t ƒ |  j t ƒ |  j ƒ  } | d k	 r’ |  j |  |  j | ƒ ƒ |  j	 d ƒ |  j t ƒ |  j
 d t j ƒ |  j d ƒ n  d S(   s4   Populate the tree with profiler data and display it.i    i   N(   RÅ   t   setItemsExpandableRJ   t   setSortingEnabledRc   R  RA   t   populate_treeR  t   resizeColumnToContentst	   sortItemsR   t   AscendingOrderR9   (   R.   t   rootkey(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRÈ     s    
c   	      C€  sË   d } | \ } } } | d k rq t  j | ƒ \ } } d } | d k r` t  j | ƒ \ } } n  d | d } n  | s„ | d k r“ d } d	 } n% | d
 k r¨ d } n  d | | f } | | | | | f S(   sA   Returns processed information about the function's name and file.Rí   s   <module>Rì   s   __init__.pyt   <t   >R  s
   (built-in)Rî   R?   Rð   s   %s : %d(   Rz   R  (	   R.   t   functionKeyt	   node_typeRo   R  t   function_namet
   modulePatht
   moduleNamet   file_and_line(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   function_info  s    		c         C€  s°  t  |  ƒ }  t |  t ƒ r% t |  ƒ Sd |  k  o< d k n rW d j |  d ƒ }  nUd |  k  on d k n r‰ d j |  d ƒ }  n#d |  k  o  d k n r» d j |  d ƒ }  nñ d |  k  oÒ d k n ré d	 j |  ƒ }  nÃ d |  k  o d
 k n rlt |  d
 ƒ \ } } | d k rWt |  d ƒ \ } } t | ƒ j d ƒ d } n  d j | | ƒ }  n@ t |  d
 ƒ \ } } | d k rš| d :} n  d j | | ƒ }  |  S(   s8   Get format and units for data coming from profiler task.g•Ö&è.>gíµ ÷Æ°>u
   {0:.2f} nsgü©ñÒMbP?u
   {0:.2f} usi   u
   {0:.2f} msi<   u   {0:.2f} seci  t   .iÿÿÿÿu   {0:.0f}.{1:.2s} minu   {0:.0f}h:{1:.0f}min(   t   abst
   isinstanceR  R   R  t   divmodR  (   t   measuret   mt   sR×   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   format_measure-  s,    
c         C€  s¡   d } d } t  | ƒ d k r„ |  j d k	 r„ | d | d } | r„ | d k  rW d n d \ } } d
 j | |  j | ƒ ƒ } q„ n  |  j | d ƒ | | g g S(   s•  Return a string formatted delta for the values in x.

        Args:
            x: 2-item list of integers (representing number of calls) or
               2-item list of floats (representing seconds of runtime).

        Returns:
            A list with [formatted x[0], [color, formatted delta]], where
            color reflects whether x[1] is lower, greater, or the same as
            x[0].
        R0   t   blacki   i    i   t   greent   -t   redt   +s   {}{}N(   R9  R:  (   R;  R<  (   RÄ   Rù   RA   R  R7  (   R.   R	  t   diff_strt   colort
   differencet   sign(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   color_stringM  s    !!c      	   C€  s\   g  |  j  D]* } | j j | d d d d i  g ƒ ^ q
 } t |  j t t | Œ  d d ƒ ƒ S(   s    Formats the data.

        self.stats1 contains a list of one or two pstat.Stats() instances, with
        the first being the current run and the second, the saved run, if it
        exists.  Each Stats instance is a dictionary mapping a function to
        5 data points - cumulative calls, number of calls, total time,
        cumulative time, and callers.

        format_output() converts the number of calls, total time, and
        cumulative time to a string format for the child_key parameter.
        i    i   i   (   R  Rô   t   getR  RA  R   t   zip(   R.   t	   child_keyR	  R½   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   format_outputc  s    :c         C€  sG  x@| D]8} |  j  d 7_  |  j | ƒ \ } } } } } |  j | ƒ \ \ }	 }
 \ } } \ } } t | ƒ } |  j j | ƒ |  j | | | ƒ | j d t d ƒ ƒ | j	 d t
 j | ƒ | j d |  j | ƒ | j d t d ƒ ƒ | j	 d t
 j | ƒ | j d t
 j ƒ | j	 d t
 j | d ƒ | j d t | d ƒ ƒ | j d t
 j ƒ | j d t d ƒ ƒ | j	 d t
 j | ƒ | j d t
 j ƒ | j	 d t
 j | d ƒ | j d t | d ƒ ƒ | j d t
 j ƒ | j d	 t d
 ƒ ƒ | j	 d	 t
 j |	 ƒ | j d	 t
 j ƒ | j	 d t
 j |
 d ƒ | j d t |
 d ƒ ƒ | j d t
 j ƒ | j d t d ƒ ƒ | j	 d t
 j | ƒ |  j | ƒ rÓ| j	 d t
 j d t d ƒ ƒ | j t ƒ n] |  j | ƒ } |  j  d k  r|  j | | ƒ n, | r0| j | j ƒ | |  j t | ƒ <n  |  j  d 8_  q Wd S(   sG   Recursive method to create each item (and associated data) in the tree.i   i    s   Function or module names*   Time in function (including sub-functions)i   i   s-   Local time in function (not in sub-functions)i   i   s+   Total number of calls (including recursion)i   i   s#   File:line where function is defineds   (%s)t	   recursionN(   Rõ   R/  RE  Rà   Rö   R¢   R  t
   setToolTipRI   t   setDataR   t   DisplayRolet   setIconRò   t   setTextAlignmentt
   AlignRightt   setForegroundR	   t	   AlignLeftt   is_recursiveRd   RJ   R  R"  t   setChildIndicatorPolicyt   ShowIndicatorR÷   t   id(   R.   t
   parentItemt   children_listRD  Ro   R  R+  R.  R*  t   total_callst   total_calls_dift   loc_timet   loc_time_dift   cum_timet   cum_time_dift
   child_itemt   callees(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR"  r  sP    * c         C€  s5   |  j  | ƒ \ } } |  j ƒ  j j | | d ƒ d  S(   NR0   (   R  Rf   t	   edit_gotoR‚   (   R.   R  Ro   R  (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRý   ²  s    c         C€  sQ   | j  ƒ  d k rM t | ƒ |  j k rM |  j t | ƒ } |  j | | ƒ n  d  S(   Ni    (   t
   childCountRR  R÷   R"  (   R.   R  R\  (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRÿ   ¶  s    'c         C€  s   | j  ƒ  } xn | r| | j d t j ƒ | j d t j ƒ k rm | j d t j ƒ | j d t j ƒ k rm t S| j  ƒ  } q Wt S(   s5   Returns True is a function is a descendant of itself.i    i   (   Rf   R½   R   RI  RJ   Rc   (   R.   R[  t   ancestor(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRO  »  s    	c         C€  s,   g  t  |  j ƒ  ƒ D] } |  j | ƒ ^ q S(   s   Iterate over top level items(   t   ranget   topLevelItemCountt   topLevelItem(   R.   t   _i(    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   get_top_level_itemsÉ  s    c         €  sb   g  ‰ d ‡  ‡ f d † ‰  x@ |  j  ƒ  D]2 } ˆ j | ƒ | d k r( ˆ  | d | ƒq( q( Wˆ S(   s+   Return all items with a level <= `maxlevel`i   c         €  sf   | d 7} xU t  |  j ƒ  ƒ D]A } |  j | ƒ } ˆ j | ƒ | | k r ˆ  | | | ƒ q q Wd  S(   Ni   (   R`  R^  t   childR¢   (   R  t   maxlevelt   levelR   t   citem(   t   add_to_itemlistt   itemlist(    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRi  Ð  s    
i    Rf  (   Rd  R¢   (   R.   Rf  t   tlitem(    (   Ri  Rj  sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt	   get_itemsÍ  s    c         C€  s{   |  j  | 7_  |  j  d k  r* d |  _  n  |  j ƒ  |  j  d k rw x1 |  j d |  j  d ƒ D] } | j t ƒ q] Wn  d S(   sB   Change the view depth by expand or collapsing all same-level nodesi    Rf  i   N(   Rø   t   collapseAllRl  t   setExpandedRJ   (   R.   t   change_in_depthR  (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyR9   Ý  s    
 N(   RÎ   RÏ   RÐ   R   RA   R?   R  R  RÅ   RÇ   RY   Rr   RW   R  R  RÈ   R/  t   staticmethodR7  RA  RE  R"  Rý   Rÿ   RO  Rd  Rl  R9   (    (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyRT   —  s0   											 			@					c         C€  s  |  d k r d g S|  d k  r# g  St  t d |  d d ƒ ƒ } |  d } |  d d d } d } d } xx | | k rá | | rÆ | | d d } d | | <x' | | k  rÂ d | | <| | 7} qŸ Wn  | d } d | d } qj Wd g g  | D] } | rï | ^ qï S(   se   
    Simple test function
    Taken from http://www.huyng.com/posts/python-performance-analysis/
    i   i   i   g      à?i    (   t   listR`  (   t   nR6  t   mroott   halfR  R5  t   jR	  (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   primesë  s&    




c    	      C€  sò   d d l  }  d d l } d d l m } |  j t ƒ } | j d d ƒ \ } } t j | d ƒ 6 } | j	 d d ƒ | j	 | d ƒ | j	 d	 ƒ Wd QX| d
 d ƒ } t
 d ƒ } | j d d ƒ | j ƒ  | j | ƒ t j | j ƒ  ƒ d S(   s   Run widget testiÿÿÿÿN(   t   qapplicationt   suffixs   .pyt   ws   # -*- coding: utf-8 -*-s   

s   primes(100000)t	   test_timei   i   iX  (   t   inspectt   tempfilet   spyder.utils.qthelpersRw  t	   getsourceRv  t   mkstempR    t   fdopent   writeR%   RA   t   resizet   showR€   R§   t   exitR…   (	   R{  R|  Rw  t	   primes_sct   fdt   scriptt   ft   appRl   (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   test  s    
t   __main__(A   RÐ   t
   __future__R    R    t   os.patht   pathRz   t	   itertoolsR   R§   RÉ   RØ   t   qtpy.compatR   R   t   qtpy.QtCoreR   R   R   R   R   t
   qtpy.QtGuiR	   t   qtpy.QtWidgetsR
   R   R   R   R   R   R   R   t   spyder.config.baseR   R   t   spyder.py3compatR   t   spyder.utilsR   RH   R}  R   R   R   R#   R   t   spyder.widgets.comboboxesR   t   spyder.utils.miscR   R   t*   spyder.widgets.variableexplorer.texteditorR   RI   t   KeyErrorR‡   t   gettextR$   R%   Rß   Rà   RT   Rv  RŠ  RÎ   (    (    (    sB   lib/python2.7/site-packages/spyder_profiler/widgets/profilergui.pyt   <module>   sF   (:	ÿ 6	ÿ U		