B
    v9a                 @   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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 krd | _ n|| _ |j| _d | _| j| _d S )N)editwintextactive_calltip_make_tk_calltip_window_calltip_window)selfr    r   /usr/lib/python3.7/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 )NTbreak)open_calltip)r
   r   r   r   r   force_open_calltip_event)   s    
z Calltip.force_open_calltip_eventc             C   s   |  d d S )NF)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 )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   
	
r   c             C   s4   | r0t jtj}y
t| |S  tk
r.   d S X d S )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  d }}y
| j }W n tk
r&   |S X t|tjr8|n| }ytt|}W n8 tk
r } zt|}|	t
rvt
S W d d }~X Y nX d|krt|ttt k r|t7 }t|tr|dkrt}t|tkrtj|ttdn|r|gng }t|tjr|j}nt| dd}|rpxZ|dtd t D ]B}	|	 }	|	s>P t|	tkr`|	d td  d }	||	 q*W d|}|st}|S )	N /z())subsequent_indent__doc__
   z...)__call__r,   
isinstancetypes
MethodTypestrinspectZ	signature
ValueError
startswith_invalid_methodlen	_MAX_COLS_argument_positionaltype_default_callable_argspectextwrapwrap_INDENTr3   getattrsplit
_MAX_LINESstripappendjoin)
Zobr   defaultZob_callZfoberrmsglinesdocliner   r   r   r"   {   s@    	

*
r"   r)   )mainzidlelib.idle_test.test_calltip   )	verbosity)r)   r;   rer'   rD   r8   Zidlelibr   Zidlelib.hyperparserr   r   r#   r@   rI   rF   compileZ_first_paramrC   r>   rA   r"   r$   ZunittestrS   r   r   r   r   <module>   s(   S
4