a
    ze                     @   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 )zTools 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 )zCreate 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   %/usr/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::MacWindowStylestylehelpZnoActivates)r   Toplevelr   Zwm_overrideredirectZtk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   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/   r0   r   r(   r#   r   r   r1   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 tooltipNr
   r4   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   r3   {   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   r6      s    zOnHoverTooltipBase.unschedulec                    s2   z|    W n ty   Y n0 tt|   dS r   )r6   r   r(   r#   r   r   r1   r   r   r      s
    zOnHoverTooltipBase.hidetip)r$   )N)N)r   r    r!   r"   r	   r   r,   r.   r3   r6   r   __classcell__r   r   r1   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(   r8   r	   text)r   r   r:   r)   r1   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   r7   r   r   r1   r   r8      s   r8   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)r:   z"Button 1 -- 1/2 second hover delayz!This is tooltip text for button1.i  r9   zButton 2 -- no hover delayz!This is tooltip
text for button2.)
r   titlemapintZgeometrysplitr;   r<   ZButtonr8   )parenttopr   r   r=   Zbutton1Zbutton2r   r   r   _tooltip   s    
 rF   __main__)mainzidlelib.idle_test.test_tooltip   F)	verbosityexit)runN)r"   tkinterr   r#   r8   rF   r   ZunittestrH   Zidlelib.idle_test.htestrL   r   r   r   r   <module>   s   H?