mò
­fIc           @   sž   d  Z  d k Z d k l Z d k l Z d k Z e d d d d d d	 d
 d d d g
 ƒ Z d d >Z d Z	 d Z
 e i d ƒ d „ Z d f  d „  ƒ  YZ d S(   sF  CodeContext - Display the block context of code at top of edit window

Once code has scrolled off the top of the screen, it can be difficult
to determine which block you are in.  This extension implements a pane
at the top of each IDLE edit window which provides block structure
hints.  These hints are the lines which contain the block opening
keywords, e.g. 'if', for the enclosing block.  The number of hint lines
is determined by the numlines variable in the CodeContext section of
config-extensions.def. Lines which do not open blocks are not shown in
the context hints pane.

N(   s   idleConf(   s   Sett   classt   deft   elift   elset   exceptt   finallyt   fort   ift   tryt   whilei   i   id   iè  s   ^(\s*)(\w*)c         C   s   | i |  ƒ i ƒ  S(   N(   t   ct   matcht   st   groups(   R   R
   (    (    t0   /mit/python/lib/python2.4/idlelib/CodeContext.pyt   <lambda>   s    t   CodeContextc           B   s¿   t  Z d d g f g Z e i d d d d d d	 d
 ƒZ e i d d d d d d	 d ƒZ e i d d d d d d	 d ƒZ d „  Z d  d „ Z
 d „  Z d „  Z d „  Z d „  Z d „  Z RS(   Nt   optionss   !Code Conte_xts   <<toggle-code-context>>t
   extensionsR   t   numlinest   typet   intt   defaulti   t   bgcolort   strt	   LightGrayt   fgcolort   Blackc         C   sÈ   | |  _  | i |  _ |  i d |  _ d  |  _ t |  i d ƒ ƒ |  _ d |  _	 t
 i d d d d d d t ƒ} | o! |  i ƒ  |  i  i d	 t ƒ n |  i i t |  i ƒ |  i i t |  i ƒ d  S(
   Nt   fonti   R   R   t   visibleR   t   boolR   s   <<toggle-code-context>>(   t   editwint   selft   textt   textfontt   Nonet   labelt   listt   interesting_linest   infot   lastfirstlinet   idleConft	   GetOptiont   FalseR   t   toggle_code_context_eventt   setvart   Truet   aftert   UPDATEINTERVALt   timer_eventt   FONTUPDATEINTERVALt   font_timer_event(   R    R   R   (    (    R   t   __init__#   s    			
c         C   sÞ   |  i p‹ t i |  i i d d |  i d d d d d d |  i d	 |  i d
 |  i	 d d d d ƒ|  _ |  i i
 d d d d d d d |  i i ƒ n |  i i ƒ  d  |  _ t i d d d t |  i d  j	 ƒ ƒ t i ƒ  d  S(   NR!   s   
i   t   anchort   wt   justifyt   leftR   t   bgt   fgt   relieft   sunkent   widtht   sidet   topt   fillt   xt   expandi    R/   R   R   R   (   R    R$   t   Tkintert   LabelR   R?   R   R"   R   R   t   packt
   status_bart   destroyR#   R)   t	   SetOptionR   t   SaveUserCfgFiles(   R    t   event(    (    R   R,   4   s    
		c         C   s³   | d j o d d t f Sn |  i i d | d | ƒ } t | ƒ \ } } | t j o | } t
 | ƒ t
 | ƒ j p | t
 | ƒ d j o
 t } n t
 | ƒ } | | | f S(   s‹  Get the line indent value, text, and any block start keyword

        If the line does not start a block, the keyword value is False.
        The indentation of empty lines (or comment lines) is INFINITY.
        There is a dummy block start, with indentation -1 and text "".

        Return the indent level, text (including leading whitespace),
        and the block opening keyword.

        i    iÿÿÿÿt    s   %d.0s   %d.endt   #N(   t   linenumR.   R    R!   t   gett   getspacesfirstwordt   spacest	   firstwordt   BLOCKOPENERSt   openert   lent   INFINITYt   indent(   R    RM   RV   R!   RP   RS   RQ   (    (    R   t   get_line_infoG   s    
 0
c         c   s“   t  } x† t | d d ƒ D]r } |  i | ƒ \ } } } | | j  oG | } | d j o | d 7} n | o | | j  o | | f Vq‹ q q Wd S(   s<   Generator which yields context lines, starting at firstline.iÿÿÿÿR   R   i   N(   R   R   (
   RU   t
   lastindentt   xranget	   firstlinet
   line_indexR    RW   RV   R!   RS   (   R    RZ   RX   R[   RS   R!   RV   (    (    R   R&   ]   s      c         C   sY  t  |  i i d ƒ i d ƒ d ƒ } |  i | j o d  Sn | |  _ g  } xw |  i | ƒ D]f \ } } x' |  i
 d d | j o |  i
 d =qk W|  i
 d d | j o Pn | i | | f ƒ q\ Wx" | o |  i
 i | i ƒ  ƒ qÉ Wd g t d |  i t |  i
 ƒ ƒ g  } |  i
 |  i D] } | | d q$~ } d i | ƒ |  i d <d  S(	   Ns   @0,0t   .i    iÿÿÿÿRK   i   s   
R!   (   R   R    R!   t   indext   splitRZ   R(   t   tmpstackR&   R[   R'   t   appendt   popt   maxR   RT   t   _[1]RA   t   linest   joinR$   (   R    RZ   R_   Rd   R[   Rc   R!   RA   (    (    R   t   update_labelm   s$    %	   Tc         C   s2   |  i o |  i ƒ  n |  i i t |  i ƒ d  S(   N(   R    R$   Rf   R!   R/   R0   R1   (   R    (    (    R   R1      s    
c         C   s^   |  i d } |  i o- | |  i j o | |  _ |  i |  i d <n |  i i t |  i ƒ d  S(   NR   (   R    R!   t   newtextfontR$   R"   R/   R2   R3   (   R    Rg   (    (    R   R3   †   s
    	(   s   !Code Conte_xts   <<toggle-code-context>>(   t   __name__t
   __module__t   menudefsR)   R*   R   R   R   R4   R#   R,   RW   R&   Rf   R1   R3   (    (    (    R   R      s   					(   t   __doc__RC   t   configHandlerR)   t   setst   Sett   reRR   RU   R0   R2   t   compileRO   R   (
   Rn   RC   RR   RO   R)   Ro   RU   R0   R2   R   (    (    R   t   ?   s   		*
