a
    åzec  ã                   @   s¨   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d„ Zedkr¤d dlmZ eddd dS )é    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 u rd | _ n|| _ |j| _d | _| j| _d S ©N)ÚeditwinÚtextÚactive_calltipÚ_make_tk_calltip_windowÚ_calltip_window)Úselfr   © r   ú%/usr/lib/python3.9/idlelib/calltip.pyÚ__init__   s    zCalltip.__init__c                 C   s
   d | _ d S r   )r
   ©r   r   r   r   Úclose   s    zCalltip.closec                 C   s   t  | j¡S r   )r   ZCalltipWindowr   r   r   r   r   r	       s    zCalltip._make_tk_calltip_windowc                 C   s   | j r| j  ¡  d | _ d S r   )r   Zhidetip©r   Úeventr   r   r   Úremove_calltip_window$   s    
zCalltip.remove_calltip_windowc                 C   s   |   d¡ dS )NTÚbreak©Úopen_calltipr   r   r   r   Úforce_open_calltip_event)   s    
z Calltip.force_open_calltip_eventc                 C   s   |   d¡ d S ©NFr   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 r   )r   Z	tipwindowr   r   r   r   r   Úrefresh_calltip_event5   s    zCalltip.refresh_calltip_eventc                 C   sð   t | jdƒ}| d¡}|s&|  ¡  d S | jr`tt|d  d¡ƒ\}}||f| jj| jj	fkr`d S | 
|d ¡ z| ¡ }W n ty   d }Y n0 |sšd S |  ¡  |s¸| d¡dkr¸d S |  |¡}|sÊd S |  ¡ | _| j ||d |d ¡ d S )NÚinsertú(r   Ú.éÿÿÿÿé   )r   r   Zget_surrounding_bracketsr   r   ÚmapÚintÚsplitZ	parenlineZparencolZ	set_indexZget_expressionÚ
ValueErrorÚfindÚ	fetch_tipr
   Zshowtip)r   Z	evalfuncsZhpZ	sur_parenZopener_lineZ
opener_colÚ
expressionÚargspecr   r   r   r   9   s6    
ÿÿ


zCalltip.open_calltipc                 C   sP   z| j jjjj}W n ty(   d }Y n0 |r@| dd|fi ¡S tt|ƒƒS d S )NÚexecZget_the_calltip)	r   Ú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   
	
3r   c                 C   s:   | r6i t j¥tj¥}zt| |ƒW S  ty4   Y d S 0 d S r   )ÚsysÚmodulesÚ__main__Ú__dict__ÚevalÚBaseException)r&   Ú	namespacer   r   r   r-   …   s    r-   éU   é   z    z(?<=\()\w*\,?\s*zSee source or doczinvalid method signaturec           	   
   C   sP  z
| j }W n ty   Y dS 0 t|tjƒr0|n| }ztt |¡ƒ}W nJ ty } z2t|ƒ}| 	t
¡rxt
W  Y d }~S d}W Y d }~n
d }~0 0 t|tƒr¨|dkr¨t}t|ƒtkrÄtj|ttdn|rÎ|gng }t | ¡}|r<| dt¡d t… D ]D}| ¡ }|s q<t|ƒtkr0|d td … d }| |¡ qöd |¡}|pNtS )NÚ z())Úsubsequent_indentÚ
é   z...)Ú__call__r6   Ú
isinstanceÚtypesÚ
MethodTypeÚstrÚinspectZ	signatureÚ	ExceptionÚ
startswithÚ_invalid_methodÚtypeÚ_default_callable_argspecÚlenÚ	_MAX_COLSÚtextwrapÚwrapÚ_INDENTZgetdocr"   Ú
_MAX_LINESÚstripÚappendÚjoin)	ÚobZob_callZfobr'   ÚerrÚmsgÚlinesÚdocÚliner   r   r   r,   š   s:    



ÿÿ

r,   r3   )Úmainzidlelib.idle_test.test_calltipé   )Ú	verbosity)r3   rC   Úrer1   rK   r@   Zidlelibr   Zidlelib.hyperparserr   r   r-   rJ   rN   rM   ÚcompileZ_first_paramrH   rF   r,   r.   ZunittestrX   r   r   r   r   Ú<module>   s&   s
1