o
     JAfc                     @   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rUd dlmZ eddd dS 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   s2   |d u r	d | _ d S || _ |j| _d | _| j| _d S N)editwintextactive_calltip_make_tk_calltip_window_calltip_window)selfr    r   &/usr/lib/python3.10/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 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 d S 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r1tt|d d\}}||f| jj| jj	fkr1d S |
|d  z| }W n tyI   d }Y nw |sNd S |   |s]|ddkr]d S | |}|sfd 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   s8   


zCalltip.open_calltipc                 C   sN   	 z	| j jjjj}W n ty   d }Y nw |r!|dd|fi S tt|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_tipr   )__name__
__module____qualname__r   r   r	   r   r   r   r   r   r%   r   r   r   r   r      s    
	
3r   c                 C   s<   	 | ri t jtj}zt| |W S  ty   Y d S w 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   sH  	 z| j }W n
 ty   Y dS w t|tjr|n| }z	tt|}W n% tyI } zt|}|	t
r=t
W  Y d }~S d}W Y d }~nd }~ww t|trU|dkrUt}t|tkrctj|ttdn|rh|gng }t| }|r|dtd t D ]}| }|s nt|tkr|d td  d }|| q{d|}|pt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,      sB   	



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