a
    ¨ô|c  ã                   @   s|   d Z ddlT G dd„ dƒZG dd„ deƒZG dd„ deƒZd	d
„ Zedkrxd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.9/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   sz   | j r
dS t| jƒ | _ }| d¡ z|j dd|jdd¡ W n tyP   Y n0 |  ¡  |  	¡  | 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   Ztwr   r   r   Úshowtip   s    
ÿ
zTooltipBase.showtipc                 C   s@   |   ¡ \}}| j ¡ | }| j ¡ | }| j d||f ¡ dS )z&(re)-set the tooltip's screen positionú+%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_heightr   r   r   r   r   6   s    	zTooltipBase.get_positionc                 C   s   t ‚dS )z$content display hook for sub-classesN)ÚNotImplementedErrorr   r   r   r   r   A   s    zTooltipBase.showcontentsc                 C   s4   | j }d| _ |r0z| ¡  W n ty.   Y n0 dS ©zhide the tooltipN)r   Zdestroyr   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.
        Nú<Enter>ú<Leave>ú<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                    sZ   z4| j  d| j¡ | j  d| j¡ | j  d| j¡ W n tyF   Y n0 tt| ƒ ¡  d S )Nr#   r$   r%   )	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   Zeventr   r   r   r)   p   s    
zOnHoverTooltipBase._show_eventc                 C   s   |   ¡  dS )z!event handler to hide the tooltipNr
   r1   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   r0   {   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   r2      s    zOnHoverTooltipBase.unschedulec                    s2   z|   ¡  W n ty   Y n0 tt| ƒ ¡  dS r   )r2   r   r&   r!   r   r   r.   r   r   r   ˆ   s
    zOnHoverTooltipBase.hidetip)r"   )N)N)r   r   r   r    r	   r   r)   r+   r0   r2   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.r"   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&   r4   r	   Útext)r   r   r6   r'   r.   r   r   r	   “   s    
zHovertip.__init__c                 C   s$   t | j| jtdtdd}| ¡  d S )Nz#ffffe0r   )r6   ZjustifyZ
backgroundZreliefZborderwidth)ÚLabelr   r6   ZLEFTZSOLIDÚpack)r   Úlabelr   r   r   r       s    ÿzHovertip.showcontents)r"   )r   r   r   r    r	   r   r3   r   r   r.   r   r4   ‘   s   r4   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   r   é–   zPlace your mouse over buttons)r6   z"Button 1 -- 1/2 second hover delayz!This is tooltip text for button1.iô  r5   zButton 2 -- no hover delayz!This is tooltip
text for button2.)
r   ÚtitleÚmapÚintZgeometryÚsplitr7   r8   ZButtonr4   )ÚparentÚtopr   r   r9   Zbutton1Zbutton2r   r   r   Ú_tooltip¦   s    
 rB   Ú__main__)Úmainzidlelib.idle_test.test_tooltipé   F)Ú	verbosityÚexit)ÚrunN)r    Ztkinterr   r!   r4   rB   r   ZunittestrD   Zidlelib.idle_test.htestrH   r   r   r   r   Ú<module>   s   H?