B þ®*0iâÚã@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__©ú4/opt/alt/python37/lib/python3.7/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) rrrrrZseer 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Úmaprrrr rr rÚshowtipÚ _bind_events)rr Z parenleftZ parenright)rrrr';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 dk r€|j  |j ¡|j t|j¡|_ dS)z4Handle CHECK_HIDE_EVENT: call hidetip or reschedule.Nrrú>Úbreak)r$r&rrrrr rZcomparer%Úhidetipr#rZ after_cancelÚafterÚCHECKHIDE_TIMEÚcheckhide_event)rÚeventr!Zcurcolrrrr1Xs  zCalltipWindow.checkhide_eventcCs|js dS| ¡dS)z%Handle HIDE_EVENT by calling hidetip.Nr-)r$r.)rr2rrrÚ hide_eventsszCalltipWindow.hide_eventc s¤|js dSy|j ¡Wntk r,YnXd|_d|_|_|_y|j t ¡Wntk rjYnXy |  ¡Wntt fk rYnXt t |ƒ ¡dS)zHide the call-tip.N)r$r Zdestroyrr rrrZ mark_unsetr%Ú_unbind_eventsÚ ValueErrorr rr.)r)rrrr.{s" zCalltipWindow.hidetipcCsp|j t|j¡|_xtD]}|j t|¡qW|j t|j¡|j t |j ¡|_ xt D]}|j t |¡qVWdS)zBind event handlers.N) rÚbindÚCHECKHIDE_EVENTr1rÚCHECKHIDE_SEQUENCESÚ event_addr/r0Ú HIDE_EVENTr3rÚHIDE_SEQUENCES)rÚseqrrrr(”s    zCalltipWindow._bind_eventscCshxtD]}|j t|¡qW|j t|j¡d|_xtD]}|j t|¡q8W|j t|j¡d|_dS)zUnbind event handlers.N) r8rZ event_deleter7Zunbindrr;r:r)rr<rrrr4 s  zCalltipWindow._unbind_events)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__r r"r#r'r+r1r3r.r(r4Ú __classcell__rr)rrrs     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é¯é–)ZsideZfillÚexpandrz string.splitcsˆ ddd¡dS)Nz(s='Hello world')rÚend)r')r2)ÚcalltiprrÚ calltip_show¹sz%_calltip_window..calltip_showcs ˆ ¡dS)N)r.)r2)rJrrÚ calltip_hide»sz%_calltip_window..calltip_hidez<>ú(z<>ú))ÚtkinterrBrCrrDÚtitler&rZgeometryrr*rÚupdaterr9r6Z focus_set) ÚparentrBrCrrDÚtopÚxÚyr rKrLr)rJrÚ_calltip_window¬s"         rVÚ__main__)Úmainz idlelib.idle_test.test_calltip_wrF)Ú verbosityÚexit)ÚrunN)r@rOrrrrZidlelib.tooltiprr:r;r7r8r0r%rrVr=ZunittestrXZidlelib.idle_test.htestr[rrrrÚs