3  f@sdZddlmZmZmZmZddlmZdZdZ dZ dZ d Z d Z Gd d d eZddZedkrddlmZeddddddlmZeedS)zvA call-tip window class for Tkinter/IDLE. After tooltip.py, which uses ideas gleaned from PySol. Used by calltip.py. )LabelLEFTSOLIDTclError) TooltipBasez<> z<> dZcalltipwindowregion_rightcsveZdZdZfddZddZfddZfdd Zd d Zdd dZ ddZ fddZ ddZ ddZ ZS) CalltipWindowz+A call-tip widget for tkinter text widgets.csDtt|j|d|_|_d|_|_|_d|_|_ d|_ dS)z}Create a call-tip; shown by showtip(). text_widget: a Text widget with code for which call-tips are desired N) superr __init__labeltext parenlineparencollastlinehideid checkhideidcheckhide_after_id)selfZ text_widget) __class__6/opt/alt/python36/lib64/python3.6/idlelib/calltip_w.pyrs   zCalltipWindow.__init__cCst|jjdjdd}||jkr2|j|jf}n|df}|jjd|}|snt|jjd}d|d<d|d<|dd|d|dfS)z$Choose the position of the call-tip.insert.rz%d.%d)int anchor_widgetindexsplitrrZbboxlist)rcurlineZ anchor_indexZboxrrr get_position#s zCalltipWindow.get_positioncsLt|jjdjdd}||jkr(dS||_|jjdtt|jdS)z Reposition the window if needed.rrrN) r r!r"r#rZseer r position_window)rr%)rrrr'2s   zCalltipWindow.position_windowcs`||_|js|j rdS|jjt|tt|jj|jd\|_ |_ t t |j |jdS)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!Zmark_set MARK_RIGHTmapr r"r#rrr r showtip _bind_events)rrZ parenleftZ parenright)rrrr+;s zCalltipWindow.showtipc Cs0t|j|jtdtd|jdd|_|jjdS)zCreate the call-tip widget.z#ffffe0rfont)rZjustifyZ backgroundZreliefZ borderwidthr-N)rr(rrrr!rpack)rrrr showcontentsPs zCalltipWindow.showcontentsNcCs|js dStt|jjdjd\}}||jksT||jkrD||jksT|jjddt r`|j dS|j |j dk r|jj |j |jjt|j|_ dS)z4Handle CHECK_HIDE_EVENT: call hidetip or reschedule.Nrr>break)r(r*r r!r"r#rrZcomparer)hidetipr'rZ after_cancelafterCHECKHIDE_TIMEcheckhide_event)reventr%Zcurcolrrrr5Ws  zCalltipWindow.checkhide_eventcCs|js dS|jdS)z%Handle HIDE_EVENT by calling hidetip.Nr1)r(r2)rr6rrr hide_eventrszCalltipWindow.hide_eventcs|js dSy|jjWntk r,YnXd|_d|_|_|_y|jjt Wntk rjYnXy |j Wntt fk rYnXt t |jdS)zHide the call-tip.N)r(rZdestroyrrrrr!Z mark_unsetr)_unbind_events ValueErrorr r r2)r)rrrr2zs" zCalltipWindow.hidetipcCsp|jjt|j|_xtD]}|jjt|qW|jjt|j|jjt |j |_ xt D]}|jjt |qVWdS)zBind event handlers.N) r!bindCHECKHIDE_EVENTr5rCHECKHIDE_SEQUENCES event_addr3r4 HIDE_EVENTr7rHIDE_SEQUENCES)rseqrrrr,s    zCalltipWindow._bind_eventscCshxtD]}|jjt|qW|jjt|jd|_xtD]}|jjt|q8W|jjt|jd|_dS)zUnbind event handlers.N) r<r!Z event_deleter;Zunbindrr?r>r)rr@rrrr8s  zCalltipWindow._unbind_events)N)__name__ __module__ __qualname____doc__rr&r'r+r/r5r7r2r,r8 __classcell__rr)rrr s     r c sddlm}m}m}m}||}|jdtt|jj ddd\}}|jd|d|df||}|j ||dd |j d d |j t |fd d } fdd} |jdd|jdd|jd| |jd| |jdS)Nr)ToplevelTextrBOTHzTest call-tips+rz 250x100+%d+%d)ZsideZfillexpandrz string.splitcsjddddS)Nz(s='Hello world')rend)r+)r6)calltiprr calltip_showsz%_calltip_window..calltip_showcs jdS)N)r2)r6)rNrr calltip_hidesz%_calltip_window..calltip_hidez<>(z<>))tkinterrFrGrrHtitler*r Zgeometryr#r.rupdater r=r:Z focus_set) parentrFrGrrHtopxyrrOrPr)rNr_calltip_windows"         rZ__main__)mainz idlelib.idle_test.test_calltip_wrF) verbosityexit)runN)rr)r r )rDrSrrrrZidlelib.tooltiprr>r?r;r<r4r)r rZrAZunittestr\Zidlelib.idle_test.htestr_rrrrs