Fa#@sdZddlZddlZddlZddlmZejejdZe dd\Z Z ddl m Z ddlmZddlZejZejreej7ZGd d d Zed krdd lmZed dddS)zAutoComplete.py - An IDLE extension for automatically completing names. This extension can complete either attribute names or file names. It can pop a window with all available names, for the user to select from. N)idleConf_)AutoCompleteWindow) HyperParserc@seZdZdd!gfgZejddddddd Zd d d Zd dZd ddZ ddZ ddZ ddZ ddZ ddZd ddZddZdd Zd S)" AutoCompleteZeditShow Completions<> extensions popupwaittypeintdefaultrNcCsD||_|dkrdS|j|_d|_d|_d|_dS)N)editwintextautocompletewindow_delayed_completion_id_delayed_completion_index)selfrr*/usr/lib/python3.5/idlelib/AutoComplete.py__init__&s     zAutoComplete.__init__cCstj|jS)N)rr)rrrr_make_autocomplete_window3sz&AutoComplete._make_autocomplete_windowcCs#|jr|jjd|_dS)N)rZ hide_window)reventrrr_remove_autocomplete_window6s  z(AutoComplete._remove_autocomplete_windowcCs|jddddS)zqHappens when the user really wants to open a completion list, even if a function call is needed. TFN)open_completions)rrrrrforce_open_completions_event;sz)AutoComplete.force_open_completions_eventcCs]|jjd}|dkr7|jdddtn"|tkrY|jdddtdS)zHappens when it would be nice to open a completion list, but not really necessary, for example after a dot, so function calls won't be made. z insert-1c.FN)rget_open_completions_laterCOMPLETE_ATTRIBUTESSEPSCOMPLETE_FILES)rrZlastcharrrrtry_open_completions_eventAs   z'AutoComplete.try_open_completions_eventcCsht|dr|jrdS|jrE|jjrE|jjdS|jddd}|rddSdS)zHappens when the user wants to complete his word, and if necessary, open a completion list after that (if there is more than one completion) mc_stateNbreakFT)hasattrr%rZ is_activecompleter)rrZopenedrrrautocomplete_eventNs zAutoComplete.autocomplete_eventcGs\|jjd|_|jdk r7|jj|j|jj|j|j||_dS)Ninsert)rindexrr after_cancelZafterr _delayed_open_completions)rargsrrrr ^s z$AutoComplete._open_completions_latercGs9d|_|jjd|jkr(dS|j|dS)Nr*)rrr+rr)rr.rrrr-fs z&AutoComplete._delayed_open_completionsc Cs|jdk r+|jj|jd|_t|jd}|jjdd}t|}}|jr| s|tkr|j t}x,|r||ddt kr|d8}qW|||} |}x(|r||ddkr|d8}qW|||} n|j r| s3|t kr|j t }xB|r||dt kszt||ddkr|d8}qFW|||} |r||ddkr|jdt||d|j} | s| r | jd d kr dSqd } ndS|r,| r,| r,dS|j| |} | d sLdS|j|_|jj| dt| ||| S) aXFind the completions and create the AutoCompleteWindow. Return True if successful (no syntax error or so found). if complete is True, then if there's nothing to complete and no start of completion, won't open completions and return False. If mode is given, will open a completion list only in this mode. Nr*zinsert linestartrz'"rz insert-%dc(r)rrr,rrrlenZ is_in_stringr#rr"Z is_in_coder!ID_CHARSordZ set_indexZget_expressionfindfetch_completionsrrZ show_window) rZ evalfuncsr(Z userWantsWinmodeZhpZcurlineijZ comp_startZ comp_whatZ comp_listsrrrrlsN  ! 7    zAutoComplete.open_completionsc Csy|jjjjj}Wnd}YnX|rL|jdd||fiS|tkrK|dkrtjj }|j tj jt d|}|j d|krtt d|}qHdd|D}qyZ|j|}t|}|j d|krt|j}nd d|D}WqggfSYqXn|tkr|dkrid }yBtjj|}tj|}|j d d|D}Wntk rggfSYnX|s|}||fSdS) aOReturn a pair of lists of completions for something. The first list is a sublist of the second. Both are sorted. If there is a Python subprocess, get the comp. list there. Otherwise, either fetch_completions() is running in the subprocess itself or it was called in an IDLE EditorWindow before any script had been run. 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. NexecZget_the_completion_listr1zdir()__all__cSs,g|]"}|dddkr|qS)Nrrr).0srrr s z2AutoComplete.fetch_completions..cSs,g|]"}|dddkr|qS)Nrrr)r=r>rrrr?s rcSs,g|]"}|dddkr|qS)Nrrr)r=r>rrrr?s )rZflistZpyshellZinterprpccltZ remotecallr!__main____dict__copyupdate __builtins__evalsortsorted get_entitydirr<r#ospath expanduserlistdirOSError) rZwhatr8r@ namespaceZbiglZsmalllZentityZ expandedpathrrrr7sL              zAutoComplete.fetch_completionscCs,tjj}|jtjt||S)zALookup name in a namespace spanning sys.modules and __main.dict__)sysmodulesrCrDrArBrF)rnamerPrrrrIszAutoComplete.get_entity)r r )__name__ __module__ __qualname__ZmenudefsrZ GetOptionr rrrrr$r)r r-rr7rIrrrrrs       ; 9rrA)mainz#idlelib.idle_test.test_autocomplete verbosity)__doc__rKrQstringZidlelib.configHandlerrZ ascii_lettersZdigitsr4ranger!r#ZidlelibrZidlelib.HyperParserrrAsepr"altseprrTZunittestrWrrrrs