ó
‹²,]c           @   sd  d  Z  d d l Z d d l Z d d l j 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 d d l m Z d d l m Z d d l m Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z  d e f d „  ƒ  YZ! d S(   s   Customized combobox widgets.iÿÿÿÿN(   t   QEventt   Qtt   QTimert   QUrlt   Signal(   t   QFont(   t	   QComboBoxt
   QCompletert	   QLineEditt   QSizePolicyt   QToolTip(   t   _(   t   to_text_string(   t   IconLineEditt   BaseComboBoxc           B   s˜   e  Z d  Z e e e ƒ Z e e ƒ Z e e ƒ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   s   Editable combo box base classc         C   sL   t  j |  | ƒ |  j t ƒ |  j t |  ƒ ƒ d |  _ |  j ƒ  |  _ d  S(   Ni    (	   R   t   __init__t   setEditablet   Truet   setCompleterR   t   numpresst   currentTextt   selected_text(   t   selft   parent(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR   &   s
    	c         C   s‡   | j  ƒ  t j k rw | j ƒ  t j k rw |  j j t ƒ |  j	 d 7_	 |  j	 d k rs t
 j d |  j ƒ |  _ n  t St j |  | ƒ S(   sK   Qt Override.

        Filter tab keys and process double tab keys.
        i   i  (   t   typeR    t   KeyPresst   keyR   t   Key_Tabt   sig_tab_pressedt   emitR   R   R   t
   singleShott   handle_keypresst
   presstimerR   t   event(   R   R!   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR!   .   s    *c         C   s–   | j  ƒ  t j k s* | j  ƒ  t j k rP |  j ƒ  r’ |  j ƒ  |  j ƒ  q’ nB | j  ƒ  t j k r‚ |  j |  j	 ƒ |  j ƒ  n t
 j |  | ƒ d S(   s7   Qt Override.

        Handle key press events.
        N(   R   R   t
   Key_Returnt	   Key_Entert   add_current_text_if_validt   selectedt   hide_completert
   Key_Escapet   set_current_textR   R   t   keyPressEvent(   R   R!   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR)   ;   s    *
c         C   s/   |  j  d k r" |  j j t ƒ n  d |  _  d S(   s4   When hitting tab, it handles if single or double tabi   i    N(   R   t   sig_double_tab_pressedR   R   (   R   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR   K   s    c         C   s   d S(   s`   
        Return True if string is valid
        Return None if validation can't be done
        N(    (   R   t   qstr(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyt   is_validQ   s    c         C   s   |  j  j t t ƒ d S(   s9   Action to be executed when a valid item has been selectedN(   t   validR   R   (   R   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR%   X   s    c         C   sÃ   |  j  | ƒ } x, | d k r= |  j | ƒ |  j  | ƒ } q W|  j d | ƒ |  j  d ƒ } | d k r² |  j | ƒ |  j d d ƒ | d k r¢ |  j d ƒ q¿ |  j d ƒ n |  j d ƒ d S(   sV   Add text to combo box: add a new item if text is not found in
        combo box items.iÿÿÿÿi    t    i   N(   t   findTextt
   removeItemt
   insertItemt   setCurrentIndex(   R   t   textt   index(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyt   add_text\   s    c         C   s   |  j  ƒ  j t | ƒ ƒ d S(   s0   Sets the text of the QLineEdit of the QComboBox.N(   t   lineEditt   setTextR   (   R   R3   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR(   o   s    c         C   s   |  j  ƒ  } |  j | ƒ d S(   s9   Add current text to combo box history (convenient method)N(   R   R5   (   R   R3   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyt   add_current_texts   s    c         C   sI   |  j  |  j ƒ  ƒ } | s' | d k r5 |  j ƒ  t S|  j |  j ƒ d S(   s.   Add current text to combo box history if validN(   R,   R   t   NoneR8   R   R(   R   (   R   R-   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR$   x   s
    
c         C   s   |  j  t g  |  ƒ ƒ d S(   s   Hides the completion widget.N(   R   R   (   R   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR&      s    (   t   __name__t
   __module__t   __doc__R   t   boolR-   R   R*   R   R!   R)   R   R,   R%   R5   R(   R8   R$   R&   (    (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR       s   											t   PatternComboBoxc           B   s    e  Z d  Z d d e d „ Z RS(   s   Search pattern combo boxc         C   s¦   t  j |  | ƒ t |  j ƒ  d ƒ r; |  j ƒ  j t ƒ n  | rT |  j t j ƒ n  |  j	 t
 j t
 j ƒ | d  k	 r† |  j | ƒ n  | d  k	 r¢ |  j | ƒ n  d  S(   Nt   setClearButtonEnabled(   R   R   t   hasattrR6   R?   R   t   setSizeAdjustPolicyR   t   AdjustToMinimumContentsLengtht   setSizePolicyR	   t	   Expandingt   FixedR9   t   addItemst
   setToolTip(   R   R   t   itemst   tipt   adjust_to_minimum(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR   ˆ   s    N(   R:   R;   R<   R9   R   R   (    (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR>   †   s   t   EditableComboBoxc           B   s8   e  Z d  Z d „  Z d d „ Z d „  Z e d „ Z RS(   s'   
    Editable combo box + Validate
    c         C   su   t  j |  | ƒ t ƒ  |  _ |  j ƒ  |  _ |  j t j ƒ |  j	 j
 |  j ƒ i t d ƒ t 6t d ƒ t 6|  _ d  S(   Ns"   Press enter to validate this entrys   This entry is incorrect(   R   R   R   t   fontR   R   RA   R   RB   t   editTextChangedt   connectt   validateR   R   t   Falset   tips(   R   R   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR   ›   s    R.   c         C   s&   t  j |  j |  j ƒ  ƒ | |  ƒ d S(   s   Show tipN(   R
   t   showTextt   mapToGlobalt   pos(   R   RI   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyt   show_tip¨   s    c         C   s    t  j |  ƒ |  j ƒ  |  _ d S(   s9   Action to be executed when a valid item has been selectedN(   R   R%   R   R   (   R   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR%   ¬   s    c         C   s}   |  j  | k r2 | d k r2 |  j j t t ƒ d S|  j | ƒ } | ry | rc |  j j t t ƒ qy |  j j t t ƒ n  d S(   s   Validate entered pathR.   N(   R   R-   R   R   R,   RP   (   R   R+   t   editingR-   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyRO   ±   s    (   R:   R;   R<   R   RU   R%   R   RO   (    (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyRK   –   s
   		t   PathComboBoxc           B   sz   e  Z d  Z e e ƒ Z e d „ Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d d „ Z d „  Z d	 „  Z d
 „  Z RS(   s+   
    QComboBox handling path locations
    c         C   sÕ   t  j |  | ƒ t |  ƒ } | r5 |  j t j ƒ n& |  j t j ƒ |  j t j	 t j
 ƒ i t d ƒ t 6d t 6|  _ |  j | ƒ |  j j |  j ƒ |  j j |  j ƒ |  j j |  j ƒ |  j j | j ƒ d  S(   Ns!   Press enter to validate this pathR.   (   RK   R   R   RA   R   t   AdjustToContentsRB   RC   R	   RD   RE   R   R   RP   RQ   t   setLineEditt   highlightedRN   t   add_tooltip_to_highlighted_itemR   t   tab_completeR*   t   double_tab_completeR-   t   update_status(   R   R   t   adjust_to_contentst   lineedit(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR   Å   s    c         C   s<   t  |  j ƒ  d d ƒ } | r( | ƒ  n  t j |  | ƒ d S(   s;   Handle focus in event restoring to display the status icon.t   show_status_iconN(   t   getattrR6   R9   R   t   focusInEvent(   R   R!   t   show_status(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyRc   Ü   s    
c            ss   ˆ j  ƒ  s7 ˆ j ƒ  ‰  t j d ‡  ‡ f d †  ƒ n  t ˆ j ƒ  d d ƒ } | r_ | ƒ  n  t j ˆ | ƒ d S(   s>   Handle focus out event restoring the last valid selected path.i2   c              s   ˆ  j  ˆ j ƒ S(   N(   R7   R   (    (   R`   R   (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyt   <lambda>é   R.   t   hide_status_iconN(   R,   R6   R   R   Rb   R9   R   t   focusOutEvent(   R   R!   t   hide_status(    (   R`   R   s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyRg   ã   s    
c         C   sm   t  |  j ƒ  ƒ } t j | d ƒ } t g  | D] } t j | ƒ r/ | ^ q/ ƒ } |  j t | |  ƒ ƒ | S(   s"   Find available completion options.t   *(   R   R   t   globt   sortedt   ospt   isdirR   R   (   R   R3   t   optst   opt(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyt   _complete_optionsñ   s
    .c         C   s5   |  j  ƒ  } t | ƒ d k r1 |  j ƒ  j ƒ  n  d S(   s;   If several options available a double tab displays options.i   N(   Rp   t   lent	   completert   complete(   R   Rn   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR]   ù   s    c         C   sG   |  j  ƒ  } t | ƒ d k rC |  j | d t j ƒ |  j ƒ  n  d S(   sU   
        If there is a single option available one tab completes the option.
        i   i    N(   Rp   Rq   R(   t   ost   sepR&   (   R   Rn   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR\   ÿ   s    c         C   s.   | d k r |  j ƒ  } n  t j t | ƒ ƒ S(   s   Return True if string is validN(   R9   R   Rl   Rm   R   (   R   R+   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR,     s    c         C   s9   |  j  ƒ  |  _ |  j j t t ƒ |  j j |  j ƒ d S(   s9   Action to be executed when a valid item has been selectedN(   R   R   R-   R   R   t   open_dir(   R   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR%     s    c         C   sU   |  j  ƒ  } t j | ƒ rD | rD | d t j k rD | d  } qD n  |  j | ƒ d S(   s“   
        Add current text to combo box history (convenient method).
        If path ends in os separator ("" windows, "/" unix) remove it.
        iÿÿÿÿN(   R   Rl   Rm   Rt   Ru   R5   (   R   R3   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR8     s
    c         C   s#   |  j  | |  j | ƒ t j ƒ d S(   st   
        Add a tooltip showing the full path of the currently highlighted item
        of the PathComboBox.
        N(   t   setItemDatat   itemTextR   t   ToolTipRole(   R   R4   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR[     s    N(   R:   R;   R<   R   t   strRv   RP   R   Rc   Rg   Rp   R]   R\   R9   R,   R%   R8   R[   (    (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyRW   ¿   s   								t   UrlComboBoxc           B   s&   e  Z d  Z e d „ Z d d „ Z RS(   s!   
    QComboBox handling urls
    c         C   s*   t  j |  | | ƒ |  j j |  j ƒ d  S(   N(   RW   R   RM   t
   disconnectRO   (   R   R   R_   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR   +  s    c         C   s+   | d k r |  j ƒ  } n  t | ƒ j ƒ  S(   s   Return True if string is validN(   R9   R   R   t   isValid(   R   R+   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR,   /  s    N(   R:   R;   R<   RP   R   R9   R,   (    (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR{   '  s   t   FileComboBoxc           B   s,   e  Z d  Z d e e d „ Z d d „ Z RS(   s'   
    QComboBox handling File paths
    c         C   sx   t  j |  | | ƒ | r5 t |  ƒ } |  j | ƒ n  | rN |  j t j ƒ n& |  j t j ƒ |  j t	 j
 t	 j ƒ d  S(   N(   RW   R   R   RY   RA   R   RX   t   AdjustToContentsOnFirstShowRC   R	   RD   RE   (   R   R   R_   t   default_line_editt	   line_edit(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR   :  s    c         C   s.   | d k r |  j ƒ  } n  t j t | ƒ ƒ S(   s   Return True if string is validN(   R9   R   Rl   t   isfileR   (   R   R+   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR,   I  s    N(   R:   R;   R<   R9   RP   R   R,   (    (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR~   6  s   c         C   s\   t  j |  ƒ o% t  j |  ƒ d d k } t  j |  ƒ oO t  j t  j |  d ƒ ƒ } | p[ | S(   s.   Return True if path is a Python module/packagei   s   .pys   .pyws   __init__.py(   s   .pys   .pyw(   Rl   R‚   t   splitextRm   t   join(   t   patht	   is_modulet
   is_package(    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyt   is_module_or_packageP  s    (*t   PythonModulesComboBoxc           B   s/   e  Z d  Z e d „ Z d d „ Z d „  Z RS(   s€   
    QComboBox handling Python modules or packages path
    (i.e. .py, .pyw files *and* directories containing __init__.py)
    c         C   s   t  j |  | | ƒ d  S(   N(   RW   R   (   R   R   R_   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR   \  s    c         C   s+   | d k r |  j ƒ  } n  t t | ƒ ƒ S(   s   Return True if string is validN(   R9   R   Rˆ   R   (   R   R+   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR,   _  s    c         C   s'   t  j |  ƒ |  j j |  j ƒ  ƒ d S(   s9   Action to be executed when a valid item has been selectedN(   RK   R%   Rv   R   R   (   R   (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR%   e  s    N(   R:   R;   R<   RP   R   R9   R,   R%   (    (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyR‰   W  s   ("   R<   Rj   Rt   t   os.pathR…   Rl   t   qtpy.QtCoreR    R   R   R   R   t
   qtpy.QtGuiR   t   qtpy.QtWidgetsR   R   R   R	   R
   t   spyder.config.baseR   t   spyder.py3compatR   t   spyder.widgets.helperwidgetsR   R   R>   RK   RW   R{   R~   Rˆ   R‰   (    (    (    s8   lib/python2.7/site-packages/spyder/widgets/comboboxes.pyt   <module>   s"   	((f)h	