B
    ^ Çc¥  ã               @   s~   d Z 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rzddlm	Z	 e	dddd ddl
mZ eeƒ dS )zŽTools for displaying tool-tips.

This includes:
 * an abstract base-class for different kinds of tooltips
 * a simple text-only Tooltip class
é    )Ú*c               @   sH   e Zd 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 )ÚTooltipBasez abstract base class for tooltipsc             C   s   || _ d| _dS )z®Create a tooltip.

        anchor_widget: the widget next to which the tooltip will be shown

        Note that a widget will only be shown when showtip() is called.
        N)Úanchor_widgetÚ	tipwindow)Úselfr   © r   ú lib/python3.7/idlelib/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 )zdisplay the tooltipNé   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 )z&(re)-set the tooltip's screen positionz+%d+%dN)Ú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 )z(choose a screen position for the tooltipé   r   )r   Zwinfo_height)r   r   r   r   r   6   s    	zTooltipBase.get_positionc             C   s   t ‚dS )z$content display hook for sub-classesN)Ú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 )zhide the tooltipN)r   Zdestroyr   )r   r   r   r   r   r
   F   s    zTooltipBase.hidetipN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r   r
   r   r   r   r   r   
   s   
r   c                   s^   e Zd 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 )ÚOnHoverTooltipBasez?abstract base class for tooltips, with delayed on-hover displayéè  c                sV   t t| ƒ |¡ || _d| _| j d| j¡| _| j d| j	¡| _
| j d| j	¡| _dS )aq  Create a tooltip with a mouse hover delay.

        anchor_widget: the widget next to which the tooltip will be shown
        hover_delay: time to delay before showing the tooltip, in milliseconds

        Note that a widget will only be shown when showtip() is called,
        e.g. after hovering over the anchor widget with the mouse for enough
        time.
        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 )z$event handler to display the tooltipN)r    Úscheduler   )r   Úeventr   r   r   r"   p   s    
zOnHoverTooltipBase._show_eventc             C   s   |   ¡  dS )z!event handler to hide the tooltipN)r
   )r   r)   r   r   r   r$   w   s    zOnHoverTooltipBase._hide_eventc             C   s    |   ¡  | j | j| j¡| _dS )z*schedule the future display of the tooltipN)Ú
unscheduler   Zafterr    r   r!   )r   r   r   r   r(   {   s    
zOnHoverTooltipBase.schedulec             C   s    | j }d| _ |r| j |¡ dS )z(cancel the future display of the tooltipN)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 )zhide the tooltipN)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*   r
   Ú__classcell__r   r   )r'   r   r   R   s   	

r   c                   s*   e Zd ZdZd‡ fdd„	Zdd„ Z‡  ZS )ÚHovertipzAA tooltip that pops up when a mouse hovers over an anchor widget.éè  c                s   t t| ƒj||d || _dS )av  Create a text tooltip with a mouse hover delay.

        anchor_widget: the widget next to which the tooltip will be shown
        hover_delay: time to delay before showing the tooltip, in milliseconds

        Note that a widget will only be shown when showtip() is called,
        e.g. after hovering over the anchor widget with the mouse for enough
        time.
        )r    N)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   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/   r0   ZButtonr,   )ÚparentÚtopr   r   r1   Zbutton1Zbutton2r   r   r   Ú_tooltip¦   s    
 r:   Ú__main__)Úmainzidlelib.idle_test.test_tooltipé   F)Ú	verbosityÚexit)ÚrunN)r   ZtkinterÚobjectr   r   r,   r:   r   Zunittestr<   Zidlelib.idle_test.htestr@   r   r   r   r   Ú<module>   s   H?