a
    "hc                     @   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rd 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   7/opt/python-3.9.21/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 |sd S |   |s|ddkrd S | |}|sd 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rt}t|tkrt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 }|| qd|}|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