
    "eG                         d Z ddl  G d d      Z G d de      Z G d de      Zd	 Zed
k(  r ddlmZ  eddd       ddl	m
Z
  e
e       yy)zTools for displaying tool-tips.

This includes:
 * an abstract base-class for different kinds of tooltips
 * a simple text-only Tooltip class
    )*c                   :    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
y	)
TooltipBasez abstract base class for tooltipsc                      || _         d| _        y)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   s     !lib/python3.12/idlelib/tooltip.py__init__zTooltipBase.__init__   s     +    c                 $    | j                          y Nhidetipr	   s    r
   __del__zTooltipBase.__del__   s    r   c                    | j                   ryt        | j                        x| _         }|j                  d       	 |j                  j                  dd|j                  dd       | j                          | j                          | j                   j                          | j                   j                          y# t        $ r Y `w xY w)zdisplay the tooltipN   z!::tk::unsupported::MacWindowStylestylehelpnoActivates)r   Toplevelr   wm_overrideredirecttkcall_wTclErrorposition_windowshowcontentsupdate_idletasksliftr	   tws     r
   showtipzTooltipBase.showtip   s    >>&t'9'9::
q!	 EEJJ:GRUU}.
 	'')  		s   )B: :	CCc                     | j                         \  }}| j                  j                         |z   }| j                  j                         |z   }| j                  j                  d||fz         y)z&(re)-set the tooltip's screen position+%d+%dN)get_positionr   winfo_rootxwinfo_rootyr   wm_geometry)r	   xyroot_xroot_ys        r
   r   zTooltipBase.position_window/   sb      "1##//1A5##//1A5""8vv.>#>?r   c                 @    d| j                   j                         dz   fS )z(choose a screen position for the tooltip   r   )r   winfo_heightr   s    r
   r'   zTooltipBase.get_position6   s#     4%%224q888r   c                     t         )z$content display hook for sub-classes)NotImplementedErrorr   s    r
   r   zTooltipBase.showcontentsA   s
     "!r   c                 p    | j                   }d| _         |r	 |j                          yy# t        $ r Y yw xY wzhide the tooltipN)r   destroyr   r"   s     r
   r   zTooltipBase.hidetipF   s>     ^^

   s   ) 	55N)__name__
__module____qualname____doc__r   r   r$   r   r'   r   r    r   r
   r   r   
   s)    **@	9"
	r   r   c                   T     e Zd ZdZd	 fd	Z fdZd
dZd
dZd Zd Z	 fdZ
 xZS )OnHoverTooltipBasez?abstract base class for tooltips, with delayed on-hover displayc                 B   t         |   |       || _        d| _        | j                  j                  d| j                        | _        | j                  j                  d| j                        | _	        | j                  j                  d| j                        | _
        y)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   hover_delay	_after_idr   bind_show_event_id1_hide_event_id2_id3)r	   r   rC   	__class__s      r
   r   zOnHoverTooltipBase.__init__U   s     	'&&&++It7G7GH	&&++It7G7GH	&&++J8H8HI	r   c                 &   	 | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         t        |           y # t
        $ r Y w xY w)Nr?   r@   rA   )r   unbindrG   rI   rJ   r   rB   r   r	   rK   s    r
   r   zOnHoverTooltipBase.__del__g   sv    	%%i;%%i;%%j$))< 	  		s   A2B 	BBc                 ^    | j                   r| j                          y| j                          y)z$event handler to display the tooltipN)rC   scheduler$   r	   events     r
   rF   zOnHoverTooltipBase._show_eventp   s    MMOLLNr   c                 $    | j                          y)z!event handler to hide the tooltipNr   rQ   s     r
   rH   zOnHoverTooltipBase._hide_eventw   s    r   c                     | j                          | j                  j                  | j                  | j                        | _        y)z*schedule the future display of the tooltipN)
unscheduler   afterrC   r$   rD   r   s    r
   rP   zOnHoverTooltipBase.schedule{   s4    ++11$2B2B26,,@r   c                 f    | j                   }d| _         |r| j                  j                  |       yy)z(cancel the future display of the tooltipN)rD   r   after_cancel)r	   after_ids     r
   rU   zOnHoverTooltipBase.unschedule   s.    >>++H5 r   c                 b    	 | j                          t        |           y# t        $ r Y w xY wr5   )rU   r   rB   r   rN   s    r
   r   zOnHoverTooltipBase.hidetip   s2    	OO 	  		s   " 	..i  r   )r7   r8   r9   r:   r   r   rF   rH   rP   rU   r   __classcell__rK   s   @r
   r=   r=   R   s0    IJ$@6 r   r=   c                   *     e Zd ZdZd fd	Zd Z xZS )HovertipzAA tooltip that pops up when a mouse hovers over an anchor widget.c                 6    t         |   ||       || _        y)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.
        rC   N)rB   r   text)r	   r   rb   rC   rK   s       r
   r   zHovertip.__init__   s     	K@	r   c                 ~    t        | j                  | j                  t        dt        d      }|j                          y )Nz#ffffe0r   )rb   justify
backgroundreliefborderwidth)Labelr   rb   LEFTSOLIDpack)r	   labels     r
   r   zHovertip.showcontents   s+    dnn499d!*5aI

r   r[   )r7   r8   r9   r:   r   r   r\   r]   s   @r
   r_   r_      s    Gr   r_   c                    t        |       }|j                  d       t        t        | j	                         j                  d      dd        \  }}|j	                  d||dz   fz         t        |d      }|j                          t        |d      }|j                          t        |d	d
       t        |d      }|j                          t        |dd        y )NzTest tooltip+r   r&      zPlace your mouse over buttons)rb   z"Button 1 -- 1/2 second hover delayz!This is tooltip text for button1.i  ra   zButton 2 -- no hover delayz!This is tooltip
text for button2.)
r   titlemapintgeometrysplitrh   rk   Buttonr_   )parenttopr+   r,   rl   button1button2s          r
   _tooltiprz      s    
6
CIInsFOO%++C045DAqLLQCL()#;<E	JJLSCDGLLNW9sKS;<GLLNW:Mr   __main__)mainzidlelib.idle_test.test_tooltip   F)	verbosityexit)runN)r:   tkinterr   r=   r_   rz   r7   unittestr|   idlelib.idle_test.htestr   r;   r   r
   <module>r      se    E EP< <~! *N z	)QUC+M r   