ó
|Nc        
   @   sƒ   d  Z  d d l Td d l m Z d d l m Z m Z d Z d Z d Z	 d Z
 d Z d Z d Z d Z d Z d d d „  ƒ  YZ d S(   sH   
An auto-completion window for IDLE, used by the AutoComplete extension
iÿÿÿÿ(   t   *(   t   MC_SHIFT(   t   COMPLETE_FILESt   COMPLETE_ATTRIBUTESs   <<autocompletewindow-hide>>s
   <FocusOut>s   <ButtonPress>s   <<autocompletewindow-keypress>>s   <Key>s   <Key-BackSpace>s   <Key-Return>s	   <Key-Tab>s   <Key-Up>s
   <Key-Down>s
   <Key-Home>s	   <Key-End>s   <Key-Prior>s
   <Key-Next>s!   <<autocompletewindow-keyrelease>>s   <KeyRelease>s   <B1-ButtonRelease>s   <Configure>s   <B1-Double-ButtonRelease>t   AutoCompleteWindowc           B   s   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s¨   | |  _  d  |  _ |  _ |  _ d  |  _ |  _ d  |  _ d  |  _ d  |  _	 d  |  _
 d  |  _ d  |  _ d  |  _ d  |  _ |  _ |  _ |  _ |  _ |  _ t |  _ d  S(   N(   t   widgett   Nonet   autocompletewindowt   listboxt	   scrollbart   origselforegroundt   origselbackgroundt   completionst   morecompletionst   modet   startt
   startindext   lasttypedstartt   userwantswindowt   hideidt
   keypressidt   listupdateidt   winconfigidt   keyreleaseidt   doubleclickidt   Falset   lastkey_was_tab(   t   selfR   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyt   __init__   s    								,c         C   sì   t  t |  j ƒ t | ƒ ƒ } d } x1 | | k  rW |  j | | | k rW | d 7} q' W| t |  j ƒ k  r¦ |  j j d |  j | f d |  j t |  j ƒ f ƒ n  | t | ƒ k  rß |  j j d |  j | f | | ƒ n  | |  _ d  S(   Ni    i   s   %s+%dc(   t   mint   lenR   R   t   deleteR   t   insert(   R   t   newstartt   min_lent   i(    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyt   _change_start8   s    & c         C   sv   d } t  |  j ƒ } xD | | k r[ | | d } |  j | | k rN | } q | d } q Wt | t  |  j ƒ d ƒ S(   s’   Find 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.i    i   i   (   R   R   R   (   R   t   sR#   t   jt   m(    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyt   _binary_searchE   s     	c   
      C   s5  |  j  | ƒ } |  j | t | ƒ  | k r0 | S| d } t |  j ƒ } xN | | k r™ | | d } |  j | t | ƒ  | k rŒ | } qL | d } qL W| d } | | k r» |  j | S|  j | } |  j | } t t | ƒ t | ƒ ƒ }	 t | ƒ } x. | |	 k  r,| | | | k r,| d 7} qÿ W| |  S(   sÖ   Assuming 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.i   i   (   R(   R   R   R   (
   R   R%   t   firstR#   R&   R'   t   lastt
   first_compt	   last_compR"   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyt   _complete_stringR   s(    
	
#c         C   sÁ  t  |  j j ƒ  d ƒ } |  j j | ƒ |  j } |  j | } |  j | ƒ | k r] | } n\ t t | ƒ t | ƒ ƒ } d } x. | | k  r® | | | | k r® | d 7} q W| |  } |  j	 | ƒ |  j | t |  j
 ƒ  |  j
 k r|  j j d |  j d |  j ƒ n² |  j j d |  j j d ƒ d |  j j d ƒ ƒ |  j r½|  j |  _ d |  _ |  j j d t ƒ x$ |  j D] } |  j j t | ƒ qwW|  j j |  j |  j
 ƒ ƒ |  j ƒ  n  d S(   s|   Should be called when the selection of the Listbox has changed.
        Updates the Listbox display and calls _change_start.i    i   t   selectbackgroundt   selectforegroundt   bgt   fgN(   t   intR   t   curselectiont   seeR   R   R(   R   R   R$   R   t	   configureR   R
   t   cgetR   R   R   t   ENDR    t
   select_sett   _selection_changed(   R   t   curselt   ltst   selstartR!   R"   R#   t   item(    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyR9   q   s2    		#
#		c      
   C   s;  | \ |  _  |  _ | |  _ |  j j | ƒ |  _ |  j j |  j d ƒ |  _ | rÓ |  j |  j ƒ } |  j	 | ƒ |  j
 | ƒ } |  j  | | k rÓ | t |  j  ƒ d k sÌ |  j  | d t | ƒ  | k rÓ d Sn  | |  _ |  j |  _ t |  j ƒ |  _ } | j d ƒ | j d ƒ y# | j j d d | j d d ƒ Wn t k
 rNn Xt | d	 t ƒ|  _ }	 t | d
 |	 j d t d d ƒ|  _ }
 x! |  j  D] } |
 j t | ƒ qšW|
 j d ƒ |  _  |
 j d ƒ |  _! |	 j" d |
 j# ƒ |	 j$ d t% d t& ƒ |
 j$ d t' d t( d t) ƒ |  j j* |  j
 |  j ƒ ƒ |  j+ ƒ  |  j j, t- |  j. ƒ |  _/ x! t0 D] } |  j j1 t- | ƒ qeW|  j j, t2 |  j3 ƒ |  _4 x! t5 D] } |  j j1 t2 | ƒ q¤W|  j j, t6 |  j7 ƒ |  _8 |  j j1 t6 t9 ƒ |
 j, t: |  j; ƒ |  _< | j, t= |  j> ƒ |  _? |
 j, t@ |  jA ƒ |  _B d S(   s¤   Show 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    i   Ns   +10000+10000s!   ::tk::unsupported::MacWindowStylet   stylet   helpt   noActivatest   orientt   yscrollcommandt   exportselectionR0   t   whiteR/   R.   t   commandt   sidet   fillt   expand(C   R   R   R   R   t   indexR   t   getR   R-   R$   R(   R   R   R   t   ToplevelR   t   wm_geometryt   wm_overrideredirectt   tkt   callt   _wt   TclErrort	   Scrollbart   VERTICALR	   t   Listboxt   setR   R   R    R7   R6   R
   R   t   configt   yviewt   packt   RIGHTt   Yt   LEFTt   BOTHt   TrueR8   R9   t   bindt   HIDE_VIRTUAL_EVENT_NAMEt
   hide_eventR   t   HIDE_SEQUENCESt	   event_addt   KEYPRESS_VIRTUAL_EVENT_NAMEt   keypress_eventR   t   KEYPRESS_SEQUENCESt   KEYRELEASE_VIRTUAL_EVENT_NAMEt   keyrelease_eventR   t   KEYRELEASE_SEQUENCEt   LISTUPDATE_SEQUENCEt   listselect_eventR   t   WINCONFIG_SEQUENCEt   winconfig_eventR   t   DOUBLECLICK_SEQUENCEt   doubleclick_eventR   (   R   t
   comp_listsRI   t   completeR   t   userWantsWint	   completedR#   t   acwR	   R   R=   t   seq(    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyt   show_window•   sd    	!	
		c         C   s
  |  j  ƒ  s d  S|  j } | j |  j ƒ | j |  j ƒ \ } } } } |  j } | j ƒ  | j ƒ  } }	 | j ƒ  | j ƒ  }
 } | j ƒ  t	 | t
 d |
 | ƒ ƒ } | j ƒ  | } | | | |	 k sØ | |	 k  rå | | 7} n
 | |	 8} | j d | | f ƒ d  S(   Ni    s   +%d+%d(   t	   is_activeR   R4   R   t   bboxR   t   winfo_widtht   winfo_heightt   winfo_rootxR   t   maxt   winfo_rootyRL   (   R   t   eventt   textt   xt   yt   cxt   cyRs   t	   acw_widtht
   acw_heightt
   text_widtht   text_heightt   new_xt   new_y(    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyRl   Ù   s    		&
c         C   s   |  j  ƒ  s d  S|  j ƒ  d  S(   N(   Rv   t   hide_window(   R   R}   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyR`   î   s    c         C   sJ   |  j  ƒ  s d  St |  _ t |  j j ƒ  d ƒ } |  j |  j | ƒ d  S(   Ni    (   Rv   R]   R   R2   R   R3   R$   R   (   R   R}   R:   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyRj   ó   s
    	c         C   s;   t  |  j j ƒ  d ƒ } |  j |  j | ƒ |  j ƒ  d  S(   Ni    (   R2   R   R3   R$   R   R‰   (   R   R}   R:   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyRn   ú   s    c            sÃ  |  j  ƒ  s d  S| j ‰  t | d ƒ r4 | j } n d } ˆ  d k rR t |  _ n  t ˆ  ƒ d k s‹ ˆ  d% k s‹ |  j t k r¼ˆ  d& k r¼| t	 @r¼t ˆ  ƒ d k rÀ |  j
 |  j ˆ  ƒ n  ˆ  d k rã |  j
 |  j d	 ƒ n} ˆ  d k r|  j
 |  j d
 ƒ nZ ˆ  d k r)|  j
 |  j d ƒ n7 t |  j ƒ d k rL|  j ƒ  d  S|  j
 |  j d  ƒ |  j |  _ |  j j d t |  j j ƒ  d ƒ ƒ |  j j |  j |  j ƒ ƒ |  j ƒ  d Sˆ  d k rÖ|  j ƒ  d  S|  j t k rñˆ  d' k s|  j t k r‘ˆ  d( k r‘| t	 @r‘t |  j j ƒ  d ƒ } |  j | t |  j ƒ  |  j k rƒ|  j t k sl|  j rƒ|  j
 |  j | ƒ n  |  j ƒ  d  Sˆ  d) k r!| r!t |  _ t |  j j ƒ  d ƒ } ˆ  d k rÛd } nˆ  d k rýt |  j ƒ d } nâ ˆ  d* k r‹|  j j |  j j ƒ  ƒ |  j j d ƒ } ˆ  d k rVt d | | ƒ } qßˆ  d k sht ‚ t t |  j ƒ d | | ƒ } nT ˆ  d k r­t d | d ƒ } n2 ˆ  d k s¿t ‚ t t |  j ƒ d | d ƒ } |  j j | ƒ |  j j | ƒ |  j ƒ  |  j
 |  j | ƒ d Sˆ  d k r‘| r‘|  j rxt |  j j ƒ  d ƒ } |  j
 |  j | ƒ |  j ƒ  d St |  _ t |  _ d  Sn. t ‡  f d †  d+ Dƒ ƒ r±d  S|  j ƒ  d  Sd  S(,   Nt   mc_statei    t   Tabi   t
   underscoret	   BackSpacet   periodt   minust   _t   .t   -iÿÿÿÿt   breakt   Returnt   spacet	   parenleftt
   parenrightt   bracketleftt   bracketrightt   slasht	   backslasht   quotedblt
   apostrophet   Homet   Endt   Priort   Nextt   Upt   Downc         3   s   |  ] } | ˆ  k Vq d  S(   N(    (   t   .0R%   (   t   keysym(    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pys	   <genexpr>`  s    t   Shiftt   Controlt   Altt   Metat   Commandt   Option(   s
   underscores	   BackSpace(   s   periods   minus(   s   periods   spaces	   parenlefts
   parenrights   bracketlefts   bracketright(   s   slashs	   backslashRœ   R   (   s   Homes   Ends   Priors   Nexts   Ups   Down(   s   Priors   Next(   s   Shifts   Controls   Alts   Metas   Commands   Option(   Rv   R¥   t   hasattrRŠ   R   R   R   R   R   R   R$   R   R‰   R   R   t   select_clearR2   R3   R8   R(   R9   R   R   R]   R   t   nearestRy   R{   t   AssertionErrorR   t   any(   R   R}   t   stateR:   t   newselt   jump(    (   R¥   s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyRd      s¤    		
&

 		#
		# 
	
		
c         C   s[   |  j  ƒ  s d  S|  j j d ƒ |  j j d |  j t |  j ƒ f ƒ k rW |  j ƒ  n  d  S(   NR    s   %s+%dc(   Rv   R   RI   R   R   R   R‰   (   R   R}   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyRg   j  s
    +c         C   s   |  j  d  k	 S(   N(   R   R   (   R   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyRv   r  s    c         C   s   |  j  |  j |  j ƒ ƒ d  S(   N(   R$   R-   R   (   R   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyRp   u  s    c         C   sL  |  j  ƒ  s d  Sx! t D] } |  j j t | ƒ q W|  j j t |  j ƒ d  |  _ x! t D] } |  j j t	 | ƒ qZ W|  j j t	 |  j
 ƒ d  |  _
 |  j j t t ƒ |  j j t |  j ƒ d  |  _ |  j j t |  j ƒ d  |  _ |  j j t |  j ƒ d  |  _ |  j j ƒ  d  |  _ |  j j ƒ  d  |  _ |  j j ƒ  d  |  _ d  S(   N(   Rv   Ra   R   t   event_deleteR_   t   unbindR   R   Re   Rc   R   Rf   Rh   R   R   Ri   R   R   Rk   R   R	   t   destroy(   R   Rt   (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyR‰   y  s0    							(   t   __name__t
   __module__R   R$   R(   R-   R9   Ru   Rl   R`   Rj   Rn   Rd   Rg   Rv   Rp   R‰   (    (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyR      s   	 				$	D					j			N(   s
   <FocusOut>s   <ButtonPress>(
   s   <Key>s   <Key-BackSpace>s   <Key-Return>s	   <Key-Tab>s   <Key-Up>s
   <Key-Down>s
   <Key-Home>s	   <Key-End>s   <Key-Prior>s
   <Key-Next>(    (   t   __doc__t   Tkintert   idlelib.MultiCallR   t   idlelib.AutoCompleteR   R   R_   Ra   Rc   Re   Rf   Rh   Ri   Rk   Rm   R   (    (    (    s/   C:\RCS\Python\lib\idlelib\AutoCompleteWindow.pyt   <module>   s   
  