î e fò#ã@s÷dZddlZddlZddlZddlmZejejdZe ddƒ\Z Z ddl m Z ddlmZddlZejZejr±eej7ZnGd d „d ƒZed kródd lmZed ddƒndS)zÖAutoComplete.py - An IDLE extension for automatically completing names. This extension can complete either attribute names of file names. It can pop a window with all available names, for the user to select from. éN)ÚidleConfÚ_éé)ÚAutoCompleteWindow)Ú HyperParserc@sÐeZdZdd!gfgZejddddddd ƒZd d d „Zd d„Zd dd„Z dd„Z dd„Z dd„Z dd„Z dd„Zd dd„Zdd„Zdd „Zd S)"Ú AutoCompleteZeditúShow Completionsú<>Ú extensionsÚ popupwaitÚtypeÚintÚdefaultrNcCsD||_|dkrdS|j|_d|_d|_d|_dS)N)ÚeditwinÚtextÚautocompletewindowÚ_delayed_completion_idÚ_delayed_completion_index)Úselfr©rú9/opt/alt/python34/lib64/python3.4/idlelib/AutoComplete.pyÚ__init__&s     zAutoComplete.__init__cCstj|jƒS)N)rr)rrrrÚ_make_autocomplete_window3sz&AutoComplete._make_autocomplete_windowcCs&|jr"|jjƒd|_ndS)N)rZ hide_window)rÚeventrrrÚ_remove_autocomplete_window6s  z(AutoComplete._remove_autocomplete_windowcCs|jdddƒdS)zqHappens when the user really wants to open a completion list, even if a function call is needed. TFN)Úopen_completions)rrrrrÚforce_open_completions_event;sz)AutoComplete.force_open_completions_eventcCs`|jjdƒ}|dkr7|jdddtƒn%|tkr\|jdddtƒndS)z¦Happens when it would be nice to open a completion list, but not really necessary, for example after an dot, so function calls won't be made. z insert-1cÚ.FN)rÚgetÚ_open_completions_laterÚCOMPLETE_ATTRIBUTESÚSEPSÚCOMPLETE_FILES)rrZlastcharrrrÚtry_open_completions_eventAs   z'AutoComplete.try_open_completions_eventcCsht|dƒr|jrdS|jrE|jjƒrE|jjƒdS|jdddƒ}|rddSdS)z¥Happens 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_stateNÚbreakFT)Úhasattrr%rZ is_activeÚcompleter)rrZopenedrrrÚautocomplete_eventNs zAutoComplete.autocomplete_eventcGs_|jjdƒ|_|jdk r:|jj|jƒn|jj|j|j|Œ|_dS)NÚinsert)rÚindexrrÚ after_cancelÚafterr Ú_delayed_open_completions)rÚargsrrrr ^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|jƒd|_nt|jdƒ}|jjddƒ}t|ƒ}}|jƒr| s„|tkr|j ƒt}x,|rÂ||ddt krÂ|d8}q—W|||…} |}x(|r||ddkr|d8}qÜW|||…} n|j ƒr| s6|t kr|j ƒt }xB|rŠ||dt ks}t||dƒdkrŠ|d8}qIW|||…} |r ||ddkr |jdt|ƒ|dƒ|jƒ} | s| r| jd ƒd krdSqd } ndS|r/| r/| r/dS|j| |ƒ} | d sOdS|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,rrrÚlenZ is_in_stringr#rr"Z is_in_coder!ÚID_CHARSÚordZ set_indexZget_expressionÚfindÚfetch_completionsrrZ show_window) rZ evalfuncsr(Z userWantsWinÚmodeZhpZcurlineÚiÚjZ comp_startZ comp_whatZ comp_listsrrrrlsN  ! 7    zAutoComplete.open_completionsc Csíy|jjjjj}Wnd}YnX|rL|jdd||fiƒS|tkrK|dkrÙtjj ƒ}|j tj jƒt d|ƒ}|j ƒd|krÃtt d|ƒƒ}qHdd„|Dƒ}qÐyZ|j|ƒ}t|ƒ}|j ƒd|krt|jƒ}nd d„|Dƒ}WqÐggfSYqÐXn…|tkrÐ|dkrld }nyBtjj|ƒ}tj|ƒ}|j ƒd d„|Dƒ}WqÐtk rÌggfSYqÐXn|sß|}n||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. NÚexecZget_the_completion_listr2zdir()Ú__all__cSs,g|]"}|dd…dkr|‘qS)Nrrr)Ú.0Úsrrrú Äs z2AutoComplete.fetch_completions..cSs,g|]"}|dd…dkr|‘qS)Nrrr)r>r?rrrr@Ís rcSs,g|]"}|dd…dkr|‘qS)Nrrr)r>r?rrrr@Øs )rZflistZpyshellZinterpÚrpccltZ remotecallr!Ú__main__Ú__dict__ÚcopyÚupdateÚ __builtins__ÚevalÚsortÚsortedÚ get_entityÚdirr=r#ÚosÚpathÚ expanduserÚlistdirÚOSError) rZwhatr9rAÚ namespaceZbiglZsmalllZentityZ expandedpathrrrr8§sL                zAutoComplete.fetch_completionscCs,tjjƒ}|jtjƒt||ƒS)zALookup name in a namespace spanning sys.modules and __main.dict__)ÚsysÚmodulesrDrErBrCrG)rÚnamerQrrrrJàszAutoComplete.get_entity)r r )Ú__name__Ú __module__Ú __qualname__ZmenudefsrZ GetOptionr rrrrr$r)r r.rr8rJrrrrrs       ; 9rrB)Úmainz#idlelib.idle_test.test_autocompleteÚ verbosityé)Ú__doc__rLrRÚstringZidlelib.configHandlerrZ ascii_lettersZdigitsr5Úranger!r#ZidlelibrZidlelib.HyperParserrrBÚsepr"ÚaltseprrUZunittestrXrrrrÚs       Ì