
    e                         d Z ddlmZmZmZmZ ddlmZ dZdZ	dZ
dZdZd	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)zvA call-tip window class for Tkinter/IDLE.

After tooltip.py, which uses ideas gleaned from PySol.
Used by calltip.py.
    )LabelLEFTSOLIDTclError)TooltipBasez<<calltipwindow-hide>>)z<Key-Escape>z
<FocusOut>z<<calltipwindow-checkhide>>)z<KeyRelease>z<ButtonRelease>d   calltipwindowregion_rightc                   f     e Zd ZdZ fdZd Z fdZ fdZd ZddZ	d Z
 fd	Zd
 Zd Z xZS )CalltipWindowz+A call-tip widget for tkinter text widgets.c                     t         |   |       dx| _        | _        dx| _        x| _        | _        dx| _        | _        d| _	        y)z}Create a call-tip; shown by showtip().

        text_widget: a Text widget with code for which call-tips are desired
        N)
super__init__labeltext	parenlineparencollastlinehideidcheckhideidcheckhide_after_id)selftext_widget	__class__s     #lib/python3.12/idlelib/calltip_w.pyr   zCalltipWindow.__init__   sL     	%!%%
TY9===)--d&"&    c                    t        | j                  j                  d      j                  d      d         }|| j                  k(  r| j                  | j
                  f}n|df}| j                  j                  d|z        }|s.t        | j                  j                  d            }d|d<   d|d<   |d   dz   |d   |d   z   fS )z$Choose the position of the call-tip.insert.r   z%d.%d         )intanchor_widgetindexsplitr   r   bboxlist)r   curlineanchor_indexboxs       r   get_positionzCalltipWindow.get_position#   s    d((..x8>>sCAFGdnn$ NNDMM:L#Q<L  %%g&<=t))..x89CCFCF1vz3q6CF?**r   c                     t        | j                  j                  d      j                  d      d         }|| j                  k(  ry|| _        | j                  j                  d       t        |           y)z Reposition the window if needed.r   r   r   N)r"   r#   r$   r%   r   seer   position_window)r   r(   r   s     r   r.   zCalltipWindow.position_window2   sc    d((..x8>>sCAFGdmm#x(!r   c                 L   || _         | j                  s| j                   sy| j                  j                  t        |       t        t        | j                  j                  |      j                  d            \  | _	        | _
        t        | 1          | j                          y)a_  Show the call-tip, bind events which will close it and reposition it.

        text: the text to display in the call-tip
        parenleft: index of the opening parenthesis in the text widget
        parenright: index of the closing parenthesis in the text widget,
                    or the end of the line if there is no closing parenthesis
        Nr   )r   	tipwindowr#   mark_set
MARK_RIGHTmapr"   r$   r%   r   r   r   showtip_bind_events)r   r   	parenleft
parenrightr   s       r   r4   zCalltipWindow.showtip;   s     	>>##J
;(+##)))4::3?)A% 	r   c                     t        | j                  | j                  t        ddt        d| j
                  d         | _        | j                  j                          y)zCreate the call-tip widget.z#ffffd0blackr    font)r   justify
background
foregroundreliefborderwidthr:   N)r   r0   r   r   r   r#   r   pack)r   s    r   showcontentszCalltipWindow.showcontentsP   sD    4>>		4&/G"'Q $ 2 26 :<
 	

