f ž _öc@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 zidZcalltipwindowregion_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©Z __class__©ú*/usr/lib64/python3.10/idlelib/calltip_w.pyrs   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ééi)ÚintÚ anchor_widgetÚindexÚsplitr r ZbboxZlist)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) rrrrr ZseerrÚposition_window)rrrrrr2s   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Úmaprrrr r rrÚ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.Nrrz>Úbreak)r r"rrrrr r Zcomparer!ÚhidetiprrZ after_cancelÚafterÚCHECKHIDE_TIMEÚcheckhide_event)rÚeventrZcurcolrrrr-Xs$ ÿÿþ ÿzCalltipWindow.checkhide_eventcCs|js dS| ¡dS)z%Handle HIDE_EVENT by calling hidetip.Nr))r r*)rr.rrrÚ 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 r r rZ mark_unsetr!Ú_unbind_eventsZ ValueErrorrrr*r'rrrr*{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_EVENTr-rÚCHECKHIDE_SEQUENCESÚ event_addr+r,Ú HIDE_EVENTr/rÚHIDE_SEQUENCES©rZseqrrrr$”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) r3rZ event_deleter2Zunbindrr6r5rr7rrrr0 szCalltipWindow._unbind_events©N)Ú__name__Z __module__Z __qualname__Ú__doc__rrrr#r(r-r/r*r$r0Z __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-tipsz+rz 250x100+%d+%di¯i–)ZsideZfillZexpandrz string.splitcsˆ ddd¡dS)Nz(s='Hello world')rZend)r#©r.©ZcalltiprrÚ calltip_show¹óz%_calltip_window..calltip_showcs ˆ ¡dSr8)r*r>r?rrÚ calltip_hide»rAz%_calltip_window..calltip_hidez<>z(z<>z))Útkinterr;r<rr=Ztitler"rZgeometryrr&rZupdaterr4r1Z focus_set) Zparentr;r<rr=ZtopZxZyr r@rBrr?rÚ_calltip_window¬s"         rDZ__main__)Úmainz idlelib.idle_test.test_calltip_wrF)Z verbosityZexit)ÚrunN)r:rCrrrrZidlelib.tooltiprr5r6r2r3r,r!rrDr9ZunittestrEZidlelib.idle_test.htestrFrrrrZs