pfc @sdZddlTddlmZddlmZmZdZdZdZ dZ dZ dZ dZ dZdZdddYZdS(sH An auto-completion window for IDLE, used by the AutoComplete extension i(t*(tMC_SHIFT(tCOMPLETE_FILEStCOMPLETE_ATTRIBUTESs<>s s s<>sss s ss s s s s s!<>s ss stAutoCompleteWindowcBseZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZRS(cCs||_d|_|_|_d|_|_d|_d|_d|_ d|_ d|_ d|_ d|_ d|_|_|_|_|_|_t|_dS(N(twidgettNonetautocompletewindowtlistboxt scrollbartorigselforegroundtorigselbackgroundt completionstmorecompletionstmodetstartt startindextlasttypedstarttuserwantswindowthideidt keypressidt listupdateidt winconfigidt keyreleaseidt doubleclickidtFalsetlastkey_was_tab(tselfR((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyt__init__s        ,cCstt|jt|}d}x1||krW|j|||krW|d7}q'W|t|jkr|jjd|j|fd|jt|jfn|t|kr|jjd|j|f||n||_dS(Niis%s+%dc(tmintlenRRtdeleteRtinsert(Rtnewstarttmin_lenti((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyt _change_start8s& cCsvd}t|j}xD||kr[||d}|j||krN|}q|d}qWt|t|jdS(sFind 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.iii(RR R(RtsR#tjtm((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyt_binary_searchEs c Cs5|j|}|j|t| |kr0|S|d}t|j}xN||kr||d}|j|t| |kr|}qL|d}qLW|d}||kr|j|S|j|}|j|}tt|t|} t|}x.|| kr,||||kr,|d7}qW|| S(sAssuming 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.ii(R(R RR( RR%tfirstR#R&R'tlastt first_compt last_compR"((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyt_complete_stringRs(        #cCst|jjd}|jj||j}|j|}|j||kr]|}n\tt|t|}d}x.||kr||||kr|d7}qW|| }|j ||j|t|j  |j kr |jj d|j d|j n|jj d|jjdd|jjd|jr|j|_d|_|jjdtx$|jD]}|jjt|qwW|jj|j|j |jndS(s|Should be called when the selection of the Listbox has changed. Updates the Listbox display and calls _change_start.iitselectbackgroundtselectforegroundtbgtfgN(tintRt curselectiontseeRR R(RRR$Rt configureR R tcgetR RRtENDR t select_sett_selection_changed(RtcurseltltstselstartR!R"R#titem((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyR9qs2   #  #    c Cs;|\|_|_||_|jj||_|jj|jd|_|r|j|j}|j ||j |}|j||kr|t |jdks|j|dt | |krdSn||_ |j|_ t|j|_}|jd|jdy#|jjdd|jddWntk rNnXt|d t|_} t|d | jd td d |_} x!|jD]} | jt| qW| jd|_ | jd|_!| j"d| j#| j$dt%dt&| j$dt'dt(dt)|jj*|j |j|j+|jj,t-|j.|_/x!t0D]} |jj1t-| qeW|jj,t2|j3|_4x!t5D]} |jj1t2| qW|jj,t6|j7|_8|jj1t6t9| j,t:|j;|_<|j,t=|j>|_?| j,t@|jA|_BdS(sShow 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 iNs +10000+10000s!::tk::unsupported::MacWindowStyletstylethelpt noActivatestorienttyscrollcommandtexportselectionR0twhiteR/R.tcommandtsidetfilltexpand(CR R RRtindexRtgetRR-R$R(RRRtToplevelRt wm_geometrytwm_overrideredirectttktcallt_wtTclErrort ScrollbartVERTICALR tListboxtsetRRR R7R6R R tconfigtyviewtpacktRIGHTtYtLEFTtBOTHtTrueR8R9tbindtHIDE_VIRTUAL_EVENT_NAMEt hide_eventRtHIDE_SEQUENCESt event_addtKEYPRESS_VIRTUAL_EVENT_NAMEtkeypress_eventRtKEYPRESS_SEQUENCEStKEYRELEASE_VIRTUAL_EVENT_NAMEtkeyrelease_eventRtKEYRELEASE_SEQUENCEtLISTUPDATE_SEQUENCEtlistselect_eventRtWINCONFIG_SEQUENCEtwinconfig_eventRtDOUBLECLICK_SEQUENCEtdoubleclick_eventR( Rt comp_listsRItcompleteRt userWantsWint completedR#tacwR RR=tseq((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyt show_windowsd  !             cCs |jsdS|j}|j|j|j|j\}}}}|j}|j|j}} |j|j} } |jt |t d| |} |j |} | ||| ks|| kr| |7} n | | 8} |j d| | fdS(Nis+%d+%d( t is_activeRR4RtbboxRt winfo_widtht winfo_heightt winfo_rootxRtmaxt winfo_rootyRL(RteventttexttxtytcxtcyRst acw_widtht acw_heightt text_widtht text_heighttnew_xtnew_y((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRls   &   cCs|jsdS|jdS(N(Rvt hide_window(RR}((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyR`s cCsJ|jsdSt|_t|jjd}|j|j|dS(Ni(RvR]RR2RR3R$R (RR}R:((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRjs   cCs;t|jjd}|j|j||jdS(Ni(R2RR3R$R R(RR}R:((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRnscs|jsdS|jt|dr4|j}nd}dkrRt|_ntdksd%ks|jtkrd&kr|t @ rtdkr|j |j ndkr|j |j d n}dkr|j |j d nZdkr)|j |j d n7t|j dkrL|j dS|j |j d |j |_ |jjdt|jjd|jj|j|j |jd Sdkr|j dS|jtkrd'ks|jtkrd(kr|t @ rt|jjd}|j|t|j  |j kr|jtksl|j r|j |j|n|j dSd)kr| rt|_t|jjd}dkrd}ndkrt|jd}nd*kry|jj|jj|jjd}dkrVtd||}qtt|jd||}nBdkrtd|d}n tt|jd|d}|jj||jj||j|j |j|d Sdkrm| rm|jrTt|jjd}|j |j||j d St|_t|_dSn.tfdd+DrdS|j dSdS(,Ntmc_stateitTabit underscoret BackSpacetperiodtminust_t.t-itbreaktReturntspacet parenleftt parenrightt bracketleftt bracketrighttslasht backslashtquotedblt apostrophetHometEndtPriortNexttUptDownc3s|]}|kVqdS(N((t.0R%(tkeysym(s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pys `stShifttControltAlttMetatCommandtOption(RR(RR(RRRRRR(sslashRRR(RRRRRR(RR(RRRRRR(RvRthasattrRRRRRRRR$RRRRt select_clearR2R3R8R(R9RR R]RtnearestRyR{Rtany(RR}tstateR:tnewseltjump((Rs2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRds            &      #        #         cCs[|jsdS|jjd|jjd|jt|jfkrW|jndS(NR s%s+%dc(RvRRIRRRR(RR}((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRgjs  +cCs |jdk S(N(RR(R((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRvrscCs|j|j|jdS(N(R$R-R(R((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRpuscCsL|jsdSx!tD]}|jjt|qW|jjt|jd|_x!tD]}|jjt |qZW|jjt |j d|_ |jjt t |jjt |j d|_ |jjt|jd|_|jjt|jd|_|jjd|_|jjd|_|jjd|_dS(N(RvRaRt event_deleteR_tunbindRRReRcRRfRhRRRiRRRkRR tdestroy(RRt((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRys0              (t__name__t __module__RR$R(R-R9RuRlR`RjRnRdRgRvRpR(((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRs  $ D     j   N(s s ( sss s ss s s s s ((t__doc__tTkintertidlelib.MultiCallRtidlelib.AutoCompleteRRR_RaRcReRfRhRiRkRmR(((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyts