a  ze@sdZddlmZmZmZmZddlmZdZdZ dZ dZ dZ d Z Gd d d eZd d ZedkrddlmZeddddddlmZeedS)zvA call-tip window class for Tkinter/IDLE. After tooltip.py, which uses ideas gleaned from PySol. Used by calltip.py. )LabelLEFTSOLIDTclError) TooltipBasez<>)z z z<>)z zdZcalltipwindowregion_rightcsveZdZdZfddZddZfddZfdd Zd d Zdd dZ ddZ fddZ ddZ ddZ ZS) CalltipWindowz+A call-tip widget for tkinter text widgets.csDtt||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__E/opt/bitninja-python-dojo/embedded/lib/python3.9/idlelib/calltip_w.pyr s   zCalltipWindow.__init__cCst|jddd}||jkr2|j|jf}n|df}|jd|}|snt|jd}d|d<d|d<|dd|d|dfS)z$Choose the position of the call-tip.insert.rz%d.%d)int anchor_widgetindexsplitr rZbboxlist)rcurlineZ anchor_indexZboxrrr get_position#s zCalltipWindow.get_positioncsLt|jddd}||jkr(dS||_|jdtt|dS)z Reposition the window if needed.rrrN) rrrr rZseer rposition_window)rr"rrrr$2s   zCalltipWindow.position_windowcs^||_|js|jsdS|jt|tt|j|d\|_ |_ t t | |dS)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 tipwindowrZmark_set MARK_RIGHTmaprrr r rr rshowtip _bind_events)rr Z parenleftZ parenrightrrrr(;s   zCalltipWindow.showtipc Cs2t|j|jtddtd|jdd|_|jdS)zCreate the call-tip widget.z#ffffd0Zblackrfont)r ZjustifyZ backgroundZ foregroundZreliefZ borderwidthr*N)rr%r rrrr packrrrr showcontentsPs  zCalltipWindow.showcontentsNcCs|js dStt|jdd\}}||jksT||jkrD||jksT|jddt r`| dS| |j dur|j |j |jt|j|_ dS)z4Handle CHECK_HIDE_EVENT: call hidetip or reschedule.Nrr>break)r%r'rrrr r rZcomparer&hidetipr$rZ after_cancelafterCHECKHIDE_TIMEcheckhide_event)reventr"Zcurcolrrrr3Xs$  zCalltipWindow.checkhide_eventcCs|js dS|dS)z%Handle HIDE_EVENT by calling hidetip.Nr/)r%r0)rr4rrr hide_eventsszCalltipWindow.hide_eventc s|js dSz|jWnty*Yn0d|_d|_|_|_z|jt WntyfYn0z | Wntt fyYn0t t |dS)zHide the call-tip.N)r%r Zdestroyrr rrrZ mark_unsetr&_unbind_events ValueErrorr rr0r,rrrr0{s"   zCalltipWindow.hidetipcCsh|jt|j|_tD]}|jt|q|jt|j|jt |j |_ t D]}|jt |qPdS)zBind event handlers.N) rbindCHECKHIDE_EVENTr3rCHECKHIDE_SEQUENCES event_addr1r2 HIDE_EVENTr5rHIDE_SEQUENCESrseqrrrr)szCalltipWindow._bind_eventscCs`tD]}|jt|q|jt|jd|_tD]}|jt|q2|jt|jd|_dS)zUnbind event handlers.N) r:rZ event_deleter9Zunbindrr=r<rr>rrrr6szCalltipWindow._unbind_events)N)__name__ __module__ __qualname____doc__r r#r$r(r-r3r5r0r)r6 __classcell__rrrrrs     rc sddlm}m}m}m}||}|dtt| ddd\}}|d|d|df||}|j ||dd | d d | t |fd d } fdd} |dd|dd|d| |d| |dS)Nr)ToplevelTextrBOTHzTest call-tips+rz 250x100+%d+%d)Zsidefillexpandrz string.splitcsddddS)Nz(s='Hello world')rend)r(r4Zcalltiprr calltip_showsz%_calltip_window..calltip_showcs dS)N)r0rNrOrr calltip_hidesz%_calltip_window..calltip_hidez<>(z<>))tkinterrErFrrGtitler'rZgeometryr r+rupdaterr;r8Z focus_set) parentrErFrrGtopxyr rPrQrrOr_calltip_windows"         r[__main__)mainz idlelib.idle_test.test_calltip_wrF) verbosityexit)runN)rCrTrrrrZidlelib.tooltiprr<r=r9r:r2r&rr[r@Zunittestr]Zidlelib.idle_test.htestr`rrrrs