r   c                 2   | j                   syt        t        | j                  j	                  d      j                  d            \  }}|| j                  k  s?|| j                  k(  r|| j                  k  s!| j                  j                  ddt              r| j                          y| j                          | j                  %| j                  j                  | j                         | j                  j                  t        | j                         | _        y)z4Handle CHECK_HIDE_EVENT: call hidetip or reschedule.Nr   r   >break)r0   r3   r"   r#   r$   r%   r   r   comparer2   hidetipr.   r   after_cancelafterCHECKHIDE_TIMEcheckhide_event)r   eventr(   curcols       r   rJ   zCalltipWindow.checkhide_eventX   s    ~~  c4#5#5#;#;H#E#K#KC#PQT^^#t~~%&DMM*A%%hZ@LLN 	"".++D,C,CD$$^T5I5IJ 	r   c                 >    | j                   sy| j                          y)z%Handle HIDE_EVENT by calling hidetip.NrD   )r0   rF   )r   rK   s     r   
hide_eventzCalltipWindow.hide_events   s    ~~r   c                 r   | j                   sy	 | j                  j                          d| _        dx| _        x| _        | _        	 | j                  j                  t               	 | j                          t        | 5          y# t        $ r Y gw xY w# t        $ r Y :w xY w# t        t        f$ r Y >w xY w)zHide the call-tip.N)r0   r   destroyr   r   r   r   r#   
mark_unsetr2   _unbind_events
ValueErrorr   rF   )r   r   s    r   rF   zCalltipWindow.hidetip{   s    ~~	JJ  
9===	))*5	!
 	!  		  		
 *% 		s5   B B 'B$ 	BB	B! B!$B65B6c                    | j                   j                  t        | j                        | _        t
        D ]"  }| j                   j                  t        |       $ | j                   j                  t        | j                         | j                   j                  t        | j                        | _        t        D ]"  }| j                   j                  t        |       $ y)zBind event handlers.N)r#   bindCHECKHIDE_EVENTrJ   r   CHECKHIDE_SEQUENCES	event_addrH   rI   
HIDE_EVENTrN   r   HIDE_SEQUENCESr   seqs     r   r5   zCalltipWindow._bind_events   s    --22?373G3GI& 	?C((#>	?  1E1EF((--j.2oo?! 	:C((S9	:r   c                 t   t         D ]"  }| j                  j                  t        |       $ | j                  j	                  t        | j
                         d| _        t        D ]"  }| j                  j                  t        |       $ | j                  j	                  t        | j                         d| _        y)zUnbind event handlers.N)	rW   r#   event_deleterV   unbindr   rZ   rY   r   r[   s     r   rR   zCalltipWindow._unbind_events   s    & 	BC++OSA	B!!/43C3CD! 	=C++J<	=!!*dkk:r   N)__name__
__module____qualname____doc__r   r+   r.   r4   rA   rJ   rN   rF   r5   rR   __classcell__)r   s   @r   r   r      s8    5'+"*62
:	r   r   c                 D   ddl m}m}m}m}  ||       }|j                  d       t        t        | j                         j                  d      dd        \  }}|j                  d|dz   |dz   fz          ||      }|j                  ||d	       |j                  d
d       |j                          t        |      fd}	fd}
|j                  dd       |j                  dd       |j                  d|	       |j                  d|
       |j!                          y )Nr   )ToplevelTextr   BOTHzTest call-tips+r    z250x100+%d+%d      )sidefillexpandr   zstring.splitc                 ,    j                  ddd       y )Nz(s='Hello world')r   end)r4   rK   calltips    r   calltip_showz%_calltip_window.<locals>.calltip_show   s    +Xu=r   c                 &    j                          y r`   )rF   rr   s    r   calltip_hidez%_calltip_window.<locals>.calltip_hide   s    r   z<<calltip-show>>(z<<calltip-hide>>))tkinterrg   rh   r   ri   titler3   r"   geometryr%   r@   r   updater   rX   rU   	focus_set)parentrg   rh   r   ri   topxyr   rt   rv   rs   s              @r   _calltip_windowr      s    22
6
CIIsFOO%++C045DAqLLAGQW#5569DII4d1I-KK.)JJLD!G>NN%s+NN%s+II ,/II ,/NNr   __main__)mainz idlelib.idle_test.test_calltip_wr   F)	verbosityexit)runN)rd   ry   r   r   r   r   idlelib.tooltipr   rY   rZ   rV   rW   rI   r2   r   r   ra   unittestr   idlelib.idle_test.htestr    r   r   <module>r      sr   
 1 0 '%
//9 (
VK Vr0 z	+quE+ r   