ó
|Nc           @   sM  d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d d l Z d d d „  ƒ  YZ	 d „  Z
 d „  Z e d	 k rId
 „  Z d d „ Z d „  Z d „  Z d „  Z d d „ Z d „  Z d e f d „  ƒ  YZ d „  Z e ƒ  Z e e e e e e e e e j e j e j e j e j e j e j f Z e e ƒ n  d S(   s  CallTips.py - An IDLE Extension to Jog Your Memory

Call Tips are floating windows which display function, class, and method
parameter and docstring information when you type an opening parenthesis, and
which disappear when you type a closing parenthesis.

iÿÿÿÿN(   t   CallTipWindow(   t   HyperParsert   CallTipsc           B   sz   e  Z d  d g f g Z d d „ Z d „  Z d „  Z d d „ Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z RS(   t   edits   Show call tips   <<force-open-calltip>>c         C   sG   | d  k r d  |  _ d  S| |  _ | j |  _ d  |  _ |  j |  _ d  S(   N(   t   Nonet   editwint   textt   calltipt   _make_tk_calltip_windowt   _make_calltip_window(   t   selfR   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   __init__   s    			c         C   s   d  |  _ d  S(   N(   R   R	   (   R
   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   close"   s    c         C   s   t  j |  j ƒ S(   N(   R    t   CallTipR   (   R
   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyR   %   s    c         C   s&   |  j  r" |  j  j ƒ  d  |  _  n  d  S(   N(   R   t   hidetipR   (   R
   t   event(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   _remove_calltip_window)   s    	c         C   s   |  j  t ƒ d S(   si   Happens when the user really wants to open a CallTip, even if a
        function call is needed.
        N(   t   open_calltipt   True(   R
   R   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   force_open_calltip_event.   s    c         C   s   |  j  t ƒ d S(   sª   Happens when it would be nice to open a CallTip, but not really
        necessary, for example after an opening bracket, so function calls
        won't be made.
        N(   R   t   False(   R
   R   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   try_open_calltip_event4   s    c         C   s,   |  j  r( |  j  j ƒ  r( |  j t ƒ n  d S(   si   If there is already a calltip window, check if it is still needed,
        and if so, reload it.
        N(   R   t	   is_activeR   R   (   R
   R   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   refresh_calltip_event;   s    c         C   sÃ   |  j  ƒ  t |  j d ƒ } | j d ƒ } | s5 d  S| j | d ƒ | j ƒ  } | su | ry | j d ƒ d k ry d  S|  j | ƒ } | s’ d  S|  j ƒ  |  _	 |  j	 j
 | | d | d ƒ d  S(   Nt   insertt   (i    iÿÿÿÿi   (   R   R   R   t   get_surrounding_bracketst	   set_indext   get_expressiont   findt	   fetch_tipR	   R   t   showtip(   R
   t	   evalfuncst   hpt	   sur_parent   namet   arg_text(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyR   B   s    
#c         C   se   y |  j  j j j j } Wn d } n X| rH | j d d | f i  ƒ S|  j | ƒ } t | ƒ Sd S(   sR  Return the argument list and docstring of a function or class

        If there is a Python subprocess, get the calltip there.  Otherwise,
        either fetch_tip() is running in the subprocess itself or it was called
        in an IDLE EditorWindow before any script had been run.

        The subprocess environment is that of the most recently run script.  If
        two unrelated modules are being edited some calltips in the current
        module may be inoperative if the module was not the last to run.

        To find methods, fetch_tip must be fed a fully qualified name.

        t   exect   get_the_calltipN(	   R   t   flistt   pyshellt   interpt   rpccltR   t
   remotecallt
   get_entityt   get_arg_text(   R
   R#   R*   t   entity(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyR   S   s    
c         C   sX   | rT t  j j ƒ  } | j t j ƒ y t | | ƒ SWqT t t f k
 rP d SXn  d S(   sA   Lookup name in a namespace spanning sys.modules and __main.dict__N(
   t   syst   modulest   copyt   updatet   __main__t   __dict__t   evalt	   NameErrort   AttributeErrorR   (   R
   R#   t	   namespace(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyR,   l   s    (   s   Show call tips   <<force-open-calltip>>N(   t   __name__t
   __module__t   menudefsR   R   R   R   R   R   R   R   R   R   R,   (    (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyR      s   								c         C   sV   y |  j  j SWnA t k
 rQ x1 |  j D]" } t | ƒ } | d  k	 r( | Sq( Wn Xd  S(   N(   R   t   im_funcR7   t	   __bases__t   _find_constructorR   (   t   class_obt   baset   rc(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyR>   v   s     c   
      C   s  d } |  d k	 rd } t |  ƒ t j t j f k rc t |  ƒ } | d k rZ d „  } q d } n- t |  ƒ t j k rŠ |  j } d } n |  } t | ƒ t j t j	 g k r•| j
 j } | j
 j | | !} | j pÙ g  } t t d „  | ƒ ƒ } d g t | ƒ t | ƒ | } t d „  | | ƒ } | j
 j d @rJ| j d ƒ n  | j
 j d	 @rj| j d
 ƒ n  d j | ƒ } d t j d d | ƒ } n  t |  d d ƒ } | r| j ƒ  } | j d ƒ }	 |	 d k  sà|	 d k réd }	 n  | rü| d 7} n  | | |	  7} qn  | S(   s:   Get a string describing the arguments for the given objectt    i    c           S   s   d  S(   N(   R   (    (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   <lambda>Š   s    i   c         S   s   d t  |  ƒ S(   Ns   =%s(   t   repr(   R#   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRC   ™   s    c         S   s   |  | S(   N(    (   t   argt   dflt(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRC   ›   s    i   s   ...i   s   ***s   , s   (%s)s   \.\d+s   <tuple>t   __doc__s   
iF   N(   R   t   typet   typest	   ClassTypet   TypeTypeR>   t
   MethodTypeR<   t   FunctionTypet
   LambdaTypet	   func_codet   co_argcountt   co_varnamest   func_defaultst   listt   mapt   lent   co_flagst   appendt   joint   ret   subt   getattrt   lstripR   (
   t   obR$   t
   arg_offsett   fobt   argcountt	   real_argst   defaultst   itemst   doct   pos(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyR-      sF    			!	R3   c           C   s   d S(   s   ()N(    (    (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   t1´   s    c         C   s   d S(   s   (a, b=None)N(    (   t   at   b(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   t2µ   s    c         G   s   d S(   s   (a, ...)N(    (   Rg   t   args(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   t3¶   s    c          G   s   d S(   s   (...)N(    (   Rj   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   t4·   s    c         G   s   d S(   s   (a, ...)N(    (   Rg   Rj   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   t5¸   s    c         O   s   d S(   s   (a, b=None, ..., ***)N(    (   Rg   Rh   Rj   t   kw(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   t6¹   s    c         C   s   |  \ } } | \ } } d S(   s   (<tuple>, c, <tuple>)N(    (   t   .0t   ct   .2Rg   Rh   t   dt   e(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   t7º   s    t   TCc           B   s_   e  Z d  Z d	 d „ Z d „  Z d	 d „ Z d „  Z d „  Z d „  Z	 d	 d „ Z
 d „  Z RS(
   s   (ai=None, ...)c         G   s   d S(   s   (ai=None, ...)N(    (   R
   t   aiRh   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyR   ¾   s    c         C   s   d S(   s   ()N(    (   R
   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRf   ¿   s    c         C   s   d S(   s   (ai, b=None)N(    (   R
   Rw   Rh   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRi   À   s    c         G   s   d S(   s	   (ai, ...)N(    (   R
   Rw   Rj   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRk   Á   s    c         G   s   d S(   s   (...)N(    (   R
   Rj   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRl   Â   s    c         G   s   d S(   s	   (ai, ...)N(    (   R
   Rw   Rj   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRm   Ã   s    c         O   s   d S(   s   (ai, b=None, ..., ***)N(    (   R
   Rw   Rh   Rj   Rn   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRo   Ä   s    c         C   s   | \ } } | \ } } d S(   s   (<tuple>, c, <tuple>)N(    (   R
   t   .1Rq   t   .3Rw   Rh   Rs   Rt   (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRu   Å   s    N(   R9   R:   RG   R   R   Rf   Ri   Rk   Rl   Rm   Ro   Ru   (    (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyRv   ¼   s   				c   	      C   sÜ   t  ƒ  } g  } x« |  D]£ } | j d | j } | j } y d | j j | f } Wn t k
 rl | } n X| j | ƒ } | | k r | j | ƒ d } | | j | t | ƒ f GHq q Wd t | ƒ t |  ƒ f GHd  S(   Ns   
s   %s.%ss   %s - expected %s, but got %ss   %d of %d tests failed(	   R   RG   R9   t   im_classR7   R   RW   R-   RU   (	   t   testst   ctt   failedt   tt   expectedR#   t   qualified_nameR$   t   fmt(    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   testÇ   s    		
"(    (   RG   RY   R/   RI   t   idlelibR    t   idlelib.HyperParserR   R3   R   R>   R-   R9   Rf   R   Ri   Rk   Rl   Rm   Ro   Ru   t   objectRv   R‚   t   tcR{   (    (    (    s%   C:\RCS\Python\lib\idlelib\CallTips.pyt   <module>   s.   e		1							3