ó
_y]c           @   sQ   d  Z  d d l Z d d l Z d d l m Z m Z d e j f d „  ƒ  YZ d S(   s.   A dropdown completer widget for the qtconsole.iÿÿÿÿN(   t   QtCoret   QtGuit   CompletionWidgetc           B   st   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z RS(   s&    A widget for GUI tab completion.
    c         C   s7  | j  } t | t j t j f ƒ s* t ‚ t t |  ƒ j d | ƒ | |  _	 |  j
 t j j ƒ |  j t j j ƒ |  j t j j ƒ |  j t j j ƒ |  j t j j ƒ |  j t j j ƒ | j ƒ  } |  j t j j ƒ | j | ƒ |  j |  j	 ƒ |  j t j j ƒ |  j  t j j! ƒ |  j" j# |  j$ ƒ d S(   sg    Create a completion widget that is attached to the specified Qt
            text edit widget.
        t   parentN(%   t   _controlt
   isinstanceR   t	   QTextEditt   QPlainTextEditt   AssertionErrort   superR   t   __init__t
   _text_editt   setEditTriggerst   QAbstractItemViewt   NoEditTriggerst   setHorizontalScrollBarPolicyR    t   Qtt   ScrollBarAlwaysOfft   setSelectionBehaviort
   SelectRowst   setSelectionModet   SingleSelectiont   setWindowFlagst   Popupt   setAttributet   WA_StaticContentst   focusPolicyt   setFocusPolicyt   NoFocust   setFocusProxyt   setFrameShadowt   QFramet   Plaint   setFrameShapet   StyledPanelt   itemActivatedt   connectt   _complete_current(   t   selft   console_widgett	   text_editt   original_policy(    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyR
      s"    	!	c         C   s™   | |  k r€ | j  ƒ  t j j k r€ |  j | j ƒ  ƒ } t j j | ƒ } | r` |  j	 | ƒ sl | |  k rp t
 S|  j ƒ  q€ n  t t |  ƒ j | | ƒ S(   sj    Reimplemented to handle mouse input and to auto-hide when the
            text edit loses focus.
        (   t   typeR    t   QEventt   MouseButtonPresst   mapToGlobalt   posR   t   QApplicationt   widgetAtt   isAncestorOft   Falset   cancel_completionR	   R   t   eventFilter(   R&   t   objt   eventR.   t   target(    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyR4   1   s    !c         C   sÑ   | j  ƒ  } | t j j t j j t j j f k r@ |  j ƒ  n | t j j k r_ |  j ƒ  nn | t j j	 t j j
 t j j t j j t j j t j j f k r· t t |  ƒ j | ƒ St j j |  j | ƒ d  S(   N(   t   keyR    R   t
   Key_Returnt	   Key_Entert   Key_TabR%   t
   Key_Escapet   hidet   Key_Upt   Key_Downt
   Key_PageUpt   Key_PageDownt   Key_Homet   Key_EndR	   R   t   keyPressEventR   R/   t	   sendEventR   (   R&   R6   R8   (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyRD   @   s    c         C   sU   t  t |  ƒ j | ƒ y |  j j j |  j ƒ Wn t k
 rC n X|  j |  ƒ d S(   sG    Reimplemented to disconnect signal handlers and event filter.
        N(	   R	   R   t	   hideEventR   t   cursorPositionChangedt
   disconnectt   _update_currentt	   TypeErrort   removeEventFilter(   R&   R6   (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyRF   R   s    c         C   s=   t  t |  ƒ j | ƒ |  j j j |  j ƒ |  j |  ƒ d S(   sD    Reimplemented to connect signal handlers and event filter.
        N(   R	   R   t	   showEventR   RG   R$   RI   t   installEventFilter(   R&   R6   (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyRL   \   s    i    c         C   sŸ  |  j  } |  j | ƒ } |  j ƒ  xW | D]O } t j ƒ  } | j t j j | ƒ | j	 | j
 d ƒ d ƒ |  j | ƒ q) W|  j ƒ  j ƒ  } t j j ƒ  j |  ƒ }	 |	 j ƒ  j ƒ  |	 j ƒ  | j ƒ  | d k  r| j | j ƒ  j ƒ  ƒ } | j | j ƒ  | ƒ n  |  j d ƒ |  j ƒ  j ƒ  j ƒ  }
 |  j | j ƒ  | j ƒ  |
 | ƒ | j t j j d | ƒ| j ƒ  |  _  |  j! d ƒ |  j" ƒ  |  j# ƒ  d S(   se    Shows the completion widget with 'items' at the position specified
            by 'cursor'.
        t   .iÿÿÿÿi    t   nN($   R   t   _get_top_left_positiont   clearR   t   QListWidgetItemt   setDataR    R   t   UserRolet   setTextt   splitt   addItemt   sizeHintt   heightR/   t   desktopt   availableGeometryt   sizet   yR-   t
   cursorRectt   topRightt   setYt   sizeHintForColumnt   verticalScrollBart   widtht   setGeometryt   xt   movePositiont   QTextCursort   Leftt   positiont   _start_positiont   setCurrentRowt   raise_t   show(   R&   t   cursort   itemst   prefix_lengthR(   t   pointt   itemt	   list_itemRY   t   screen_rectt   w(    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyt
   show_itemsg   s*    	
0"
c         C   sÈ   |  j  j | ƒ j ƒ  } |  j  j ƒ  j ƒ  } t j d k rS t | d d ƒ } n: t j	 d k ry t | d d ƒ } n t | d d ƒ } | | d } | j
 | j ƒ  | ƒ |  j  j | ƒ } | S(   s0    Get top left position for this widget.
        t   darwing333333ó?g\Âõ(\ï?t   ntgÍÌÌÌÌÌð?i   (   R   R^   t   centert   fontt	   pointSizet   syst   platformt   intt   ost   nameR`   R]   R-   (   R&   Rn   Rq   t
   point_sizet   deltaR]   (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyRP   ‰   s    c         C   s<   |  j  ƒ  j t j j ƒ } |  j ƒ  j | ƒ |  j ƒ  d S(   sB    Perform the completion with the currently selected item.
        N(   t   currentItemt   dataR    R   RT   t   _current_text_cursort
   insertTextR=   (   R&   t   text(    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyR%   ›   s    c         C   sD   |  j  j ƒ  } | j ƒ  |  j k r@ | j |  j t j j ƒ n  | S(   sn    Returns a cursor with text between the start position and the
            current position selected.
        (   R   t
   textCursorRi   Rj   t   setPositionR   Rg   t
   KeepAnchor(   R&   Rn   (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyR…   ¢   s
    c         C   s    |  j  j ƒ  } |  j | ƒ } |  j | ƒ |  j ƒ  j ƒ  j ƒ  } | r’ |  j | t j	 j
 t j	 j Bƒ } | r… |  j | d ƒ qœ |  j ƒ  n
 |  j ƒ  d S(   sh    Updates the current item based on the current text and the
            position of the widget.
        i    N(   R   Rˆ   RP   t   moveR…   t	   selectiont   toPlainTextt	   findItemsR    R   t   MatchStartsWitht   MatchCaseSensitivet   setCurrentItemR=   (   R&   Rn   Rq   t   prefixRo   (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyRI   ¬   s    c         C   s   |  j  ƒ  d  S(   N(   R=   (   R&   (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyR3   Á   s    (   t   __name__t
   __module__t   __doc__R
   R4   RD   RF   RL   Rv   RP   R%   R…   RI   R3   (    (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyR   	   s   	 			
	"			
	(   R•   R   R|   t   qtconsole.qtR    R   t   QListWidgetR   (    (    (    s:   lib/python2.7/site-packages/qtconsole/completion_widget.pyt   <module>   s   