
    dG                         d Z ddlT  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           dS 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                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
TooltipBasez abstract base class for tooltipsc                 "    || _         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   s     !  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/idlelib/tooltip.py__init__zTooltipBase.__init__   s     +    c                 .    |                                   d S Nhidetipr	   s    r
   __del__zTooltipBase.__del__   s    r   c                    | j         rdS t          | j                  x| _         }|                    d           	 |j                            dd|j        dd           n# t          $ r Y nw xY w|                                  | 	                                 | j         
                                 | j                                          dS )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    > 	F&t'9:::
q!!!	 EJJ:GRU}. . . . 	 	 	D	 	'')))s   #A 
A,+A,c                     |                                  \  }}| j                                        |z   }| j                                        |z   }| j                            d||fz             dS )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/   so      ""1#//11A5#//11A5""8vv.>#>?????r   c                 >    d| 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44q888r   c                     t           )z$content display hook for sub-classes)NotImplementedErrorr   s    r
   r   zTooltipBase.showcontentsA   s
     "!r   c                 v    | j         }d| _         |r(	 |                                 dS # t          $ r Y dS w xY wdS zhide the tooltipN)r   destroyr   r"   s     r
   r   zTooltipBase.hidetipF   s\     ^ 	

   	 	s   ( 
66N)__name__
__module____qualname____doc__r   r   r$   r   r'   r   r    r   r
   r   r   
   s        **      *@ @ @	9 	9 	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 display  c                 D   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   hover_delay	_after_idr   bind_show_event_id1_hide_event_id2_id3)r	   r   rD   	__class__s      r
   r   zOnHoverTooltipBase.__init__U   s     	'''&&++It7GHH	&++It7GHH	&++J8HII			r   c                 ,   	 | j                             d| j                   | j                             d| j                   | j                             d| j                   n# t
          $ r Y nw xY wt                                                       d S )Nr@   rA   rB   )r   unbindrH   rJ   rK   r   rC   r   r	   rL   s    r
   r   zOnHoverTooltipBase.__del__g   s    	%%i;;;%%i;;;%%j$)<<<< 	 	 	D	s   A A$ $
A10A1Nc                 h    | j         r|                                  dS |                                  dS )z$event handler to display the tooltipN)rD   scheduler$   r	   events     r
   rG   zOnHoverTooltipBase._show_eventp   s/     	MMOOOOOLLNNNNNr   c                 .    |                                   dS )z!event handler to hide the tooltipNr   rR   s     r
   rI   zOnHoverTooltipBase._hide_eventw   s    r   c                     |                                   | j                            | j        | j                  | _        dS )z*schedule the future display of the tooltipN)
unscheduler   afterrD   r$   rE   r   s    r
   rQ   zOnHoverTooltipBase.schedule{   s<    +11$2B26,@ @r   c                 ^    | j         }d| _         |r| j                            |           dS dS )z(cancel the future display of the tooltipN)rE   r   after_cancel)r	   after_ids     r
   rV   zOnHoverTooltipBase.unschedule   s?    > 	6++H55555	6 	6r   c                     	 |                                   n# t          $ r Y nw xY wt                                                       dS r5   )rV   r   rC   r   rO   s    r
   r   zOnHoverTooltipBase.hidetip   sU    	OO 	 	 	D	s    
%%r>   r   )r7   r8   r9   r:   r   r   rG   rI   rQ   rV   r   __classcell__rL   s   @r
   r=   r=   R   s        IIJ J J J J J$          @ @ @6 6 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.r>   c                 \    t                                          ||           || _        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.
        rD   N)rC   r   text)r	   r   rc   rD   rL   s       r
   r   zHovertip.__init__   s-     	K@@@			r   c                     t          | j        | j        t          dt          d          }|                                 d S )Nz#ffffe0r   )rc   justify
backgroundreliefborderwidth)Labelr   rc   LEFTSOLIDpack)r	   labels     r
   r   zHovertip.showcontents   s;    dn49d!*5aI I I

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