ó
‹²,]c           @   s²   d  Z  d d l m Z d d l m Z m Z m Z 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 d e f d „  ƒ  YZ d	 S(
   s+  
Calltip widget used only to show signatures.

Adapted from IPython/frontend/qt/console/call_tip_widget.py of the
`IPython Project <https://github.com/ipython/ipython>`_.
Now located at qtconsole/call_tip_widget.py as part of the
`Jupyter QtConsole Project <https://github.com/jupyter/qtconsole>`_.
iÿÿÿÿ(   t   category(   t   QBasicTimert   QCoreApplicationt   QEventt   Qt(   t   QCursort   QPalette(   t   QFramet   QLabelt	   QTextEditt   QPlainTextEditt   QStylet   QStyleOptionFramet   QStylePaintert   QToolTip(   t   to_text_stringt   CallTipWidgetc           B   s›   e  Z d  Z e 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 RS(   sF    Shows call tips by parsing the current text of Q[Plain]TextEdit.
    c         C   s  t  | t t f ƒ s t ‚ t t |  ƒ j d t j	 ƒ t
 j ƒ  |  _ | |  _ d |  _ t ƒ  |  _ | |  _ |  j | j ƒ  j ƒ  ƒ |  j t j ƒ |  j t j ƒ |  j t j ƒ  ƒ |  j t j ƒ |  j d ƒ |  j  t! j" ƒ |  j# d |  j$ ƒ  j% t& j' d |  ƒ ƒ d S(   sf    Create a call tip manager that is attached to the specified Qt
            text edit widget.
        i   N((   t
   isinstanceR	   R
   t   AssertionErrort   superR   t   __init__t   NoneR   t   ToolTipR   t   instancet   appt   hide_timer_ont   tipR   t   _hide_timert
   _text_editt   setFontt   documentt   defaultFontt   setForegroundRoleR   t   ToolTipTextt   setBackgroundRolet   ToolTipBaset
   setPaletteR   t   palettet   setAlignmentt	   AlignLeftt	   setIndentt   setFrameStyleR   t   NoFramet	   setMargint   stylet   pixelMetricR   t   PM_ToolTipLabelFrameWidth(   t   selft	   text_editR   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyR   (   s     			c         C   sp  | |  j  k rW| j ƒ  } | t j k rÍ | j ƒ  } |  j  j ƒ  } |  j  j | j ƒ  d d ƒ} | t j	 t j
 t j t j f k r” |  j ƒ  qT| t j k r± |  j ƒ  t S| d k rT|  j ƒ  qTqW| t j k ré |  j ƒ  qW| t j k r8|  j j ƒ  rT|  j j t j ƒ  ƒ |  k rT|  j j ƒ  qTqW| t j k rW|  j ƒ  qWn  t t |  ƒ j | | ƒ S(   sb    Reimplemented to hide on certain key presses and on text edit focus
            changes.
        t   offsetiÿÿÿÿt   )(   R   t   typeR   t   KeyPresst   keyt
   textCursort   get_charactert   positionR   t	   Key_Entert
   Key_Returnt   Key_Downt   Key_Upt   hidet
   Key_Escapet   Truet   FocusOutt   EnterR   t   isActiveR   t
   topLevelAtR   t   post   stopt   Leavet   _leave_event_hideR   R   t   eventFilter(   R/   t   objt   eventt   etypeR5   t   cursort	   prev_char(    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRH   @   s0    	
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   RE   R=   (   R/   RJ   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyt
   timerEventb   s    c         C   sW   t  t |  ƒ j | ƒ |  j j ƒ  rS |  j j t j ƒ  ƒ |  k rS |  j j	 ƒ  n  d S(   s1    Reimplemented to cancel the hide timer.
        N(
   R   R   t
   enterEventR   RB   R   RC   R   RD   RE   (   R/   RJ   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRP   m   s    c         C   sX   t  t |  ƒ j | ƒ y |  j j j |  j ƒ Wn t k
 rC n X|  j j |  ƒ d S(   sG    Reimplemented to disconnect signal handlers and event filter.
        N(	   R   R   t	   hideEventR   t   cursorPositionChangedt
   disconnectt   _cursor_position_changedt	   TypeErrort   removeEventFilter(   R/   RJ   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRQ   u   s    c         C   s$   t  t |  ƒ j | ƒ |  j ƒ  d S(   s0    Reimplemented to start the hide timer.
        N(   R   R   t
   leaveEventRG   (   R/   RJ   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRW      s    c         C   s$   t  t |  ƒ j | ƒ |  j ƒ  d  S(   N(   R   R   t   mousePressEventR=   (   R/   RJ   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRX   ‡   s    c         C   sY   t  |  ƒ } t ƒ  } | j |  ƒ | j t j | ƒ | j ƒ  t t |  ƒ j	 | ƒ d S(   s6    Reimplemented to paint the background panel.
        N(
   R   R   t   initFromt   drawPrimitiveR   t   PE_PanelTipLabelt   endR   R   t
   paintEvent(   R/   RJ   t   paintert   option(    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyR]   ‹   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(    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyR   –   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   RR   t   connectRT   t   installEventFilter(   R/   RJ   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRa   ›   s    
c         C   s   |  j  ƒ  d S(   sV    Reimplemented to hide it when focus goes out of the main
            window.
        N(   R=   (   R/   RJ   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyt   focusOutEvent£   s    c         C   sÁ  |  j  ƒ  r, |  j | k r t S|  j ƒ  n  |  j } | j ƒ  } | j ƒ  d } |  j | d t ƒ\ |  _	 } |  j	 d k r‚ t S|  j
 rz|  j j ƒ  t | ƒ d k r	| d j d ƒ d } t | j d ƒ ƒ }	 |	 d k rë d }
 qd|	 d k r d	 }
 qdd
 }
 n[ t | ƒ d k r^| d j ƒ  } t | j d ƒ ƒ } | d k rUd }
 qdd }
 n d }
 |  j j |
 |  ƒ n  | |  _ |  j | ƒ |  j |  j ƒ  ƒ d } | 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 | ƒ  ƒ } | 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   (t   ,ix  i   i@  i  iÄ	  ið
  i¬  i   t   bottomt   Rightt   topt   Lefts   %s%s($   t	   isVisibleR   R?   R=   R   R6   R8   t   _find_parenthesist   Falset   _start_positionR   R   RE   t   lent   splitt   stript   startt   setTextt   resizet   sizeHintt
   cursorRectR   t   desktopt   screenGeometryt   setYt   yt   sizet   heightt   widtht   mapToGlobalt   topRightt   xt   getattrt   setXt   movet   show(   R/   t   pointR   t   wrapped_tiplinesR0   RL   t
   search_post   _t   argst   nargst	   hide_timet   args1t   nargs1t   paddingt   cursor_rectt   screen_rectt
   tip_heightt	   tip_widtht   verticalt
   horizontalt   point_RD   t   adjusted_point(    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyt   show_tip­   s~    								&			&			
c         C   s  d } } |  j  j ƒ  } t | j | ƒ ƒ } x× t | ƒ d k r| d k r| d k rt | d k rt | 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} t | j | ƒ ƒ } q1 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   CcRg   i   R2   Rf   iÿÿÿÿ(   R   R   R   t   characterAtR    (   R/   R8   Re   t   commast   depthR   t   char(    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRm     s$    
!c         C   sQ   |  j  rM |  j j ƒ  rM |  j j t j ƒ  ƒ |  k rM |  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   R   RB   R   RC   R   RD   Rs   (   R/   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRG   .  s    c         C   sª   |  j  j ƒ  } | j ƒ  } |  j  j ƒ  } t | j | d ƒ ƒ } | |  j k r_ |  j ƒ  nG | d k r¦ |  j | d d t	 ƒ\ } } | d k r¦ |  j ƒ  q¦ n  d S(   s8    Updates the tip based on user cursor movement.
        i   R2   Re   iÿÿÿÿN(
   R   R6   R8   R   R   Rš   Ro   R=   Rm   Rn   (   R/   RL   R8   R   R   RD   R‰   (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyRT   ;  s    (   t   __name__t
   __module__t   __doc__Rn   R   RH   RO   RP   RQ   RW   RX   R]   R   Ra   Rd   R˜   R?   Rm   RG   RT   (    (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyR       s    	"									
	d	N(   R    t   unicodedataR    t   qtpy.QtCoreR   R   R   R   t
   qtpy.QtGuiR   R   t   qtpy.QtWidgetsR   R   R	   R
   R   R   R   R   t   spyder.py3compatR   R   (    (    (    s5   lib/python2.7/site-packages/spyder/widgets/calltip.pyt   <module>   s   ":