
    d                         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           dS dS )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| _	        dS )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     #  /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/calltip_w.pyr   zCalltipWindow.__init__   s]     	%%%!%%
TY9===)--d&"&    c                    t          | j                            d                              d          d                   }|| j        k    r| j        | j        f}n|df}| j                            d|z            }|s1t          | 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8>>sCCAFGGdn$$ NDM:LL#Q<L %%g&<== 	t)..x8899CCFCF1vz3q6CF?**r   c                 $   t          | j                            d                              d          d                   }|| j        k    rdS || _        | j                            d           t                                                       dS )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   s    d(..x88>>sCCAFGGdm##Fx(((!!!!!r   c                 x   || _         | j        s| j         sdS | j                            t          |           t          t          | j                            |                              d                    \  | _	        | _
        t                                                       |                                  dS )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     	> 	 	F##J
;;;(+#)))44::3??)A )A% 	r   c                     t          | j        | j        t          ddt          d| j        d                   | _        | j                                         dS )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   sQ    4>	4&/G"'Q $ 26 :< < <
 	
r   Nc                    | j         sdS t          t          | j                            d                              d                    \  }}|| j        k     s7|| j        k    r|| j        k    s!| j                            ddt                    r| 
                                 dS |                                  | j        | j                            | j                   | j                            t          | j                  | _        dS )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    ~ 	 4 c4#5#;#;H#E#E#K#KC#P#PQQT^##t~%%&DM*A*A%%hZ@@ +BLLNNN7 	".++D,CDDD$$^T5IJJ 	tr   c                 @    | j         sdS |                                  dS )z%Handle HIDE_EVENT by calling hidetip.NrD   )r0   rF   )r   rK   s     r   
hide_eventzCalltipWindow.hide_events   s#    ~ 	4wr   c                    | j         sdS 	 | j                                         n# t          $ r Y nw xY wd| _        dx| _        x| _        | _        	 | j                            t                     n# t          $ r Y nw xY w	 | 
                                 n# t          t          f$ r Y nw xY wt                                                       dS )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   ~ 	F	J     	 	 	D	
9===	))*5555 	 	 	D		!!!!*% 	 	 	D	 	s0   & 
33A3 3
B ?B B B-,B-c                    | j                             t          | j                  | _        t
          D ]"}| j                             t          |           #| j                             t          | j                   | j                             t          | j
                  | _        t          D ]"}| j                             t          |           #dS )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?373GI I& 	? 	?C((#>>>>  1EFFF(--j.2o? ?! 	: 	:C((S9999	: 	:r   c                 ^   t           D ]"}| j                            t          |           #| j                            t          | j                   d| _        t          D ]"}| j                            t          |           #| j                            t          | j                   d| _        dS )zUnbind event handlers.N)	rW   r#   event_deleterV   unbindr   rZ   rY   r   r[   s     r   rR   zCalltipWindow._unbind_events   s    & 	B 	BC++OSAAAA!!/43CDDD! 	= 	=C++J<<<<!!*dk:::r   N)__name__
__module____qualname____doc__r   r+   r.   r4   rA   rJ   rN   rF   r5   rR   __classcell__)r   s   @r   r   r      s        55' ' ' ' '+ + +" " " " "    *     6      2
: 
: 
:	 	 	 	 	 	 	r   r   c                    ddl m}m}m}m}  ||           }|                    d           t          t          |                                 	                    d          dd                    \  }}|                    d|dz   |dz   fz              ||          }|
                    ||d	           |                    d
d           |                                 t          |          fd}	fd}
|                    dd           |                    dd           |                    d|	           |                    d|
           |                                 d S )Nr   )ToplevelTextr   BOTHzTest call-tips+r    z250x100+%d+%d      )sidefillexpandr   zstring.splitc                 6                         ddd           d S )Nz(s='Hello world')r   end)r4   rK   calltips    r   calltip_showz%_calltip_window.<locals>.calltip_show   s     +Xu=====r   c                 0                                      d S 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2222222222
(6

CIIsFOO%%++C00455DAqLLAGQW#55666499DII4d1I---KK.)))JJLLL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      s   
 1 0 0 0 0 0 0 0 0 0 0 0 ' ' ' ' ' '%
//9 (
V V V V VK V V Vr  0 zD	+quEEEE++++++C r   