
,]c           @ s%  d  Z  d d l m Z m Z d d l Z d d l Z d d l j Z d d l	 Z	 d d l
 Z
 d d l Z d d l Z d d l m Z d d l m Z 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 m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% m& Z& m' Z' d d l( m) Z) d d	 l* m+ Z+ d d
 l, m- Z- m. Z. d d l/ m0 Z1 d d l2 m3 Z3 m4 Z4 d d l5 m6 Z6 d d l7 m8 Z8 d d l9 m: Z: d d l5 m; Z; d d l< m= Z= m> Z> d d l? m@ Z@ d d lA mB ZB d ZC d ZD d ZE d ZF d ZG d ZH d ZI d ZJ d ZK d ZL d   ZM d e f d      YZN d! e f d"     YZO d# e' f d$     YZP d% e% f d&     YZQ d' e% f d(     YZR d) e# f d*     YZS d+ e: f d,     YZT d- e' f d.     YZU d/ e' f d0     YZV d1   ZW eX d2 k r!eW   n  d S(3   s   Find in files widgeti(   t   with_statementt   print_functionN(   t   getexistingdirectory(   t   QAbstractTextDocumentLayoutt   QTextDocument(   t   QEventt   QMutext   QMutexLockert   QSizet   Qtt   QThreadt   Signalt   Slot(   t   QApplicationt	   QComboBoxt   QHBoxLayoutt   QLabelt   QMessageBoxt   QSizePolicyt   QStylet   QStyledItemDelegatet   QStyleOptionViewItemt   QTreeWidgetItemt   QVBoxLayoutt   QWidget(   t   _(   t   EXCLUDE_PATTERNS(   t   to_text_stringt   PY2(   t   icon_manager(   t   is_text_filet   to_unicode_from_fs(   t   getcwd_or_home(   t   PatternComboBox(   t   OneColumnTree(   t   regexp_error_msg(   t   create_toolbuttont   get_icon(   t   get_font(   t   QWaitingSpinnert   ont   offi    i   i   i   i   i   i<   i   c         C sY   d } t  t |  d } |  t t j |    } |  t t j |   } | | | S(   Ns   ...g       @(   t   MAX_PATH_LENGTHt   lent   intt   matht   ceilt   floor(   t   textt   ellipsist   part_lent	   left_textt
   right_text(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   truncate_path?   s
    t   SearchThreadc           B s   e  Z d  Z e e  Z e e  Z e e  Z e e	 e
  Z e e  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   s   Find in files search threadc         C s   t  j |  |  t   |  _ d  |  _ d  |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ d  |  _ t |  _ i  |  _ d |  _ t |  _ d  S(   Ni    (   R
   t   __init__R   t   mutext   Nonet   stoppedt   resultst   pathlistt   total_matchest
   error_flagt   rootpatht   excludet   textst   text_ret	   completedt   Truet   case_sensitivet   Falset   is_file(   t   selft   parent(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7   O   s     													c         C s^   | |  _  | r$ t j |  |  _ n  | |  _ | |  _ | |  _ t |  _ t |  _	 | |  _
 d  S(   N(   R?   t   ret   compileR@   RA   RB   RG   RF   R:   RC   RE   (   RH   t   pathRG   R@   RA   RB   RE   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt
   initializea   s    						c         C s   y9 g  |  _  |  j r( |  j |  j  n |  j |  j  Wn* t k
 re t j   t d  |  _	 n X|  j
   |  j j |  j  d  S(   Ns&   Unexpected error: see internal console(   t	   filenamesRG   t   find_string_in_fileR?   t   find_files_in_patht	   Exceptiont	   tracebackt	   print_excR   R>   t   stopt   sig_finishedt   emitRC   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   runm   s    		

c         C s#   t  |  j   t |  _ Wd  QXd  S(   N(   R   R8   RD   R:   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRT   }   s    c         C s  |  j  d  k r g  |  _  n  |  j  j |  xt j |  D]\ } } } t |  j   |  j rg t SWd  QXy4x | D] } t |  j   |  j r t SWd  QXt j	 j
 | |  } |  j r t j |  j | t j  r | j |  qx | d k s| d k rx | j |  qx qx Wx | D]~ } t |  j   |  j rAt SWd  QXt j	 j
 | |  } |  j rt j |  j |  rqn  t |  r|  j |  qqWWq; t j k
 rt d  |  _ t SXq; Wt S(   Ns   .gits   .hgs   invalid regular expression(   R<   R9   t   appendt   ost   walkR   R8   R:   RF   RL   t   joinR@   RJ   t   searcht   sept   removeR   RO   t   errorR   R>   RD   (   RH   RL   t   dirst   filest   dt   dirnamet   ft   filename(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRP      s>    	
	
		
	c      	   C s  t  |  _ |  j j |  yxyt t | d   D]b\ } } x |  j D] \ } } t |  j   |  j	 rq t  SWd  QX| } |  j
 s | j   } n  |  j r t j | |  } | d  k	 r Pq qH | j |  } | d k rH PqH qH Wy | j |  } Wn t k
 r| } n X|  j
 s+| j   } n  |  j rx]t j | |  D]v }	 t |  j   |  j	 rjt  SWd  QX|  j d 7_ |  j j t j |  | d |	 j   |	 j   | f |  j  qGWq2 | j |  } x | d k rt |  j   |  j	 rt  SWd  QX|  j d 7_ |  j j t j |  | d | | t |  | f |  j  x= |  j D]2 \ } } | j | | d  } | d k rZPqZqZWqWq2 WWn1 t k
 r}
 |
 j \ } } t d  |  _ n Xt |  _ d  S(   Nt   rbii   s)   permission denied errors were encountered(    RF   R>   t   sig_current_fileRV   t	   enumeratet   openRA   R   R8   R:   RE   t   lowerRB   RJ   R\   R9   t   findt   decodet   UnicodeDecodeErrort   finditerR=   t   sig_file_matcht   ospt   abspatht   startt   endR+   t   IOErrort   argsR   RD   RC   (   RH   t   fnamet   linenot   lineR0   t   enct   line_searcht   foundt   line_dect   matcht   xxx_todo_changemet   _errnot	   _strerror(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRO      sl    	"	
		
			
		

c         C s   |  j  |  j |  j |  j f S(   N(   R;   R<   R=   R>   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   get_results   s    (   t   __name__t
   __module__t   __doc__R   t   boolRU   t   strRg   t   sig_current_foldert   tupleR,   Ro   t   objectt   sig_out_printR7   RM   RW   RT   RP   RO   R   (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR6   G   s   					!	:t   SearchInComboBoxc           B s   e  Z d  Z g  d d  Z d   Z d   Z d   Z d   Z d   Z	 e
   d    Z e
   d    Z d	   Z d
   Z d   Z RS(   s[   
    Non editable combo box handling the path locations of the FindOptions
    widget.
    c         C s   t  t |   j |  |  j t j t j  |  j t d   |  j	 t
  d |  _ d  |  _ d  |  _ d  |  _ |  j t d   d } |  j d | t j  |  j t d   t d  } |  j d | t j  |  j   j d d  j t
  |  j t d	  j d
 d   t d  } |  j d | t j  |  j d  |  j t d   t d  } |  j d | t j  |  j t d   t d  } |  j d | t j  |  j d  x | D] } |  j |  qW|  j j |  j  |  j   j |   d  S(   Ns   Search directoryt    s   Current working directorysF   Search in all files and directories present on the current Spyder pathi    t   ProjectsS   Search in all files and directories present on the current project path (if opened)i   t   Filet   &s   Search in current opened filei   i   s   Select other directorys1   Search in other folder present on the file systemi   s   Clear this lists#   Clear the list of other directoriesi   i   (   t   superR   R7   t   setSizePolicyR   t	   Expandingt   Fixedt
   setToolTipR   t   setEditableRF   RL   R9   t   project_patht	   file_patht   external_patht   addItemt   setItemDataR	   t   ToolTipRolet   modelt   itemt
   setEnabledt   replacet   insertSeparatort   add_external_patht   currentIndexChangedt   connectt   path_selection_changedt   viewt   installEventFilter(   RH   t   external_path_historyRI   t   ttipRL   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7      s<    				c         C s   t  j |  s d S|  j |  j |   |  j |  |  j |  j   d | t j  x' |  j   t	 t
 k r |  j t
  qY Wd S(   s@  
        Adds an external path to the combobox if it exists on the file system.
        If the path is already listed in the combobox, it is removed from its
        current position and added back at the end. If the maximum number of
        paths is reached, the oldest external path is removed from the list.
        Ni   (   Rp   t   existst
   removeItemt   findTextR   R   t   countR	   R   t   MAX_PATH_HISTORYt   EXTERNAL_PATHS(   RH   RL   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     s     c         C s5   g  t  t |  j    D] } t |  j |   ^ q S(   s<   Returns a list of the external paths listed in the combobox.(   t   rangeR   R   R   t   itemText(   RH   t   i(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   get_external_paths   s    c         C s*   x# |  j    t k r% |  j t  q Wd S(   s5   Remove all the external paths listed in the combobox.N(   R   R   R   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   clear_external_paths%  s    c         C sP   |  j    } | t k r |  j S| t k r2 |  j S| t k rE |  j S|  j Sd S(   sh   
        Returns the path corresponding to the currently selected item
        in the combobox.
        N(   t   currentIndext   CWDRL   t   PROJECTR   t	   FILE_PATHR   R   (   RH   t   idx(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   get_current_searchpath*  s    c         C s   |  j    t k r t St Sd S(   s2   Returns whether the current search path is a file.N(   R   R   RD   RF   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   is_file_search9  s    c         C s   |  j    } | t k rm |  j   } t |  d k r] |  j |  |  j |  j   d  q |  j t  n | t k r t	 j
 |  t d  t d  t	 j t	 j B } | t	 j k r |  j   n  |  j t  n' | t k r t |  j |   |  _ n  d S(   s7   Handles when the current index of the combobox changes.i    i   s   Clear other directoriess3   Do you want to clear the list of other directories?N(   R   t   SELECT_OTHERt   select_directoryR+   R   t   setCurrentIndexR   R   t
   CLEAR_LISTR   t   questionR   t   Yest   NoR   R   R   R   R   (   RH   R   R   t   reply(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR   @  s"    	c         C sW   |  j  t  t |  t d   |  j  } | rF t t j |   } n  |  j  t  | S(   s   Select directory(	   t&   _SearchInComboBox__redirect_stdio_emitRF   R   R   RL   R   Rp   Rq   RD   (   RH   t	   directory(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR   V  s    c         C s   | d k rY d |  _ |  j   j t d  j t  |  j   t k r |  j t	  q n7 t
 j |  } | |  _ |  j   j t d  j t  d S(   s}   
        Sets the project path and disables the project search in the combobox
        if the value of path is None.
        i    N(   R9   R   R   R   R   R   RF   R   R   R   Rp   Rq   RD   (   RH   RL   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   set_project_patha  s    		c         C s   | j    t j k r | j   t j k r |  j   j   j   } | t	 k r |  j
 |  |  j   t |  j   d |  } | t	 k  r d n | } |  j   j |  j   j | d   |  j |  n  t St j |  | |  S(   s;   Used to handle key events on the QListView of the combobox.i   i    (   t   typeR   t   KeyPresst   keyR	   t
   Key_DeleteR   R   t   rowR   R   t	   showPopupt   minR   R   R   t   indexRD   R   t   eventFilter(   RH   t   widgett   eventR   t	   new_index(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR   p  s    *
%c         C sX   |  j    } xE | d k	 rS y | j j |  Wn t k
 rN | j    } q XPq Wd S(   s   
        Searches through the parent tree to see if it is possible to emit the
        redirect_stdio signal.
        This logic allows to test the SearchInComboBox select_directory method
        outside of the FindInFiles plugin.
        N(   RI   R9   t   redirect_stdioRV   t   AttributeError(   RH   t   valueRI   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   __redirect_stdio_emit  s    N(   R   R   R   R9   R7   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR      s   ,							t   FindOptionsc           B s   e  Z d  Z d Z e d  Z e   Z e   Z d   Z	 e
 e  d    Z d   Z d   Z e d  Z e d    Z d	   Z e d
    Z d   Z d   Z e d    Z d   Z d   Z RS(   s   Find widget with optionss"   background-color:rgb(255, 80, 80);s   Regular expression errorc          so  t  j   |  t | t t f  s1 | g } n  t | t t f  sR | g } n  t |
 t t f  ss |
 g }
 n  |   _ t   } t   | t d     _	 t
   d t d  d t d    _ t
   d t d  d t d    _   j j t    j j |	    j j t    j j |  d   _ t
   d   j   _   j j t    j j |  t
   d	 t d
  d t j d  d   f d   d t d  d t   _   j j j   j  t
   d	 t d  d t j d  d   f d   d t d  d t   _   j j t  x?   j	   j   j   j   j   j g D] } | j |  qVWt   } t   | t d     _ | d  k	 r| d k r|   j j    k  r  j j! |  n  t
   d t d  d t d    _"   j" j t    j" j |  t# t d   } | j$   j  x* |   j   j" g D] } | j |  qPWt   } t# t d   } t% |
 |    _& | j |  | j   j&    j	 j' j   f d      j j' j   f d    t(   } | j) d d d d  | j* |  | j* |  | j* |  | f   _   j |    j+ |    j, t- j. t- j/  d  S(   Ns   Search patternt   icons
   regexp.svgt   tips   Regular expressions   upper_lower.pngs   Case Sensitivet   toggledR0   t   SearchRk   t	   triggeredc            s     j  j   S(   N(   Rk   RV   (    (   RH   (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   <lambda>  R   s   Start searcht   text_beside_icont   StopRT   c            s     j  j   S(   N(   RT   RV   (    (   RH   (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     s    s   Stop searchs   Exclude patterni    s   Exclude:s
   Search in:c          s     j  j   S(   N(   Rk   RV   (   t   valid(   RH   (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     R   c          s     j  j   S(   N(   Rk   RV   (   R   (   RH   (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     R   (    (0   R   R7   t
   isinstancet   listR   t   supported_encodingsR   R!   R   t   search_textR$   R%   t   edit_regexpt   case_buttont   setCheckableRD   t
   setCheckedt   more_widgetst   toggle_more_optionst   more_optionst   imaR   t	   ok_buttont   clickedR   t   update_combost   stop_buttonR   RF   t	   addWidgett   exclude_patternR9   R   R   t   exclude_regexpR   t   setBuddyR   t   path_selection_comboR   R   t   setContentsMarginst	   addLayoutt	   setLayoutR   R   R   t   Minimum(   RH   RI   R   t   search_text_regexpR@   t   exclude_idxR   R   R   RE   R   t   hlayout1R   t   hlayout2t   exclude_labelt   hlayout3t   search_on_labelt   vlayout(    (   RH   s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7     s    												c         C s   xf |  j  D][ } xR t | j    D]> } | r; |  j   sB | r# | j |  j   j |  q# q# Wq
 W| r t j d  } t	 d  } n t j d  } t	 d  } |  j
 j |  |  j
 j |  d  S(   Nt   options_lesss   Hide advanced optionst   options_mores   Show advanced options(   R   R   R   t	   isVisiblet   itemAtR   t
   setVisibleR   R   R   R   t   setIconR   (   RH   t   statet   layoutR   R   R   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     s    'c         C s0   |  j  j   j j   |  j j   j j   d  S(   N(   R   t   lineEditt   returnPressedRV   R   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     s    c         C s=   | r, |  j  j |  |  j  j   j   n  |  j  j   d  S(   N(   R   t   add_textR	  t	   selectAllt   setFocus(   RH   R0   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   set_search_text
  s    c         C s  |  j  j   } |  j j   } |  j j   } | r g  t |  j j    D] } t |  j j |   ^ qI } g  t |  j	 j    D] } t |  j	 j |   ^ q } |  j	 j
   } |  j j   }	 |  j j   }
 | | | | | |
 | |	 f S|  j j   j d  |  j	 j   j d  |  j j d  |  j	 j d  t |  j j    } | s[d Sy | j d  d f g } Wn_ t k
 rg  } xI |  j D]: } y  | j | j |  | f  Wqt k
 rqXqWn Xt |  j	 j    } | s$g  | D]  } | d j   | d f ^ q} n  |  j j   } |  j j   } | sg  | j d  D]- } | j   d k rXt j | j    ^ qX} d j |  } n  | rt |  } | r|  j	 j   } | j |  j   |  j! d t |  } |  j	 j |  d St# j$ |  } n  | rt | d d  } | ru|  j j   j |  j   |  j! d t |  } |  j j |  d Sg  | D]# } t# j$ | d  | d f ^ q|} n  | | | | | | f S(	   s   Get optionsR   Ns   utf-8i    i   t   ,t   |u   : (%   R   t	   isCheckedR   R   R   R   R   R   R   R   R   R   R   R   R	  t   setStyleSheetR   t   currentTextt   encodet   UnicodeEncodeErrorR   RX   Rm   Rj   R   R   t   splitt   stript   fnmatcht	   translateR[   R#   t   REGEX_INVALIDt   REGEX_ERRORR9   RJ   RK   (   RH   t   to_saveRB   t
   exclude_reRE   R   R   R@   R   t   path_historyR   t   utextRA   Ry   R0   t   file_searchRL   R   t   itemst	   error_msgt   exclude_editt   tooltipt   x(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   get_options  sv    77
 0-3c         C s
   |  j  j S(   N(   R   RL   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRL   `  s    c         C s   t  j |  |  j _ d  S(   N(   Rp   Rq   R   RL   (   RH   R   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   set_directoryd  s    c         C s
   |  j  j S(   N(   R   R   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR   g  s    c         C s   |  j  j |  d  S(   N(   R   R   (   RH   RL   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR   k  s    c         C s   |  j  j d   d  S(   N(   R   R   R9   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   disable_project_searchn  s    c         C s
   |  j  j S(   N(   R   R   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR   q  s    c         C s   | |  j  _ d  S(   N(   R   R   (   RH   RL   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   set_file_pathu  s    c         C s   | j    t j @} | j    t j @} | j   t j t j f k rT |  j j   nQ | j   t j	 k r | r | r |  j
   j j |  j    n t j |  |  d S(   s"   Reimplemented to handle key eventsN(   t	   modifiersR	   t   ControlModifiert   ShiftModifierR   t	   Key_Entert
   Key_ReturnRk   RV   t   Key_FRI   t   toggle_visibilityR  R   t   keyPressEvent(   RH   R   t   ctrlt   shift(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR1  x  s    ! (   R   R   R   R  R   R  R   Rk   RT   R7   R   R   R   R   R  RF   R&  t   propertyRL   R'  R   R   R(  R   R)  R1  (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     s$   			^		P				t   LineMatchItemc           B s>   e  Z d    Z d   Z d   Z d   Z d   Z d   Z RS(   c         C sA   | |  _  | |  _ | |  _ t j |  | |  j   g t j  d  S(   N(   Rw   t   colnoR}   R   R7   t   __repr__t   Type(   RH   RI   Rw   R6  R}   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7     s
    			c         C sL   t  |  j  j   } t   } t  d  } | j | j   |  j |  j |  S(   NsI   <b>{1}</b> ({2}): <span style='font-family:{0};font-size:75%;'>{3}</span>(   R   R}   t   rstripR&   t   formatt   familyRw   R6  (   RH   R}   t   fontt   _str(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7    s    	c         C s
   |  j    S(   N(   R7  (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   __unicode__  s    c         C s
   |  j    S(   N(   R7  (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   __str__  s    c         C s   |  j  | j  k  S(   N(   Rw   (   RH   R%  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   __lt__  s    c         C s   |  j  | j  k S(   N(   Rw   (   RH   R%  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   __ge__  s    (   R   R   R7   R7  R>  R?  R@  RA  (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR5    s   					t   FileMatchItemc           B s#   e  Z d    Z d   Z d   Z RS(   c         C s{   | |  _  t j |  |  _ t d  } | j t j |  t j |   } t j |  | | g t j	  |  j
 d |  d  S(   Ns)   <b>{0}</b><br><small><em>{1}</em></small>i    (   t   sortingRp   t   basenameRe   R   R:  Rc   R   R7   R8  R   (   RH   RI   Re   RC  t   title_formatt   title(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7     s    	c         C s+   |  j  d t k r# |  j | j k  St Sd  S(   Nt   status(   RC  t   ONRe   RF   (   RH   R%  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR@    s    c         C s+   |  j  d t k r# |  j | j k St Sd  S(   NRG  (   RC  RH  Re   RF   (   RH   R%  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRA    s    (   R   R   R7   R@  RA  (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRB    s   		t   ItemDelegatec           B s#   e  Z d    Z d   Z d   Z RS(   c         C s   t  j |  |  d  S(   N(   R   R7   (   RH   RI   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7     s    c   	      C s
  t  |  } |  j | |  | j d  k r7 t j   n | j j   } t   } | j d  | j | j	  d | _	 | j
 t j | |  t j   } | j t j |  } | j   | j | j    | j | j | j     | j   j | |  | j   d  S(   Ni    R   (   R   t   initStyleOptionR   R9   R   t   styleR   t   setDocumentMargint   setHtmlR0   t   drawControlR   t   CE_ItemViewItemR   t   PaintContextt   subElementRectt   SE_ItemViewItemTextt   saveR  t   topLeftt   setClipRectt
   translatedt   documentLayoutt   drawt   restore(	   RH   t   paintert   optionR   t   optionsRK  t   doct   ctxt   textRect(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   paint  s     		
c         C sj   t  |  } |  j | |  t   } | j | j  | j | j j    t | j	   | j
   j    S(   N(   R   RJ  R   RM  R0   t   setTextWidtht   rectt   widthR   t
   idealWidtht   sizet   height(   RH   R[  R   R\  R]  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   sizeHint  s    	(   R   R   R7   R`  Rg  (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRI    s   		t   ResultsBrowserc           B sk   e  Z d    Z d   Z d   Z e e  d    Z d   Z d   Z	 d   Z
 e e e  d    Z RS(   c         C s   t  j |  |  d  |  _ d  |  _ d  |  _ d  |  _ d  |  _ i  |  _ d  |  _	 d  |  _
 |  j d  |  j t  |  j t  d  |  _ |  j d t j  |  j t |    |  j t  |  j   j j |  j  d  S(   NR   i    (   R"   R7   R9   R   R;   R=   R>   RC   RC  t   dataRa   t	   set_titlet   set_sortingt   OFFt   setSortingEnabledRF   t
   root_itemst   sortByColumnR	   t   AscendingOrdert   setItemDelegateRI  t   setUniformRowHeightst   headert   sectionClickedR   t   sort_section(   RH   RI   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7     s"    									c         C s_   |  j  j t |  j     } | d k	 r[ | \ } } } |  j   j j | | |  j  n  d S(   s   Double-click eventN(	   Ri  t   gett   idt   currentItemR9   RI   t	   edit_gotoRV   R   (   RH   R   t   itemdataRe   Rw   R6  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt	   activated  s    c         C s*   | |  j  d <|  j   j | t k  d S(   s/   Enable result sorting after search is complete.RG  N(   RC  Rs  t   setSectionsClickableRH  (   RH   t   flag(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRk     s    c         C s   |  j  t  d  S(   N(   Rm  RD   (   RH   R   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRu    s    c         C s   |  j  |  d S(   s   Click eventN(   R{  (   RH   R   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR   	  s    c         C ss   |  j    |  j t  d |  _ i  |  _ i  |  _ |  j t  | |  _ d | } t	 d  } |  j
 | |  d  S(   Ni    s   '%s' - s   String not found(   t   clearRm  RF   t	   num_filesRi  Ra   Rk  Rl  R   R   Rj  (   RH   R   RF  R0   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   clear_title  s    
				
c          s  d } d } d } i d d 6d d 6d d	 6d
 d 6d d 6    f d   } t  re t | d d } n t |  } | |  | | | !| | } }	 }
 t |  | k r@t |  t |	  d } | j d  } t |  } | d k r!| d } t |  | k r| | | } n  | g } n  |
 j d  }
 t |
  } | d k r|
 d }
 t |
  | k ru|
 |  | }
 n  |
 g }
 n  | d } |
 d  }
 t |  | k  r| g | } n  t |
  | k  r|
 | g }
 n  d j |  } d j |
  }
 t |  | k r| | d } n  t |
  | k r@|
 d  | }
 q@n  d } | |  } | |
  }
 | |	  }	 | j | |	 |
  } | S(   Nu   ...iP   i(   u   &amp;u   &u   &quot;u   "u   &apos;u   'u   &gt;u   >u   &lt;u   <c          s   d j    f d   |  D  S(   s   Produce entities within text.u    c         3 s!   |  ] }   j  | |  Vq d  S(   N(   Rv  (   t   .0t   c(   t   html_escape_table(    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pys	   <genexpr>(  s    (   R[   (   R0   (   R  (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   html_escape&  s    t   encodingt   utf8i   u    i   i    ii   ii   u   {0}<b>{1}</b>{2}(   R   R   R+   R  R[   R:  (   RH   Rx   Rr   Rs   R1   t   max_line_lengtht   max_num_char_fragmentR  t   leftR}   t   rightt   offsett   num_left_wordst   num_right_wordst   line_match_formatt
   trunc_line(    (   R  s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   truncate_result  s`    
#



c         C sK  | \ } } } } } | |  j  k re t |  | |  j  } | j t  | |  j  | <|  j d 7_ n  |  j }	 d |	 }
 |  j } | d k r t d  } nG t d  } t d  } | d k r | d 7} n  d | | | | f } |  j |
 |  |  j  | } |  j	 | | |  } t
 | | | |  } | | | f |  j t |  <d	 S(
   s"   Real-time update of search resultsi   s   '%s' - i    s   String not founds
   matches int   filet   ss   %d %s %d %sN(   Ra   RB  RC  t   setExpandedRD   R  R   R   Rj  R  R5  Ri  Rw  (   RH   R;   t   num_matchesRe   Rw   R6  t	   match_endRx   t	   file_itemR   RF  t   nb_filesR0   t   text_matchest
   text_filesR   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   append_result^  s,    	
		(   R   R   R7   R{  Rk  R   R,   Ru  R   R  R  R   R  (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRh    s   						Et   FileProgressBarc           B sJ   e  Z d  Z d   Z e e  e d   Z d   Z d   Z	 d   Z
 RS(   s$   Simple progress spinner with a labelc         C s   t  j |  |  t |   |  _ t |  d t |  _ |  j j d  |  j j d  t	   } | j
 |  j  | j
 |  j  |  j |  d  S(   Nt   centerOnParenti   i   (   R   R7   R   t   status_textR'   RF   t   spinnert   setNumberOfLinest   setInnerRadiusR   R   R   (   RH   RI   R  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7     s    	c         C sS   t  |  } | s* t d  j |  } n t d  j |  } |  j j |  d  S(   Nu    Scanning: {0}u#    Searching for files in folder: {0}(   R5   R   R:  R  t   setText(   RH   RL   t   folderR0   t
   status_str(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   set_label_path  s
    c         C s   |  j  j t d   d  S(   Ns     Searching for files...(   R  R  R   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   reset  s    c         C s!   t  j |  |  |  j j   d S(   s-   Override show event to start waiting spinner.N(   R   t	   showEventR  Rr   (   RH   R   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR    s    c         C s!   t  j |  |  |  j j   d S(   s,   Override hide event to stop waiting spinner.N(   R   t	   hideEventR  RT   (   RH   R   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR    s    (   R   R   R   R7   R   R   RF   R  R  R  R  (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR  }  s   				t   FindInFilesWidgetc        
   B so   e  Z d  Z e   Z d e e d d e d e e g  d 	 Z	 d   Z
 d   Z e d	  Z d
   Z d   Z RS(   s   
    Find in files widget
    R   i    s   utf-8s
   iso-8859-1t   cp1252c         C s;  t  j |  |  |  j t d   d  |  _ t |   |  _ |  j j   t	 |  | | | | | | | |	 |
 
 |  _
 |  j
 j j |  j  |  j
 j j |  j  t |   |  _ t   } | j |  j  t   } | j   \ } } } } | j | d | |  | j |  j
  | j |  | j |  j  |  j |  d  S(   Ns   Find in filesi    (   R   R7   t   setWindowTitleR   R9   t   search_threadR  t
   status_bart   hideR   t   find_optionsRk   R   RT   t   stop_and_reset_threadRh  t   result_browserR   R   R   t   getContentsMarginsR   R   R   (   RH   RI   R   R   R@   R   R   R   R   RE   R   t   hlayoutR  R  t   _xR  t   bottom(    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR7     s,    
				c         C s   |  j  j |  d S(   s   Set search patternN(   R  R  (   RH   R0   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR    s    c          s8    j  j   } | d k r d S  j d t  t      _   j j j   j	    j j
 j   f d      j j j   f d      j j j   j j    j j j d      j j     j j   j  j j      j j |     j j     j  j j t    j  j j t    j j   d S(   s   Call the find functionNt   ignore_resultsc          s     j  j |  d t S(   NR  (   R  R  RF   (   R%  (   RH   (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     R   c          s     j  j |  d t S(   NR  (   R  R  RD   (   R%  (   RH   (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     R   c         S s   t  j j t |   d  S(   Ns   
(   t   syst   stdoutt   writeR   (   R%  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     R   (   R  R&  R9   R  RD   R6   R  RU   R   t   search_completeRg   R   Ro   R  R  R   R  R  R  R   R  RM   Rr   R   R   RF   R   t   show(   RH   R\  (    (   RH   s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyRk     s,    
	c         C sz   |  j  d k	 rv |  j  j   rZ | r= |  j  j j |  j  n  |  j  j   |  j  j   n  |  j  j d  d |  _  n  d S(   s'   Stop current search thread and clean-upN(	   R  R9   t	   isRunningRU   t
   disconnectR  RT   t   waitt	   setParent(   RH   R  (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR    s    c         C s   |  j  d t  d S(   s'   Perform actions before widget is closedR  N(   R  RD   (   RH   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   closing_widget  s    c         C s   |  j  j t  |  j j j t  |  j j j t  |  j	 j
   |  j  j   |  j d k rc d S|  j j   |  j j   } |  j   | d k	 r | \ } } } } |  j  j   n  d S(   s"   Current search thread has finishedN(   R  Rk  RH  R  R   R   RD   R   RF   R  R  t	   expandAllR  R9   RU   RV   R   R  R  (   RH   RC   R{   R;   R<   t   nbR>   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR     s    
N(   s   utf-8s
   iso-8859-1R  (   R   R   R   R   RU   RF   R   R9   RD   R7   R  Rk   R  R  R  (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyR    s    				c          C s   d d l  m }  d d l m } |    } t d  } | j d d  | j   | t  | | t   | | | t    | | | | t     g } x! | D] } | j	 j
 j |  q Wt j | j    d S(   s   Run Find in Files widget testi(   t   qapplication(   Rc   i  i  N(   t   spyder.utils.qthelpersR  t   os.pathRc   R  R9   t   resizeR  t   __file__R  R   R   R  t   exitt   exec_(   R  Rc   t   appR   t   external_pathsRL   (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   test  s    	
	!t   __main__(Y   R   t
   __future__R    R   R  RY   R  RL   Rp   RJ   R  R-   RR   t   qtpy.compatR   t
   qtpy.QtGuiR   R   t   qtpy.QtCoreR   R   R   R   R	   R
   R   R   t   qtpy.QtWidgetsR   R   R   R   R   R   R   R   R   R   R   R   t   spyder.config.baseR   t   spyder.config.mainR   t   spyder.py3compatR   R   t   spyder.utilsR   R   t   spyder.utils.encodingR   R   t   spyder.utils.miscR    t   spyder.widgets.comboboxesR!   t   spyder.widgets.onecolumntreeR"   R#   R  R$   R%   t   spyder.config.guiR&   t   spyder.widgets.waitingspinnerR'   RH  Rl  R   R   R   R   R   R   R*   R   R5   R6   R   R   R5  RB  RI  Rh  R  R  R  R   (    (    (    s9   lib/python2.7/site-packages/spyder/widgets/findinfiles.pyt   <module>   s^   :R	'&n	