B
    ^ Çc®  ã               @   s°   d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 G dd„ dƒZdd„ Zd	Zd
ZdZe d¡ZdZdZdZdd„ Zedkr¬ddlmZ eddd dS )zúPop up a reminder of how to call a function.

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.
é    N)Ú	calltip_w)ÚHyperParserc               @   sX   e Zd Zddd„Zdd„ Zdd„ Zddd	„Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚCalltipNc             C   s0   |d krd | _ n|| _ |j| _d | _| j| _d S )N)ÚeditwinÚtextÚactive_calltipÚ_make_tk_calltip_windowÚ_calltip_window)Úselfr   © r   ú lib/python3.7/idlelib/calltip.pyÚ__init__   s    zCalltip.__init__c             C   s
   d | _ d S )N)r	   )r
   r   r   r   Úclose   s    zCalltip.closec             C   s   t  | j¡S )N)r   ZCalltipWindowr   )r
   r   r   r   r       s    zCalltip._make_tk_calltip_windowc             C   s   | j r| j  ¡  d | _ d S )N)r   Zhidetip)r
   Úeventr   r   r   Úremove_calltip_window$   s    
zCalltip.remove_calltip_windowc             C   s   |   d¡ dS )z9The user selected the menu entry or hotkey, open the tip.TÚbreak)Úopen_calltip)r
   r   r   r   r   Úforce_open_calltip_event)   s    
z Calltip.force_open_calltip_eventc             C   s   |   d¡ dS )zª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.
        FN)r   )r
   r   r   r   r   Útry_open_calltip_event.   s    zCalltip.try_open_calltip_eventc             C   s   | j r| j jr|  d¡ d S )NF)r   Z	tipwindowr   )r
   r   r   r   r   Úrefresh_calltip_event5   s    zCalltip.refresh_calltip_eventc             C   s’   |   ¡  t| jdƒ}| d¡}|s&d S | |d ¡ | ¡ }|sDd S |sZ| d¡dkrZd S |  |¡}|sld S |  ¡ | _	| j	 
||d |d ¡ d S )NÚinsertú(r   éÿÿÿÿé   )r   r   r   Zget_surrounding_bracketsZ	set_indexZget_expressionÚfindÚ	fetch_tipr	   r   Zshowtip)r
   Z	evalfuncsZhpZ	sur_parenÚ
expressionÚargspecr   r   r   r   9   s     


zCalltip.open_calltipc             C   sR   y| j jjjj}W n tk
r*   d}Y nX |rB| dd|fi ¡S tt|ƒƒS dS )aD  Return the argument list and docstring of a function or class.

        If there is a Python subprocess, get the calltip there.  Otherwise,
        either this fetch_tip() is running in the subprocess or it was
        called in an IDLE running without the subprocess.

        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.

        NÚexecZget_the_calltip)	r   ZflistZpyshellZinterpÚrpccltÚAttributeErrorZ
remotecallÚget_argspecÚ
get_entity)r
   r   r   r   r   r   r   L   s    

zCalltip.fetch_tip)N)N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r   r   r   r   r   r   r      s   
	
r   c             C   s4   | r0t jtj–}y
t| |ƒS  tk
r.   dS X dS )zwReturn the object corresponding to expression evaluated
    in a namespace spanning sys.modules and __main.dict__.
    N)ÚsysÚmodulesÚ__main__Ú__dict__ÚevalÚBaseException)r   Ú	namespacer   r   r   r"   e   s    
r"   éU   é   z    z(?<=\()\w*\,?\s*zSee source or doczinvalid method signaturez0  # '/' marks preceding args as positional-only.c       	   
   C   s€  y
| j }W n tk
r   dS X t|tjƒr0|n| }ytt |¡ƒ}W n< tk
r‚ } zt|ƒ}| 	t
¡rnt
S d}W dd}~X Y nX d|kr¨t|ƒtttƒ k r¨|t7 }t|tƒr¾|dkr¾t}t|ƒtkrÚtj|ttdn|rä|gng }t|tjƒ rþ|j}nt| ddƒ}|rlxZ| dt¡dt… D ]B}| ¡ }|s:P t|ƒtkr\|dtd … d	 }| |¡ q&W d |¡}|p~tS )
a¡  Return a string describing the signature of a callable object, or ''.

    For Python-coded functions and methods, the first line is introspected.
    Delete 'self' parameter for classes (.__init__) and bound methods.
    The next lines are the first lines of the doc string up to the first
    empty line or _MAX_LINES.    For builtins, this typically includes
    the arguments in addition to the return value.
    Ú Nú/z())Zsubsequent_indentÚ__doc__Ú
é   z...)Ú__call__r+   Ú
isinstanceÚtypesÚ
MethodTypeÚstrÚinspectZ	signatureÚ	ExceptionÚ
startswithÚ_invalid_methodÚlenÚ	_MAX_COLSÚ_argument_positionalÚtypeÚ_default_callable_argspecÚtextwrapZwrapÚ_INDENTr1   ÚgetattrÚsplitÚ
_MAX_LINESÚstripÚappendÚjoin)	ÚobZob_callZfobr   ÚerrÚmsgÚlinesÚdocÚliner   r   r   r!   {   s<    


*
r!   r(   )Úmainzidlelib.idle_test.test_calltipé   )Ú	verbosity)r1   r(   r9   Úrer&   rB   r6   Zidlelibr   Zidlelib.hyperparserr   r   r"   r>   rF   rC   ÚcompileZ_first_paramrA   r<   r?   r!   r#   ZunittestrP   r   r   r   r   Ú<module>   s*   S
6