7ec @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   #  #    cCsT|\|_|_||_|jj||_|jj|jd|_|r|j|j}|j}|j ||j |}|j||kr|t |jdks|j|dt | |kr||kSn||_ |j|_ t|j|_} | jd| jdy#| jjdd| jddWntk r]nXt| dt|_} t| d | jd td d |_} x!|jD]} | jt| qW| jd |_ | jd|_!| j"d| j#| j$dt%dt&| j$dt'dt(dt)| j*|jj+|j |j|j,|jj-t.|j/|_0x!t1D]} |jj2t.| q~W|jj-t3|j4|_5x!t6D]} |jj2t3| qW|jj-t7|j8|_9|jj2t7t:| j-t;|j<|_=| j-t>|j?|_@| j-tA|jB|_CdS(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 is +10000+10000s!::tk::unsupported::MacWindowStyletstylethelpt noActivatestorienttyscrollcommandtexportselectionR0twhiteR/R.tcommandtsidetfilltexpandN(DR R RRtindexRtgetRR-R$R(RRRtToplevelRt wm_geometrytwm_overrideredirectttktcallt_wtTclErrort ScrollbartVERTICALR tListboxtsetRRR R7R6R R tconfigtyviewtpacktRIGHTtYtLEFTtBOTHtTruetliftR8R9tbindtHIDE_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 completedRR#tacwR RR=tseq((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyt show_windowsh   !               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(RteventttexttxtytcxtcyRtt acw_widtht acw_heightt text_widtht text_heighttnew_xtnew_y((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRms   &   cCs|jsdS|jdS(N(Rwt hide_window(RR~((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRas cCsJ|jsdSt|_t|jjd}|j|j|dS(Ni(RwR]RR2RR3R$R (RR~R:((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRks   cCs;t|jjd}|j|j||jdS(Ni(R2RR3R$R R(RR~R:((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRoscs|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!| r!t|_t|jjd}dkrd}ndkrt|jd}nd*kr|jj|jj|jjd}dkrVtd||}qdkshttt|jd||}nTdkrtd|d}n2dksttt|jd|d}|jj||jj||j|j |j|d Sdkr| r|jrxt|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 bstShifttControltAlttMetatCommandtOption(RR(RR(RRRRRR(RRRR(RRRRRR(RR(RRRRRR(RwRthasattrRRRRRRRR$RRRRt select_clearR2R3R8R(R9RR R]RtnearestRzR|tAssertionErrorRtany(RR~tstateR:tnewseltjump((Rs2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRes            &      #        #         cCs[|jsdS|jjd|jjd|jt|jfkrW|jndS(NR s%s+%dc(RwRRIRRRR(RR~((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRhls  +cCs |jdk S(N(RR(R((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRwtscCs|j|j|jdS(N(R$R-R(R((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRqwscCsL|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(RwRbRt event_deleteR`tunbindRRRfRdRRgRiRRRjRRRlRR tdestroy(RRu((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyR{s0              (t__name__t __module__RR$R(R-R9RvRmRaRkRoReRhRwRqR(((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyRs  $ F     j   N(s s ( sss s ss s s s s ((t__doc__tTkintertidlelib.MultiCallRtidlelib.AutoCompleteRRR`RbRdRfRgRiRjRlRnR(((s2/usr/lib64/python2.7/idlelib/AutoCompleteWindow.pyts