B
    v9aV  ã               @   sz   d dl T G dd„ deƒZG dd„ deƒZG dd„ deƒZdd	„ Zed
krvd dlmZ edddd d dl	m
Z
 e
eƒ dS )é    )Ú*c               @   sD   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dS )ÚTooltipBasec             C   s   || _ d | _d S )N)Úanchor_widgetÚ	tipwindow)Úselfr   © r   ú/usr/lib/python3.7/tooltip.pyÚ__init__   s    zTooltipBase.__init__c             C   s   |   ¡  d S )N)Úhidetip)r   r   r   r   Ú__del__   s    zTooltipBase.__del__c             C   s|   | j r
d S t| jƒ | _ }| d¡ y|j dd|jdd¡ W n tk
rR   Y nX |  ¡  |  	¡  | j  
¡  | j  ¡  d S )Né   z!::tk::unsupported::MacWindowStyleZstyleÚhelpZnoActivates)r   ÚToplevelr   Zwm_overrideredirectZtkZcallZ_wÚTclErrorÚposition_windowÚshowcontentsZupdate_idletasksZlift)r   Útwr   r   r   Úshowtip   s    

zTooltipBase.showtipc             C   s@   |   ¡ \}}| j ¡ | }| j ¡ | }| j d||f ¡ d S )Nz+%d+%d)Úget_positionr   Zwinfo_rootxZwinfo_rootyr   Zwm_geometry)r   ÚxÚyZroot_xZroot_yr   r   r   r   /   s    zTooltipBase.position_windowc             C   s   d| j  ¡ d fS )Né   r   )r   Zwinfo_height)r   r   r   r   r   6   s    	zTooltipBase.get_positionc             C   s   t ‚d S )N)ÚNotImplementedError)r   r   r   r   r   A   s    zTooltipBase.showcontentsc             C   s6   | j }d | _ |r2y| ¡  W n tk
r0   Y nX d S )N)r   Zdestroyr   )r   r   r   r   r   r
   F   s    zTooltipBase.hidetipN)
Ú__name__Ú
__module__Ú__qualname__r	   r   r   r   r   r   r
   r   r   r   r   r   
   s   
r   c                   sZ   e Zd Zd‡ fdd„	Z‡ fdd„Zddd„Zdd	d
„Zdd„ Zdd„ Z‡ fdd„Z	‡  Z
S )ÚOnHoverTooltipBaseéè  c                sV   t t| ƒ |¡ || _d | _| j d| j¡| _| j d| j	¡| _
| j d| j	¡| _d S )Nz<Enter>z<Leave>z<Button>)Úsuperr   r	   Úhover_delayÚ	_after_idr   ZbindÚ_show_eventÚ_id1Ú_hide_eventÚ_id2Ú_id3)r   r   r   )Ú	__class__r   r   r	   U   s    
zOnHoverTooltipBase.__init__c                s\   y4| j  d| j¡ | j  d| j¡ | j  d| j¡ W n tk
rH   Y nX tt| ƒ ¡  d S )Nz<Enter>z<Leave>z<Button>)	r   Zunbindr"   r$   r%   r   r   r   r   )r   )r&   r   r   r   g   s    zOnHoverTooltipBase.__del__Nc             C   s   | j r|  ¡  n|  ¡  d S )N)r   Úscheduler   )r   Úeventr   r   r   r!   p   s    
zOnHoverTooltipBase._show_eventc             C   s   |   ¡  d S )N)r
   )r   r(   r   r   r   r#   w   s    zOnHoverTooltipBase._hide_eventc             C   s    |   ¡  | j | j| j¡| _d S )N)Ú
unscheduler   Zafterr   r   r    )r   r   r   r   r'   {   s    
zOnHoverTooltipBase.schedulec             C   s    | j }d | _ |r| j |¡ d S )N)r    r   Zafter_cancel)r   Zafter_idr   r   r   r)      s    zOnHoverTooltipBase.unschedulec                s4   y|   ¡  W n tk
r    Y nX tt| ƒ ¡  d S )N)r)   r   r   r   r
   )r   )r&   r   r   r
   ˆ   s
    zOnHoverTooltipBase.hidetip)r   )N)N)r   r   r   r	   r   r!   r#   r'   r)   r
   Ú__classcell__r   r   )r&   r   r   R   s   	

r   c                   s&   e Zd Zd‡ fdd„	Zdd„ Z‡  ZS )ÚHovertipéè  c                s   t t| ƒj||d || _d S )N)r   )r   r+   r	   Útext)r   r   r-   r   )r&   r   r   r	   “   s    
zHovertip.__init__c             C   s$   t | j| jtdtdd}| ¡  d S )Nz#ffffe0r   )r-   ZjustifyZ
backgroundZreliefZborderwidth)ÚLabelr   r-   ZLEFTZSOLIDÚpack)r   Úlabelr   r   r   r       s    zHovertip.showcontents)r,   )r   r   r   r	   r   r*   r   r   )r&   r   r+   ‘   s   r+   c             C   s¤   t | ƒ}| d¡ tt|  ¡  d¡dd … ƒ\}}| d||d f ¡ t|dd}| ¡  t|dd}| ¡  t	|d	d
d t|dd}| ¡  t	|dd d d S )NzTest tooltipú+r   z+%d+%dé–   zPlace your mouse over buttons)r-   z"Button 1 -- 1/2 second hover delayz!This is tooltip text for button1.iô  )r   zButton 2 -- no hover delayz!This is tooltip
text for button2.)
r   ÚtitleÚmapÚintZgeometryÚsplitr.   r/   ZButtonr+   )ÚparentÚtopr   r   r0   Zbutton1Zbutton2r   r   r   Ú_tooltip¦   s    
 r9   Ú__main__)Úmainzidlelib.idle_test.test_tooltipé   F)Ú	verbosityÚexit)ÚrunN)ZtkinterÚobjectr   r   r+   r9   r   Zunittestr;   Zidlelib.idle_test.htestr?   r   r   r   r   Ú<module>   s   H?