ó
|Nc           @   s^   d  Z  d d l m Z d d l m Z i d d 6d d 6d d	 6Z 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 j d d d d d ƒZ e j d d d	 d
 d d d ƒZ e j e j	 ƒ  d ƒ Z
 e j 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   | |  _  | j |  _ | j j |  j |  j ƒ d |  _ d |  _ |  j |  j ƒ d  S(   Ni    (	   t   editwint   textt   bindt   RESTORE_VIRTUAL_EVENT_NAMEt   restore_eventt   countert   is_restore_activet	   set_stylet   STYLE(   t   selfR   (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyt   __init__;   s    	
		c         C   sC   |  j  s? x' |  j D] } |  j j |  j | ƒ q Wt |  _  n  d  S(   N(   R   t   RESTORE_SEQUENCESR   t	   event_addR   t   True(   R   t   seq(    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyt   activate_restoreG   s    	c         C   sC   |  j  r? x' |  j D] } |  j j |  j | ƒ q Wt |  _  n  d  S(   N(   R   R   R   t   event_deleteR   t   False(   R   R!   (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyt   deactivate_restoreM   s    	c         C   s[   | |  _  | d k r0 |  j |  _ |  j |  _ n' | d k rW |  j |  _ |  j |  _ 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'   C:\RCS\Python\lib\idlelib\ParenMatch.pyR   S   s    	c         C   sW   t  |  j d ƒ j ƒ  } | d  k r2 |  j ƒ  d  S|  j ƒ  |  j | ƒ |  j ƒ  d  S(   Nt   insert(   R    R   t   get_surrounding_bracketst   Nonet   warn_mismatchedR"   R'   R(   (   R   t   eventt   indices(    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyt   flash_paren_event\   s    

c         C   s™   |  j  j d ƒ } | t k r" d  St |  j d ƒ } | j ƒ  sD d  S| j t | t ƒ } | d  k rt |  j	 ƒ  d  S|  j
 ƒ  |  j | ƒ |  j ƒ  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'   C:\RCS\Python\lib\idlelib\ParenMatch.pyt   paren_closed_evente   s    

c         C   s-   |  j  j d ƒ |  j ƒ  |  j d 7_ d  S(   Nt   pareni   (   R   t
   tag_deleteR%   R   (   R   R0   (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyR   u   s    
c         C   s    | |  j  k r |  j ƒ  n  d  S(   N(   R   R   (   R   t   timer_count(    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyt   handle_restore_timerz   s    c         C   s   |  j  r |  j j ƒ  n  d  S(   N(   t   BELLR   R   (   R   (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyR/   ~   s    	c         C   s1   |  j  j d | d ƒ |  j  j d |  j ƒ d S(   s'   Highlight the single paren that matchesR9   i    N(   R   t   tag_addt
   tag_configt   HILITE_CONFIG(   R   R1   (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyR&   …   s    c         C   sk   |  j  j | d ƒ d	 k r- | d d } n
 | d } |  j  j d | d | ƒ |  j  j d |  j ƒ 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'   C:\RCS\Python\lib\idlelib\ParenMatch.pyR*   Š   s
    
c         C   sM   |  j  d 7_  |  |  j  |  j j d ƒ d „ } |  j j j t | | ƒ d S(   sS   Highlight will remain until user input turns it off
        or the insert has movedi   R,   c         S   sE   | | j  j d ƒ k r( | j | ƒ n | j j j t |  |  ƒ d  S(   NR,   (   R   t   indexR<   R   t
   text_framet   aftert   CHECK_DELAY(   t   callmeR   t   cRB   (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyRF      s    N(   R   R   RB   R   RC   RD   RE   (   R   RF   (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyR+   –   s    	c         C   s8   |  j  d 7_  |  j j j |  j |  |  j  d „ ƒ d S(   s7   The last highlight created will be removed after .5 seci   c         S   s   |  j  | ƒ S(   N(   R<   (   R   RG   (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyt   <lambda>«   s    N(   R   R   RC   RD   t   FLASH_DELAY(   R   (    (    s'   C:\RCS\Python\lib\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'   C:\RCS\Python\lib\idlelib\ParenMatch.pyR      s4   	 													N(    (   RL   t   idlelib.HyperParserR    t   idlelib.configHandlerR   R4   RE   R   (    (    (    s'   C:\RCS\Python\lib\idlelib\ParenMatch.pyt   <module>   s
   