3 § f³ã@s°dZddlZddlZddlZddlZddlZddlmZddlm Z ddl Z Gdd„dƒZ dd„Z d Z d ZdZejd ƒZdZdZdZdd„Zedkr¬ddlmZeddd�dS)zúPop up a reminder of how to call a function. Call Tips are floating windows which display function, class, and method parameter and docstring information when you type an opening parenthesis, and which disappear when you type a closing parenthesis. éN)Ú calltip_w)Ú HyperParserc@sXeZdZddd„Zdd„Zdd„Zddd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dS)ÚCalltipNcCs0|dkrd|_n||_|j|_d|_|j|_dS)N)ÚeditwinÚtextÚactive_calltipÚ_make_tk_calltip_windowÚ_calltip_window)Úselfr©r ú4/opt/alt/python36/lib64/python3.6/idlelib/calltip.pyÚ__init__s zCalltip.__init__cCs d|_dS)N)r )r r r r Úclosesz Calltip.closecCs tj|jƒS)N)rZ CalltipWindowr)r r r r r szCalltip._make_tk_calltip_windowcCs|jr|jjƒd|_dS)N)rZhidetip)r Úeventr r r Ú_remove_calltip_window$s zCalltip._remove_calltip_windowcCs|jdƒdS)z9The user selected the menu entry or hotkey, open the tip.TÚbreak)Ú open_calltip)r rr r r Úforce_open_calltip_event)s z Calltip.force_open_calltip_eventcCs|jdƒdS)zªHappens when it would be nice to open a calltip, but not really necessary, for example after an opening bracket, so function calls won't be made. FN)r)r rr r r Útry_open_calltip_event.szCalltip.try_open_calltip_eventcCs|jr|jjr|jdƒdS)NF)rZ tipwindowr)r rr r r Úrefresh_calltip_event5szCalltip.refresh_calltip_eventcCs”|jƒt|jdƒ}|jdƒ}|s&dS|j|dƒ|jƒ}|sDdS| r\|jdƒdkr\dS|j|ƒ}|sndS|jƒ|_ |j j ||d|dƒdS)NÚinsertú(rééÿÿÿÿ) rrrZget_surrounding_bracketsZ set_indexZget_expressionÚfindÚ fetch_tipr rZshowtip)r Z evalfuncsZhpZ sur_parenÚ expressionÚargspecr r r r9s     zCalltip.open_calltipc CsRy|jjjjj}Wntk r*d}YnX|rB|jdd|fiƒStt|ƒƒSdS)aDReturn the argument list and docstring of a function or class. If there is a Python subprocess, get the calltip there. Otherwise, either this fetch_tip() is running in the subprocess or it was called in an IDLE running without the subprocess. The subprocess environment is that of the most recently run script. If two unrelated modules are being edited some calltips in the current module may be inoperative if the module was not the last to run. To find methods, fetch_tip must be fed a fully qualified name. NÚexecZget_the_calltip) rZflistZpyshellZinterpÚrpccltÚAttributeErrorZ remotecallÚ get_argspecÚ get_entity)r rrr r r rLs  zCalltip.fetch_tip)N)N) Ú__name__Ú __module__Ú __qualname__r rrrrrrrrr r r r rs  rc Cs>|r:tjjƒ}|jtjƒy t||ƒStk r8dSXdS)zwReturn the object corresponding to expression evaluated in a namespace spanning sys.modules and __main.dict__. N)ÚsysÚmodulesÚcopyÚupdateÚ__main__Ú__dict__ÚevalÚ BaseException)rÚ namespacer r r r"es   r"éUéú éz(?<=\()\w*\,?\s*zSee source or doczinvalid method signaturez4 ['/' marks preceding arguments as positional-only] c Csrd}}y |j}Wntk r&|SXt|tjƒr8|n|}yttj|ƒƒ}Wn8tk r†}zt|ƒ}|j t ƒrvt SWYdd}~XnXd|kr˜|t 7}t|t ƒr®|dkr®t }t|ƒtkrÊtj|ttd�n |rÔ|gng}t|tjƒrì|j}n t|ddƒ}|�rdxZ|jdtƒdt…D]B} | jƒ} | �s(Pt| ƒtk�rJ| dtd…d } |j| ƒ�qWdj|ƒ}|�snt }|S) a¡Return a string describing the signature of a callable object, or ''. For Python-coded functions and methods, the first line is introspected. Delete 'self' parameter for classes (.__init__) and bound methods. The next lines are the first lines of the doc string up to the first empty line or _MAX_LINES. For builtins, this typically includes the arguments in addition to the return value. ÚNú/z())Zsubsequent_indentÚ__doc__Ú éz...)Ú__call__r-Ú isinstanceÚtypesÚ MethodTypeÚstrÚinspectZ signatureÚ ValueErrorÚ startswithÚ_invalid_methodÚ_argument_positionalÚtypeÚ_default_callable_argspecÚlenÚ _MAX_COLSÚtextwrapZwrapÚ_INDENTr5ÚgetattrÚsplitÚ _MAX_LINESÚstripÚappendÚjoin) ÚobrÚdefaultZob_callZfobÚerrÚmsgÚlinesÚdocÚliner r r r!|s@   *   r!r*)Úmainzidlelib.idle_test.test_calltipé)Ú verbosityz )r5r=Úrer&rFr:ZidlelibrZidlelib.hyperparserrr*rr"rErJrGÚcompileZ _first_paramrCr@rAr!r#ZunittestrUr r r r Ús*  S 4