ó
_y]c           @   sO   d  d l  Z  d  d l m Z d  d l m Z m Z d e j f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   category(   t   QtCoret   QtGuit   CallTipWidgetc           B   s›   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 d „ Z d „  Z e d „ Z d „  Z d „  Z d „  Z RS(   sF    Shows call tips by parsing the current text of Q[Plain]TextEdit.
    c         C   sL  t  | t j t j f ƒ s! t ‚ t t |  ƒ j d t	 j
 j ƒ t	 j ƒ  |  _ | |  _ |  j | j ƒ  j ƒ  ƒ |  j t j j ƒ |  j t j j ƒ |  j t j j ƒ  ƒ |  j t	 j
 j ƒ |  j d ƒ |  j t j j ƒ |  j  d |  j! ƒ  j" t j# j$ d |  ƒ ƒ |  j% |  j! ƒ  j& t j# j' d |  d ƒ d ƒ |  j( t) ƒ d S(   sf    Create a call tip manager that is attached to the specified Qt
            text edit widget.
        i   g     ào@N(*   t
   isinstanceR   t	   QTextEditt   QPlainTextEditt   AssertionErrort   superR   t   __init__t   NoneR   t   Qtt   ToolTipt   QBasicTimert   _hide_timert
   _text_editt   setFontt   documentt   defaultFontt   setForegroundRolet   QPalettet   ToolTipTextt   setBackgroundRolet   ToolTipBaset
   setPalettet   QToolTipt   palettet   setAlignmentt	   AlignLeftt	   setIndentt   setFrameStylet   QFramet   NoFramet	   setMargint   stylet   pixelMetrict   QStylet   PM_ToolTipLabelFrameWidtht   setWindowOpacityt	   styleHintt   SH_ToolTipLabel_Opacityt   setWordWrapt   True(   t   selft	   text_edit(    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyR	      s     !	c         C   s  | |  j  k rê | j ƒ  } | t j j k r‡ | j ƒ  } | t j j t j j f k rd |  j	 ƒ  qç | t j j
 k rç |  j	 ƒ  t Sqê | t j j k r¦ |  j	 ƒ  qê | t j j k rÈ |  j j ƒ  qê | t j j k rê |  j ƒ  qê n  t t |  ƒ j | | ƒ S(   sb    Reimplemented to hide on certain key presses and on text edit focus
            changes.
        (   R   t   typeR   t   QEventt   KeyPresst   keyR   t	   Key_Entert
   Key_Returnt   hidet
   Key_EscapeR*   t   FocusOutt   EnterR   t   stopt   Leavet   _leave_event_hideR   R   t   eventFilter(   R+   t   objt   eventt   etypeR0   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyR:   )   s     
c         C   s9   | j  ƒ  |  j j  ƒ  k r5 |  j j ƒ  |  j ƒ  n  d S(   sE    Reimplemented to hide the widget when the hide timer fires.
        N(   t   timerIdR   R7   R3   (   R+   R<   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyt
   timerEventC   s    c         C   s'   t  t |  ƒ j | ƒ |  j j ƒ  d S(   s1    Reimplemented to cancel the hide timer.
        N(   R   R   t
   enterEventR   R7   (   R+   R<   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyR@   N   s    c         C   s@   t  t |  ƒ j | ƒ |  j j j |  j ƒ |  j j |  ƒ d S(   sG    Reimplemented to disconnect signal handlers and event filter.
        N(   R   R   t	   hideEventR   t   cursorPositionChangedt
   disconnectt   _cursor_position_changedt   removeEventFilter(   R+   R<   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyRA   T   s    
c         C   s$   t  t |  ƒ j | ƒ |  j ƒ  d S(   s0    Reimplemented to start the hide timer.
        N(   R   R   t
   leaveEventR9   (   R+   R<   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyRF   \   s    c         C   sb   t  j |  ƒ } t  j ƒ  } | j |  ƒ | j t  j j | ƒ | j ƒ  t t	 |  ƒ j
 | ƒ d S(   s6    Reimplemented to paint the background panel.
        N(   R   t   QStylePaintert   QStyleOptionFramet   initFromt   drawPrimitiveR$   t   PE_PanelTipLabelt   endR   R   t
   paintEvent(   R+   R<   t   paintert   option(    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyRM   b   s    
c         C   s   t  t |  ƒ j | ƒ d S(   s>    Reimplemented to allow use of this method as a slot.
        N(   R   R   R   (   R+   t   font(    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyR   m   s    c         C   s@   t  t |  ƒ j | ƒ |  j j j |  j ƒ |  j j |  ƒ d S(   sD    Reimplemented to connect signal handlers and event filter.
        N(   R   R   t	   showEventR   RB   t   connectRD   t   installEventFilter(   R+   R<   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyRQ   r   s    
i   c         C   sm   | j  d i  ƒ } | j  d d ƒ } t j d | | ƒ } | rW | | j ƒ   d } n  |  j |  j | ƒ ƒ S(   s!   Show inspection data as a tooltipt   datas
   text/plaint    s   (?:[^
]*
){%i}s   
[Documentation continues...](   t   gett   ret   matchRL   t   show_tipt   _format_tooltip(   R+   t   contentt   maxlinesRT   t   textRX   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyt   show_inspect_data~   s    c         C   sÈ  |  j  } | j ƒ  } | j ƒ  } | j ƒ  d } |  j | d t ƒ\ |  _ } |  j d k rb t S|  j | ƒ |  j |  j	 ƒ  ƒ d } | j
 | ƒ } t j j ƒ  j | ƒ }	 | j | j ƒ  ƒ }
 |
 j |
 j ƒ  | ƒ |  j ƒ  j ƒ  } |  j ƒ  j ƒ  } d } d } |
 j ƒ  | |	 j ƒ  |	 j ƒ  k r“| j | j ƒ  ƒ } | j ƒ  | | k  rŠd |
 j ƒ  |	 j ƒ  k  rd } qd } q“d } n  |
 j ƒ  | |	 j ƒ  |	 j ƒ  k r| j | j ƒ  ƒ } | j ƒ  | | k  rd |
 j ƒ  |	 j ƒ  k  r	d } qd	 } qd	 } n  t | d
 | | f ƒ } | j | ƒ  ƒ }
 |
 j |
 j ƒ  | ƒ | d k rƒ|
 j |
 j ƒ  | ƒ n  | d	 k r­|
 j |
 j ƒ  | | ƒ n  |  j |
 ƒ |  j ƒ  t S(   sL    Attempts to show the specified tip at the current cursor location.
        i   t   forwardiÿÿÿÿi   t   bottomt   Righti   t   topt   Lefts   %s%s(   R   R   t
   textCursort   positiont   _find_parenthesist   Falset   _start_positiont   setTextt   resizet   sizeHintt
   cursorRectR   t   qAppt   desktopt   screenGeometryt   mapToGlobalt   bottomRightt   setYt   yt   sizet   heightt   widtht   topRightt   xt   getattrt   setXt   movet   showR*   (   R+   t   tipR,   R   t   cursort
   search_post   _t   paddingt   cursor_rectt   screen_rectt   pointt
   tip_heightt	   tip_widtht   verticalt
   horizontalt   point_t   pos(    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyRY   ˆ   sV    	&			&			
c         C   s  d } } |  j  j ƒ  } | j | ƒ } xÑ t | ƒ d k rõ | d k rõ | d k rn | d k rn | d 7} n_ | d k r | r | d k r Pn  | d 7} n0 | d k rÍ | rÀ | d k rÀ Pn  | d 8} n  | | rÜ d n d 7} | j | ƒ } q+ Wd } | | f S(   sz   If 'forward' is True (resp. False), proceed forwards
            (resp. backwards) through the line that contains 'position' until an
            unmatched closing (resp. opening) parenthesis is found. Returns a
            tuple containing the position of this parenthesis (or -1 if it is
            not found) and the number commas (at depth 0) found along the way.
        i    t   Cct   ,i   t   )t   (iÿÿÿÿ(   R   R   t   characterAtR    (   R+   Re   R_   t   commast   depthR   t   char(    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyRf   Î   s$    
!c         C   sK   |  j  j ƒ  rG t j j t j j ƒ  ƒ |  k rG |  j  j d |  ƒ n  d S(   sq    Hides the tooltip after some time has passed (assuming the cursor is
            not over the tooltip).
        i,  N(   R   t   isActiveR   Rm   t
   topLevelAtt   QCursorRŠ   t   start(   R+   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyR9   ë   s    !c         C   s   t  j d d | ƒ } | S(   Ns   \033\[(\d|;)+?mRU   (   RW   t   sub(   R+   t   doc(    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyRZ   ö   s    c         C   sj   |  j  j ƒ  } | j ƒ  |  j k r1 |  j ƒ  n5 |  j |  j d ƒ \ } } | d k rf |  j ƒ  n  d S(   s8    Updates the tip based on user cursor movement.
        i   iÿÿÿÿN(   R   Rd   Re   Rh   R3   Rf   (   R+   R~   Re   R   (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyRD   ü   s    (   t   __name__t
   __module__t   __doc__R	   R:   R?   R@   RA   RF   RM   R   RQ   R^   RY   R*   Rf   R9   RZ   RD   (    (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyR   	   s    									
	F		(   RW   t   unicodedataR    t   qtconsole.qtR   R   t   QLabelR   (    (    (    s8   lib/python2.7/site-packages/qtconsole/call_tip_widget.pyt   <module>   s   