î Òê[,ã@sódZddlZddlZddlZddlZddlZddlZddlmZddl m Z Gdd„dƒZ dd„Z d Z d ZdZejd ƒZdZdd„ZedkrïddlmZedddƒndS)aCallTips.py - An IDLE Extension to Jog Your Memory 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)Ú CallTipWindow)Ú HyperParserc@s”eZdZddgfgZddd„Zdd„Zd d „Zdd d „Zd d„Zdd„Z dd„Z dd„Z dd„Z dS)ÚCallTipsZeditú Show call tipú<>NcCsF|dkrd|_n*||_|j|_d|_|j|_dS)N)ÚeditwinÚtextÚactive_calltipÚ_make_tk_calltip_windowÚ_calltip_window)Úselfr©r ú&/usr/lib/python3.4/idlelib/CallTips.pyÚ__init__s      zCallTips.__init__cCs d|_dS)N)r )r r r rÚclose#szCallTips.closecCstj|jƒS)N)rZCallTipr)r r r rr &sz CallTips._make_tk_calltip_windowcCs&|jr"|jjƒd|_ndS)N)r Zhidetip)r Úeventr r rÚ_remove_calltip_window*s  zCallTips._remove_calltip_windowcCs|jdƒdS)z9The user selected the menu entry or hotkey, open the tip.TN)Ú open_calltip)r rr r rÚforce_open_calltip_event/sz!CallTips.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_event3szCallTips.try_open_calltip_eventcCs,|jr(|jjƒr(|jdƒndS)NF)r Z is_activer)r rr r rÚrefresh_calltip_event:szCallTips.refresh_calltip_eventcCsÆ|jƒt|jdƒ}|jdƒ}|s5dS|j|dƒ|jƒ}|s\dS| r||jdƒdkr|dS|j|ƒ}|s•dS|jƒ|_ |j j ||d|dƒdS)NÚinsertú(rééÿÿÿÿ) rrrZget_surrounding_bracketsZ set_indexZget_expressionÚfindÚ fetch_tipr r Zshowtip)r Z evalfuncsZhpZ sur_parenÚ expressionÚargspecr r rr>s   zCallTips.open_calltipc Csgy|jjjjj}Wntk r3d}YnX|rS|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 rr r r rrQs    zCallTips.fetch_tip)rr) Ú__name__Ú __module__Ú __qualname__Zmenudefsrrr rrrrrrr r r rrs       rc CsV|rRtjjƒ}|jtjƒyt||ƒSWqRtk rNdSYqRXndS)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 rr#is r#éUéú éz(?<=\()\w*\,?\s*zSee source or docc Csîd}y |j}Wntk r+|SYnXt|tƒrG|j}n!t|tjƒrb|}n|}t|tjtjfƒrÝtj tj |ƒŒ}t|ttjfƒsÅt|tjƒrÝt j d|ƒ}qÝnt |ƒtkrtj|tdtƒn|r|gng}t|tjƒr:|j}nt|ddƒ}|rÛxt|jdtƒdt…D]V}|jƒ}|s‹Pnt |ƒtkr¸|dtd…d}n|j|ƒqoWdj|ƒ}n|sêt}n|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. ÚZsubsequent_indentÚ__doc__Ú Néz...)Ú__call__r.Ú isinstanceÚtyperÚtypesÚ MethodTypeÚ FunctionTypeÚinspectZ formatargspecZgetfullargspecÚ _first_paramÚsubÚlenÚ _MAX_COLSÚtextwrapZwrapÚ_INDENTr5ÚgetattrÚsplitÚ _MAX_LINESÚstripÚappendÚjoinÚ_default_callable_argspec)ÚobrZob_callZfobÚlinesÚdocÚliner r rr"s>      ? #  r"r+)Úmainzidlelib.idle_test.test_calltipsÚ verbosityéz )r5r+r>Úrer'rCr;ZidlelibrZidlelib.HyperParserrrr#rBrGrDÚcompiler?rKr"r$ZunittestrPr r r rÚs&      W  .