3 ^c@sdZddlZddlZddlZddlZddlZddlmZddlm Z ddl Z GdddZ ddZ d Z d ZdZejd ZdZdZdZddZedkrddlmZeddddS)zPop 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@sXeZdZdddZddZddZddd Zd d Zd d ZddZ ddZ ddZ dS)CalltipNcCs0|dkrd|_n||_|j|_d|_|j|_dSN)editwintextactive_calltip_make_tk_calltip_window_calltip_window)selfrr '/usr/lib64/python3.6/idlelib/calltip.py__init__s zCalltip.__init__cCs d|_dSr)r r r r r closesz Calltip.closecCs tj|jSr)rZ CalltipWindowrrr r r r szCalltip._make_tk_calltip_windowcCs|jr|jjd|_dSr)rZhidetipr Zeventr r r _remove_calltip_window$s zCalltip._remove_calltip_windowcC|jddS)z9The user selected the menu entry or hotkey, open the tip.TZbreak open_calltiprr r r force_open_calltip_event)s z Calltip.force_open_calltip_eventcCr)zHappens 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. FNrrr r r try_open_calltip_event.szCalltip.try_open_calltip_eventcCs|jr|jjr|jddS)NF)rZ tipwindowrrr r r refresh_calltip_event5szCalltip.refresh_calltip_eventcCs|jt|jd}|jd}|s&dS|j|d|j}|sDdS| r\|jddkr\dS|j|}|sndS|j|_ |j j ||d|ddS)NZinsertz(rii) rrrZget_surrounding_bracketsZ set_indexZget_expressionZfind fetch_tipr rZshowtip)r Z evalfuncsZhpZ sur_paren expressionargspecr r r r9s     zCalltip.open_calltipc CsRy|jjjjj}Wntk r*d}YnX|rB|jdd|fiStt|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. NZexecZget_the_calltip) rZflistZpyshellZinterprpccltZAttributeErrorZ remotecall get_argspec get_entity)r rrr r r rLs  zCalltip.fetch_tiprr) __name__Z __module__Z __qualname__r rrrrrrrrr r r r rs  rc Cs>|r:tjj}|jtjy t||Stk r8dSXdS)zwReturn the object corresponding to expression evaluated in a namespace spanning sys.modules and __main.dict__. N)sysZmodulesZcopyZupdate__main__Z__dict__Zeval BaseException)rZ namespacer r r res   riUiz iz(?<=\()\w*\,?\s*zSee source or doczinvalid method signaturez4 ['/' marks preceding arguments as positional-only] c Csrd}}y |j}Wntk r&|SXt|tjr8|n|}yttj|}Wn8tk r}zt|}|j t rvt SWYdd}~XnXd|kr|t 7}t|t r|dkrt }t|tkrtj|ttdn |r|gng}t|tjr|j}n t|dd}|rdxZ|jdtdtD]B} | j} | s(Pt| tkrJ| dtdd } |j| qWdj|}|snt }|S) aReturn 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. ZNz/z())Zsubsequent_indent__doc__Z iz...)Z__call__r!Z isinstancetypesZ MethodTypeZstrinspectZ signatureZ ValueErrorZ startswith_invalid_method_argument_positionalZtype_default_callable_argspecZlen _MAX_COLStextwrapZwrap_INDENTr"ZgetattrZsplit _MAX_LINESZstripZappendZjoin) ZobrZdefaultZob_callZfobZerrZmsgZlinesZdocZliner r r r|s@   *   rr )mainzidlelib.idle_test.test_calltipi)Z verbosityz )r"r$Zrerr)r#ZidlelibrZidlelib.hyperparserrr rrr(r+r*ZcompileZ _first_paramr'r%r&rrZunittestr,r r r r Zs*  S 4