
    .hh                         S r SSKJrJrJrJr  SSKJr  SrSr	Sr
SrSrS	r " S
 S\5      rS r\S:X  a  SSKJr  \" SSSS9  SSKJr  \" \5        gg)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                   x   ^  \ rS rSrSrU 4S jrS rU 4S jrU 4S jrS r	SS jr
S	 rU 4S
 jrS rS rSrU =r$ )CalltipWindow   z+A call-tip widget for tkinter text widgets.c                    > [         TU ]  U5        S=U l        U l        S=U l        =U l        U l        S=U l        U l        SU l	        g)zmCreate 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     :/opt/python-3.13.8/usr/lib/python3.13/idlelib/calltip_w.pyr   CalltipWindow.__init__   sL     	%!%%
TY9===)--d&"&    c                    [        U R                  R                  S5      R                  S5      S   5      nXR                  :X  a  U R                  U R
                  4nOUS4nU R                  R                  SU-  5      nU(       d.  [        U R                  R                  S5      5      nSUS'   SUS'   US   S-   US   US   -   4$ )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_positionCalltipWindow.get_position#   s    d((..x8>>sCAFGnn$ NNDMM:L#Q<L  %%g&<=t))..x89CCFCF1vz3q6CF?**r   c                    > [        U R                  R                  S5      R                  S5      S   5      nXR                  :X  a  gXl        U R                  R                  S5        [        TU ]  5         g)z Reposition the window if needed.r   r    r   N)r$   r%   r&   r'   r   seer   position_window)r   r*   r   s     r   r1   CalltipWindow.position_window2   s_    d((..x8>>sCAFGmm#x(!r   c                 ^  > Xl         U R                  (       d  U R                   (       d  gU R                  R                  [        U5        [        [        U R                  R                  U5      R                  S5      5      u  U l	        U l
        [        TU ]1  5         U R                  5         g)a7  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   r8   CalltipWindow.showtip;   s}     	>>##J
;(+##)))4::3?)A% 	r   c                     [        U R                  U R                  [        SS[        SU R
                  S   S9U l        U R                  R                  5         g)zCreate the call-tip widget.z#ffffd0blackr"   font)r   justify
background
foregroundreliefborderwidthr?   N)r   r4   r   r   r   r%   r   pack)r   s    r   showcontentsCalltipWindow.showcontentsP   sD    4>>		4&/G"'Q $ 2 26 :<
 	

r   c                 F   U R                   (       d  g[        [        U R                  R	                  S5      R                  S5      5      u  p#X R                  :  dD  X R                  :X  a  X0R                  ::  d&  U R                  R                  SS[        5      (       a  U R                  5         gU R                  5         U R                  b%  U R                  R                  U R                  5        U R                  R                  [        U R                   5      U l        g)z4Handle CHECK_HIDE_EVENT: call hidetip or reschedule.Nr   r    >break)r4   r7   r$   r%   r&   r'   r   r   comparer6   hidetipr1   r   after_cancelafterCHECKHIDE_TIMEcheckhide_event)r   eventr*   curcols       r   rP   CalltipWindow.checkhide_eventX   s    ~~  c4#5#5#;#;H#E#K#KC#PQ^^#~~%&MM*A%%hZ@@LLN 	"".++D,C,CD$$^T5I5IJ 	r   c                 H    U R                   (       d  gU R                  5         g)z%Handle HIDE_EVENT by calling hidetip.NrJ   )r4   rL   )r   rQ   s     r   
hide_eventCalltipWindow.hide_events   s    ~~r   c                   > U R                   (       d  g U R                  R                  5         SU l        S=U l        =U l        U l         U R                  R                  [        5         U R                  5         [        TU ]5  5         g! [         a     Nhf = f! [         a     N<f = f! [        [        4 a     NAf = f)zHide the call-tip.N)r4   r   destroyr   r   r   r   r%   
mark_unsetr6   _unbind_events
ValueErrorr   rL   )r   r   s    r   rL   CalltipWindow.hidetip{   s    ~~	JJ  
9===	))*5	!
 	!  		  		
 *% 		s5   B B ,B+ 
BB
B('B(+B>=B>c                    U R                   R                  [        U R                  5      U l        [
         H#  nU R                   R                  [        U5        M%     U R                   R                  [        U R                  5        U R                   R                  [        U R                  5      U l        [         H#  nU R                   R                  [        U5        M%     g)zBind event handlers.N)r%   bindCHECKHIDE_EVENTrP   r   CHECKHIDE_SEQUENCES	event_addrN   rO   
HIDE_EVENTrU   r   HIDE_SEQUENCESr   seqs     r   r9   CalltipWindow._bind_events   s    --22?373G3GI&C((#> '  1E1EF((--j.2oo?!C((S9 "r   c                 |   [          H#  nU R                  R                  [        U5        M%     U R                  R	                  [        U R
                  5        SU l        [         H#  nU R                  R                  [        U5        M%     U R                  R	                  [        U R                  5        SU l        g)zUnbind event handlers.N)	r`   r%   event_deleter_   unbindr   rc   rb   r   rd   s     r   rZ   CalltipWindow._unbind_events   s    &C++OSA '!!/43C3CD!C++J< "!!*dkk:r   )r   r   r   r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r-   r1   r8   rF   rP   rU   rL   r9   rZ   __static_attributes____classcell__)r   s   @r   r   r      s=    5'+"*62
:	 	r   r   c                 >  ^ SSK JnJnJnJn  U" U 5      nUR                  S5        [        [        U R                  5       R                  S5      SS  5      u  pgUR                  SUS-   US-   4-  5        U" U5      nUR                  X4SS	9  UR                  S
S5        UR                  5         [        U5      mU4S jn	U4S jn
UR                  SS5        UR                  SS5        UR                  SU	5        UR                  SU
5        UR!                  5         g )Nr   )ToplevelTextr   BOTHzTest call-tips+r"   z250x100+%d+%d      )sidefillexpandr   zstring.splitc                 ,   > TR                  SSS5        g )Nz(s='Hello world')r   end)r8   rQ   calltips    r   calltip_show%_calltip_window.<locals>.calltip_show   s    +Xu=r   c                 &   > TR                  5         g rk   )rL   r   s    r   calltip_hide%_calltip_window.<locals>.calltip_hide   s    r   z<<calltip-show>>(z<<calltip-hide>>))tkinterrt   ru   r   rv   titler7   r$   geometryr'   rE   r   updater   ra   r^   	focus_set)parentrt   ru   r   rv   topxyr   r   r   r   s              @r   _calltip_windowr      s    22
6
CIIsFOO%++C045DALLAGQW#5569DII41I-KK.)JJLD!G>NN%s+NN%s+II ,/II ,/NNr   __main__)mainz idlelib.idle_test.test_calltip_wr!   F)	verbosityexit)runN)rp   r   r   r   r   r   idlelib.tooltipr   rb   rc   r_   r`   rO   r6   r   r   rl   unittestr   idlelib.idle_test.htestr    r   r   <module>r      sr   
 1 0 '%
//9 (
VK Vr2 z	+quE+ r   