f ž _öã@s’dZddlmZmZmZmZddlmZdZdZ dZ dZ dZ d Z Gd d „d eƒZd d „ZedkrŽddlmZeddddddlmZeeƒdS)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<>)z z z<>)z zédZcalltipwindowregion_rightcsveZdZdZ‡fdd„Zdd„Z‡fdd„Z‡fdd „Zd d „Zdd d„Z dd„Z ‡fdd„Z dd„Z dd„Z ‡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__ÚlabelÚtextÚ parenlineÚparencolÚlastlineÚhideidÚ checkhideidÚcheckhide_after_id)ÚselfZ text_widget©Ú __class__©ú*/usr/lib64/python3.10/idlelib/calltip_w.pyr s   zCalltipWindow.__init__cCsŠt|j d¡ d¡dƒ}||jkr2|j|jf}n|df}|j d|¡}|snt|j d¡ƒ}d|d<d|d<|dd|d|dfS)z$Choose the position of the call-tip.ÚinsertÚ.rz%d.%dééé)ÚintÚ anchor_widgetÚindexÚsplitr rZbboxÚlist)rÚcurlineZ anchor_indexZboxrrrÚ get_position#s zCalltipWindow.get_positioncsLt|j d¡ d¡dƒ}||jkr(dS||_|j d¡tt|ƒ ¡dS)z Reposition the window if needed.rrrN) rrrr rZseer rÚposition_window)rr"rrrr$2s   zCalltipWindow.position_windowcs^||_|js|jsdS|j t|¡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_RIGHTÚmaprrr r rr rÚshowtipÚ _bind_events)rr Z parenleftZ parenrightrrrr(;s  ÿ zCalltipWindow.showtipc Cs2t|j|jtddtd|jdd|_|j ¡dS)zCreate the call-tip widget.z#ffffd0ZblackrÚfont)r ZjustifyZ backgroundZ foregroundZreliefZ borderwidthr*N)rr%r rrrr Úpack©rrrrÚ showcontentsPs  ýzCalltipWindow.showcontentsNcCs–|js dStt|j d¡ d¡ƒ\}}||jksT||jkrD||jksT|j ddt ¡r`|  ¡dS|  ¡|j dur€|j  |j ¡|j t|j¡|_ dS)z4Handle CHECK_HIDE_EVENT: call hidetip or reschedule.Nrrú>Úbreak)r%r'rrrr r rZcomparer&Úhidetipr$rZ after_cancelÚafterÚCHECKHIDE_TIMEÚcheckhide_event)rÚeventr"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|j ¡Wnty*Yn0d|_d|_|_|_z|j t ¡WntyfYn0z |  ¡Wntt fyŠYn0t t |ƒ ¡dS)zHide the call-tip.N)r%r Zdestroyrr rrrZ mark_unsetr&Ú_unbind_eventsÚ ValueErrorr rr0r,rrrr0{s"   zCalltipWindow.hidetipcCsh|j t|j¡|_tD]}|j t|¡q|j t|j¡|j t |j ¡|_ t D]}|j t |¡qPdS)zBind event handlers.N) rÚbindÚCHECKHIDE_EVENTr3rÚCHECKHIDE_SEQUENCESÚ event_addr1r2Ú HIDE_EVENTr5rÚHIDE_SEQUENCES©rÚseqrrrr)”sÿÿzCalltipWindow._bind_eventscCs`tD]}|j t|¡q|j t|j¡d|_tD]}|j t|¡q2|j t|j¡d|_dS)zUnbind event handlers.N) r:rZ event_deleter9Zunbindrr=r<rr>rrrr6 szCalltipWindow._unbind_events)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r r#r$r(r-r3r5r0r)r6Ú __classcell__rrrrrs     rc sìddlm}m}m}m}||ƒ}| d¡tt| ¡  d¡dd…ƒ\}}| d|d|df¡||ƒ}|j ||dd |  d d ¡|  ¡t |ƒ‰‡fd d „} ‡fdd„} | dd¡| dd¡| d| ¡| d| ¡| ¡dS)Nr)ÚToplevelÚTextrÚBOTHzTest call-tipsú+rz 250x100+%d+%dé¯é–)ZsideÚfillÚexpandrz string.splitcsˆ ddd¡dS)Nz(s='Hello world')rÚend)r(©r4©ZcalltiprrÚ calltip_show¹sz%_calltip_window..calltip_showcs ˆ ¡dS)N)r0rNrOrrÚ calltip_hide»sz%_calltip_window..calltip_hidez<>ú(z<>ú))ÚtkinterrErFrrGÚtitler'rZgeometryr r+rÚupdaterr;r8Z focus_set) ÚparentrErFrrGÚtopÚxÚyr rPrQrrOrÚ_calltip_window¬s"         r[Ú__main__)Úmainz idlelib.idle_test.test_calltip_wrF)Ú verbosityÚexit)ÚrunN)rCrTrrrrZidlelib.tooltiprr<r=r9r:r2r&rr[r@Zunittestr]Zidlelib.idle_test.htestr`rrrrÚs