[E @sdZddlTddlmZddlmZmZdZdZdZ dZ dZ dZ dZ dZdZGdddZdS)zH An auto-completion window for IDLE, used by the AutoComplete extension )*)MC_SHIFT)COMPLETE_FILESCOMPLETE_ATTRIBUTESz<> z<>  z!<>z zz zc@seZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZddZddZdS) AutoCompleteWindowcCs||_d|_|_|_d|_|_d|_d|_d|_d|_ d|_ d|_ d|_ d|_ |_|_|_|_|_d|_dS)NF)widgetautocompletewindowlistbox scrollbarorigselforegroundorigselbackground completionsmorecompletionsmodestart startindexlasttypedstartuserwantswindowhideid keypressid listupdateid winconfigid keyreleaseid doubleclickidlastkey_was_tab)selfrr(0/usr/lib/python3.4/idlelib/AutoCompleteWindow.py__init__s        ,zAutoCompleteWindow.__init__cCstt|jt|}d}x1||krW|j|||krW|d7}q'W|t|jkr|jjd|j|fd|jt|jfn|t|kr|jjd|j|f||dn||_dS)Nrz%s+%dc)minlenrrdeleterinsert)r'newstartmin_lenir(r(r) _change_start8s& z AutoCompleteWindow._change_startcCsvd}t|j}xD||kr[||d}|j||krN|}q|d}qWt|t|jdS)zFind the first index in self.completions where completions[i] is greater or equal to s, or the last index if there is no such one.rr+)r-rr,)r'sr2jmr(r(r)_binary_searchEs z!AutoCompleteWindow._binary_searchc CsG|j|}|j|dt||kr6|S|d}t|j}xT||kr||d}|j|dt||kr|}qR|d}qRW|d}||kr|j|S|j|}|j|}tt|t|} t|}x.|| kr8||||kr8|d7}q W|d|S)zAssuming that s is the prefix of a string in self.completions, return the longest string which is a prefix of all the strings which s is a prefix of them. If s is not a prefix of a string, return s.Nr+r4)r8rr-r,) r'r5firstr2r6r7lastZ first_compZ last_compr1r(r(r)_complete_stringRs(# #       #z#AutoCompleteWindow._complete_stringcCst|jjd}|jj||j}|j|}|j||kr]|}nbtt|t|}d}x.||kr||||kr|d7}qW|d|}|j ||j|dt|j |j kr|jj d|j d|j n|jj d|jjdd|jjd|jr|j|_d|_|jjdtx$|jD]}|jjt|qW|jj|j|j |jndS)z|Should be called when the selection of the Listbox has changed. Updates the Listbox display and calls _change_start.rr+NselectbackgroundselectforegroundbgZfg)intr curselectionseerrr8r,r-r3rZ configurerrcgetrr.ENDr/ select_set_selection_changed)r'curselZltsZselstartr0r1r2itemr(r(r)rEqs2   # )    z%AutoCompleteWindow._selection_changedcCsQ|\|_|_||_|jj||_|jj|jd|_|r|j|j}|j}|j ||j |}|j||kr|t |jdks|j|ddt ||kr||kSn||_ |j|_ t|j|_} | jd| jdy#| jjdd| jddWntk rdYnXt| d t|_} t| d | jd d d d|_} x!|jD]} | jt| qW| jd|_| jd|_ | j!d| j"| j#dt$dt%| j#dt&dt'dd|jj(|j |j|j)|jj*t+|j,|_-x!t.D]} |jj/t+| q{W|jj*t0|j1|_2x!t3D]} |jj/t0| qW|jj*t4|j5|_6|jj/t4t7| j*t8|j9|_:| j*t;|j<|_=| j*t>|j?|_@dS)zShow the autocomplete list, bind events. If complete is True, complete the text, and if there is exactly one matching completion, don't open a list.r/r+Nz +10000+10000z!::tk::unsupported::MacWindowStyleZstylehelpZ noActivatesZorientZyscrollcommandZexportselectionFr>Zwhiter=r<ZcommandZsideZfillexpandT)Arrrrindexrgetrr;r3r8r-rrZToplevelr wm_geometryZwm_overrideredirectZtkcallZ_wZTclErrorZ ScrollbarZVERTICALrZListboxsetrr/rCrBrrZconfigZyviewZpackZRIGHTYZLEFTZBOTHrDrEZbindHIDE_VIRTUAL_EVENT_NAME hide_eventr HIDE_SEQUENCESZ event_addKEYPRESS_VIRTUAL_EVENT_NAMEkeypress_eventr!KEYPRESS_SEQUENCESKEYRELEASE_VIRTUAL_EVENT_NAMEkeyrelease_eventr$KEYRELEASE_SEQUENCELISTUPDATE_SEQUENCElistselect_eventr"WINCONFIG_SEQUENCEwinconfig_eventr#DOUBLECLICK_SEQUENCEdoubleclick_eventr%)r'Z comp_listsrJcompleterZ userWantsWinZ completedrr2acwrrrGseqr(r(r) show_windowsf   '              zAutoCompleteWindow.show_windowcCs |jsdS|j}|j|j|j|j\}}}}|j}|j|j}} |j|j} } |jt |t d| |} |j |} | ||| ks|| kr| |7} n | | 8} |j d| | fdS)Nrz+%d+%d) is_activerrArZbboxrZ winfo_width winfo_heightZ winfo_rootxr,maxZ winfo_rootyrL)r'eventtextxyZcxZcyr`Z acw_widthZ acw_heightZ text_widthZ text_heightZnew_xZnew_yr(r(r)r\s   &   z"AutoCompleteWindow.winconfig_eventcCs|jsdS|jdS)N)rc hide_window)r'rfr(r(r)rQs zAutoCompleteWindow.hide_eventcCsJ|jsdSd|_t|jjd}|j|j|dS)NTr)rcrr?rr@r3r)r'rfrFr(r(r)rZs   z#AutoCompleteWindow.listselect_eventcCs;t|jjd}|j|j||jdS)Nr)r?rr@r3rrj)r'rfrFr(r(r)r^sz$AutoCompleteWindow.doubleclick_eventcs]|jsdS|jt|dr4|j}nd}dkrRd|_ntdksd(ks|jtkrd)kr|t@ rtdkr|j |j ndkr|j |j d ndkr|j |j d n`d kr)|j |j d n=t|j dkrL|j dS|j |j dd*|j |_ |j jdt|j jd|j j|j|j |jd Sdkr|j dS|jtkrd+ks|jtkrd,kr|t@ rt|j jd}|j|dt|j |j kr|jtksx|j r|j |j|n|j dSd-kr-| r-d|_t|j jd}dkrd}ndkr t|jd}nd.kr|j j|j j|j jd}dkrbtd||}qdkstttt|jd||}nTdkrtd|d}n2dksttt|jd|d}|j j||j j||j|j |j|d Sdkr| r|jrt|j jd}|j |j||j d Sd|_d|_dSntfdd d/DrdS|jrK|jd'krK|j |j |j|j |_ |j jdt|j jd|j j|j|j |jd S|j dSdS)0Nmc_staterZTabFr+ underscore BackSpaceperiodminus_.-breakZReturnspace parenleft parenright bracketleft bracketrightslash backslashquotedbl apostropheHomeEndPriorNextUpDownTc3s|]}|kVqdS)Nr().0r5)keysymr(r) asz4AutoCompleteWindow.keypress_event..ShiftControlAltMetaCommandOption )rlrm)rnro)rnrtrurvrwrx)ryrzr{r|)r}r~rrrr)rr)rrrrrr)rcrhasattrrkr&r-rrrr3rrjrrZ select_clearr?r@rDr8rErrrZnearestrdreAssertionErrorr,anychar)r'rfstaterFZnewseljumpr()rr)rTs            &      )        #         &  z!AutoCompleteWindow.keypress_eventcCs[|jsdS|jjd|jjd|jt|jfkrW|jndS)Nr/z%s+%dc)rcrrJrr-rrj)r'rfr(r(r)rWts  +z#AutoCompleteWindow.keyrelease_eventcCs |jdk S)N)r)r'r(r(r)rc|szAutoCompleteWindow.is_activecCs|j|j|jdS)N)r3r;r)r'r(r(r)r_szAutoCompleteWindow.completecCsL|jsdSx!tD]}|jjt|qW|jjt|jd|_x!tD]}|jjt|qZW|jjt|j d|_ |jjt t |jjt |j d|_ |j jt|jd|_|jjt|jd|_|jjd|_|j jd|_ |jjd|_dS)N)rcrRrZ event_deleterPZunbindr rUrSr!rVrXr$rrYr"rr[r#rZdestroy)r'rar(r(r)rjs0              zAutoCompleteWindow.hide_windowN)__name__ __module__ __qualname__r*r3r8r;rErbr\rQrZr^rTrWrcr_rjr(r(r(r)rs   $ E     s   rN)rr) rr r r r r rrrr)__doc__ZtkinterZidlelib.MultiCallrZidlelib.AutoCompleterrrPrRrSrUrVrXrYr[r]rr(r(r(r)s