³ò
ž›\Kc           @   sd   d  Z  d d k l Z d d k l Z h  d d <d d <d d	 <Z d
 Z d d d „  ƒ  YZ d S(   sò   ParenMatch -- An IDLE extension for parenthesis matching.

When you hit a right paren, the cursor should move briefly to the left
paren.  Paren here is used generically; the matching applies to
parentheses, square brackets, and curly braces.
iÿÿÿÿ(   t   HyperParser(   t   idleConft   (t   )t   [t   ]t   {t   }id   t
   ParenMatchc           B   s  e  Z d  Z d d# g f g Z e i d d d d d ƒZ e i d d d	 d
 d d d ƒZ e i e i	 ƒ  d ƒ Z
 e i d d d d
 d d d ƒZ d Z d$ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d% d „ Z d „  Z d „  Z d „  Z d  „  Z d! „  Z d" „  Z RS(&   s¤  Highlight matching parentheses

    There are three supported style of paren matching, based loosely
    on the Emacs options.  The style is select based on the
    HILITE_STYLE attribute; it can be changed used the set_style
    method.

    The supported styles are:

    default -- When a right paren is typed, highlight the matching
        left paren for 1/2 sec.

    expression -- When a right paren is typed, highlight the entire
        expression from the left paren to the right paren.

    TODO:
        - extend IDLE with configuration dialog to change options
        - implement rest of Emacs highlight styles (see below)
        - print mismatch warning in IDLE status window

    Note: In Emacs, there are several styles of highlight where the
    matching paren is highlighted whenever the cursor is immediately
    to the right of a right paren.  I don't know how to do that in Tk,
    so I haven't bothered.
    t   edits   Show surrounding parenss   <<flash-paren>>t
   extensionsR   t   stylet   defaultt
   expressions   flash-delayt   typet   intiô  t   hilitet   bellt   booli   s   <<parenmatch-check-restore>>s
   <KeyPress>s   <ButtonPress>s   <Key-Return>s   <Key-BackSpace>c         C   sT   | |  _  | i |  _ | i i |  i |  i ƒ d |  _ d |  _ |  i |  i ƒ d  S(   Ni    (	   t   editwint   textt   bindt   RESTORE_VIRTUAL_EVENT_NAMEt   restore_eventt   countert   is_restore_activet	   set_stylet   STYLE(   t   selfR   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyt   __init__;   s    	
		c         C   sE   |  i  p7 x' |  i D] } |  i i |  i | ƒ q Wt |  _  n d  S(   N(   R   t   RESTORE_SEQUENCESR   t	   event_addR   t   True(   R   t   seq(    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyt   activate_restoreG   s
    

 c         C   sE   |  i  o7 x' |  i D] } |  i i |  i | ƒ q Wt |  _  n d  S(   N(   R   R   R   t   event_deleteR   t   False(   R   R!   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyt   deactivate_restoreM   s
    

 c         C   s_   | |  _  | d j o |  i |  _ |  i |  _ n* | d j o |  i |  _ |  i |  _ n d  S(   NR   R   (   R   t   create_tag_defaultt
   create_tagt   set_timeout_lastt   set_timeoutt   create_tag_expressiont   set_timeout_none(   R   R   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyR   S   s    	c         C   s\   t  |  i d ƒ i ƒ  } | d  j o |  i ƒ  d  Sn |  i ƒ  |  i | ƒ |  i ƒ  d  S(   Nt   insert(   R    R   t   get_surrounding_bracketst   Nonet   warn_mismatchedR"   R'   R(   (   R   t   eventt   indices(    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyt   flash_paren_event\   s    

c         C   s¨   |  i  i d ƒ } | t j o d  Sn t |  i d ƒ } | i ƒ  p d  Sn | i t | t ƒ } | d  j o |  i	 ƒ  d  Sn |  i
 ƒ  |  i | ƒ |  i ƒ  d  S(   Ns	   insert-1c(   R   t   gett   _openersR    R   t
   is_in_codeR-   R    R.   R/   R"   R'   R)   (   R   R0   t   closert   hpR1   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyt   paren_closed_evente   s    

c         C   s-   |  i  i d ƒ |  i ƒ  |  i d 7_ d  S(   Nt   pareni   (   R   t
   tag_deleteR%   R   (   R   R0   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyR   u   s    
c         C   s"   | |  i  j o |  i ƒ  n d  S(   N(   R   R   (   R   t   timer_count(    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyt   handle_restore_timerz   s    c         C   s   |  i  o |  i i ƒ  n d  S(   N(   t   BELLR   R   (   R   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyR/   ~   s    
c         C   s1   |  i  i d | d ƒ |  i  i d |  i ƒ d S(   s'   Highlight the single paren that matchesR9   i    N(   R   t   tag_addt
   tag_configt   HILITE_CONFIG(   R   R1   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyR&   …   s    c         C   sm   |  i  i | d ƒ d	 j o | d d } n | d } |  i  i d | d | ƒ |  i  i d |  i ƒ d S(
   s   Highlight the entire expressioni   R   R   R   s   +1cR9   i    N(   R   R   R   (   R   R3   R>   R?   R@   (   R   R1   t
   rightindex(    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyR*   Š   s
    
c         C   sM   |  i  d 7_  |  |  i  |  i i d ƒ d „ } |  i i i t | | ƒ d S(   sS   Highlight will remain until user input turns it off
        or the insert has movedi   R,   c         S   sG   | | i  i d ƒ j o | i | ƒ n | i i i t |  |  ƒ d  S(   NR,   (   R   t   indexR<   R   t
   text_framet   aftert   CHECK_DELAY(   t   callmeR   t   cRB   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyRF      s    N(   R   R   RB   R   RC   RD   RE   (   R   RF   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyR+   –   s    	c         C   s8   |  i  d 7_  |  i i i |  i |  |  i  d „ ƒ d S(   s7   The last highlight created will be removed after .5 seci   c         S   s   |  i  | ƒ S(    (   R<   (   R   RG   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyt   <lambda>«   s    N(   R   R   RC   RD   t   FLASH_DELAY(   R   (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyR(   ¥   s    (   s   Show surrounding parenss   <<flash-paren>>(   s
   <KeyPress>s   <ButtonPress>s   <Key-Return>s   <Key-BackSpace>N(   t   __name__t
   __module__t   __doc__t   menudefsR   t	   GetOptionR   RI   t   GetHighlightt   CurrentThemeR@   R=   R   R   R   R"   R%   R   R2   R8   R.   R   R<   R/   R&   R*   R+   R(   (    (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pyR      s4   	 													N(    (   RL   R    t   configHandlerR   R4   RE   R   (    (    (    s(   /usr/lib/python2.5/idlelib/ParenMatch.pys   <module>   s
   !