B
    v9aö  ã               @   sŽ   d dl mZmZmZmZ d dlmZ dZdZdZ	dZ
dZdZG d	d
„ d
eƒZdd„ ZedkrŠd dlmZ edddd d dlmZ eeƒ dS )é    )ÚLabelÚLEFTÚSOLIDÚTclError)ÚTooltipBasez<<calltipwindow-hide>>)z<Key-Escape>z
<FocusOut>z<<calltipwindow-checkhide>>)z<KeyRelease>z<ButtonRelease>éd   Zcalltipwindowregion_rightc                   sr   e Zd Z‡ fdd„Zdd„ Z‡ fdd„Z‡ fdd„Zd	d
„ Zddd„Zdd„ Z	‡ fdd„Z
dd„ Zdd„ Z‡  ZS )ÚCalltipWindowc                sD   t t| ƒ |¡ d  | _| _d  | _ | _| _d  | _| _	d | _
d S )N)Úsuperr   Ú__init__ÚlabelÚtextÚ	parenlineÚparencolÚlastlineÚhideidÚcheckhideidÚcheckhide_after_id)ÚselfZtext_widget)Ú	__class__© ú/usr/lib/python3.7/calltip_w.pyr
      s
    zCalltipWindow.__init__c             C   sŠ   t | j d¡ d¡d ƒ}|| jkr2| j| jf}n|df}| j d| ¡}|snt| j d¡ƒ}d|d< d|d< |d d |d |d  fS )NÚinsertÚ.r   z%d.%dé   é   é   )ÚintÚanchor_widgetÚindexÚsplitr   r   ZbboxÚlist)r   ÚcurlineZanchor_indexZboxr   r   r   Úget_position#   s    
zCalltipWindow.get_positionc                sL   t | j d¡ d¡d ƒ}|| jkr(d S || _| j d¡ tt| ƒ ¡  d S )Nr   r   r   )	r   r   r   r   r   Zseer	   r   Úposition_window)r   r!   )r   r   r   r#   2   s    
zCalltipWindow.position_windowc                s^   || _ | js| j sd S | j t|¡ tt| j |¡ d¡ƒ\| _	| _
tt| ƒ ¡  |  ¡  d S )Nr   )r   Ú	tipwindowr   Zmark_setÚ
MARK_RIGHTÚmapr   r   r   r   r   r	   r   ÚshowtipÚ_bind_events)r   r   Z	parenleftZ
parenright)r   r   r   r'   ;   s    	zCalltipWindow.showtipc          
   C   s2   t | j| jtddtd| jd d| _| j ¡  d S )Nz#ffffd0Zblackr   Úfont)r   ZjustifyZ
backgroundZ
foregroundZreliefZborderwidthr)   )r   r$   r   r   r   r   r   Úpack)r   r   r   r   ÚshowcontentsP   s
    zCalltipWindow.showcontentsNc             C   s–   | j s
d S tt| j d¡ d¡ƒ\}}|| jk sT|| jkrD|| jksT| j ddt	¡r`|  
¡  dS |  ¡  | jd k	r€| j | j¡ | j t| j¡| _d S )Nr   r   ú>Úbreak)r$   r&   r   r   r   r   r   r   Zcomparer%   Úhidetipr#   r   Zafter_cancelÚafterÚCHECKHIDE_TIMEÚcheckhide_event)r   Úeventr!   Zcurcolr   r   r   r1   X   s    

zCalltipWindow.checkhide_eventc             C   s   | j s
d S |  ¡  dS )Nr-   )r$   r.   )r   r2   r   r   r   Ú
hide_events   s    zCalltipWindow.hide_eventc          	      s¤   | j s
d S y| j ¡  W n tk
r,   Y nX d | _d  | _ | _| _y| j t	¡ W n tk
rj   Y nX y|  
¡  W n ttfk
r   Y nX tt| ƒ ¡  d S )N)r$   r   Zdestroyr   r   r   r   r   Z
mark_unsetr%   Ú_unbind_eventsÚ
ValueErrorr	   r   r.   )r   )r   r   r   r.   {   s"    zCalltipWindow.hidetipc             C   sp   | j  t| j¡| _xtD ]}| j  t|¡ qW | j  t| j¡ | j  t	| j
¡| _xtD ]}| j  t	|¡ qVW d S )N)r   ÚbindÚCHECKHIDE_EVENTr1   r   ÚCHECKHIDE_SEQUENCESÚ	event_addr/   r0   Ú
HIDE_EVENTr3   r   ÚHIDE_SEQUENCES)r   Úseqr   r   r   r(   ”   s    



zCalltipWindow._bind_eventsc             C   sh   xt D ]}| j t|¡ qW | j t| j¡ d | _xtD ]}| j t|¡ q8W | j t| j¡ d | _d S )N)	r8   r   Zevent_deleter7   Zunbindr   r;   r:   r   )r   r<   r   r   r   r4       s    

zCalltipWindow._unbind_events)N)Ú__name__Ú
__module__Ú__qualname__r
   r"   r#   r'   r+   r1   r3   r.   r(   r4   Ú__classcell__r   r   )r   r   r      s   	
r   c                sì   ddl m}m}m}m} || ƒ}| d¡ tt|  ¡  	d¡dd … ƒ\}}| d|d |d f ¡ ||ƒ}|j
||dd	 | d
d¡ | ¡  t|ƒ‰ ‡ fdd„}	‡ fdd„}
| dd¡ | dd¡ | d|	¡ | d|
¡ | ¡  d S )Nr   )ÚToplevelÚTextr   ÚBOTHzTest call-tipsú+r   z250x100+%d+%dé¯   é–   )ZsideÚfillÚexpandr   zstring.splitc                s   ˆ   ddd¡ d S )Nz(s='Hello world')r   Úend)r'   )r2   )Úcalltipr   r   Úcalltip_show¹   s    z%_calltip_window.<locals>.calltip_showc                s   ˆ   ¡  d S )N)r.   )r2   )rJ   r   r   Úcalltip_hide»   s    z%_calltip_window.<locals>.calltip_hidez<<calltip-show>>ú(z<<calltip-hide>>ú))ÚtkinterrA   rB   r   rC   Útitler&   r   Zgeometryr   r*   r   Úupdater   r9   r6   Z	focus_set)ÚparentrA   rB   r   rC   ÚtopÚxÚyr   rK   rL   r   )rJ   r   Ú_calltip_window¬   s"    
 rV   Ú__main__)Úmainz idlelib.idle_test.test_calltip_wr   F)Ú	verbosityÚexit)ÚrunN)rO   r   r   r   r   Zidlelib.tooltipr   r:   r;   r7   r8   r0   r%   r   rV   r=   ZunittestrX   Zidlelib.idle_test.htestr[   r   r   r   r   Ú<module>   s    