B
    v9a$  ã               @   sb   d dl mZ d dlmZ ddddœZdZG dd	„ d	ƒZe ¡  ed
kr^d dl	m
Z
 e
ddd dS )é    )ÚHyperParser)ÚidleConfú(ú[ú{)ú)ú]ú}éd   c               @   s˜   e Zd ZdZdZdd„ Zedd„ ƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zd!dd„Zdd„ Zdd„ Zdd„ Zdd„ ZeeeedœZdd„ Zdd „ ZdS )"Ú
ParenMatchz<<parenmatch-check-restore>>)z
<KeyPress>z<ButtonPress>z<Key-Return>z<Key-BackSpace>c             C   s0   || _ |j| _|j | j| j¡ d| _d| _d S )Nr   )ÚeditwinÚtextZbindÚRESTORE_VIRTUAL_EVENT_NAMEÚrestore_eventÚcounterÚis_restore_active)Úselfr   © r   ú /usr/lib/python3.7/parenmatch.pyÚ__init__(   s    
zParenMatch.__init__c             C   sV   t jddddd| _t jdddddd	| _t jddd
ddd	| _t  t  ¡ d¡| _d S )NÚ
extensionsr   ZstyleÚopener)Údefaultzflash-delayÚintiô  )Útyper   ÚbellÚboolé   Zhilite)r   Z	GetOptionÚSTYLEÚFLASH_DELAYÚBELLZGetHighlightZCurrentThemeÚHILITE_CONFIG)Úclsr   r   r   Úreload3   s    
zParenMatch.reloadc             C   s0   | j s,x| jD ]}| j | j|¡ qW d| _ d S )NT)r   ÚRESTORE_SEQUENCESr   Z	event_addr   )r   Úseqr   r   r   Úactivate_restore>   s    zParenMatch.activate_restorec             C   s0   | j r,x| jD ]}| j | j|¡ qW d| _ d S )NF)r   r$   r   Zevent_deleter   )r   r%   r   r   r   Údeactivate_restoreE   s    zParenMatch.deactivate_restorec             C   s   t | jdƒ ¡ }|  |¡ dS )NÚinsertÚbreak)r   r   Úget_surrounding_bracketsÚfinish_paren_event)r   ÚeventÚindicesr   r   r   Úflash_paren_eventL   s    
zParenMatch.flash_paren_eventc             C   sN   | j  d¡}|tkrd S t| jdƒ}| ¡ s0d S | t| d¡}|  |¡ d S )Nz	insert-1cT)r   ÚgetÚ_openersr   r   Z
is_in_coder*   r+   )r   r,   ZcloserZhpr-   r   r   r   Úparen_closed_eventS   s    
zParenMatch.paren_closed_eventc             C   sT   |d kr| j r| j ¡  d S |  ¡  | j | j| j¡| |ƒ | jrH| j	n| j
ƒ  d S )N)r    r   r   r&   Útagfuncsr/   r   Úcreate_tag_expressionr   Úset_timeout_lastÚset_timeout_none)r   r-   r   r   r   r+   `   s    
zParenMatch.finish_paren_eventNc             C   s&   | j  d¡ |  ¡  |  jd7  _d S )NÚparenr   )r   Z
tag_deleter'   r   )r   r,   r   r   r   r   k   s    zParenMatch.restore_eventc             C   s   || j kr|  ¡  d S )N)r   r   )r   Ztimer_countr   r   r   Úhandle_restore_timerq   s    
zParenMatch.handle_restore_timerc             C   s&   | j  d|d ¡ | j  d| j¡ d S )Nr6   r   )r   Útag_addÚ
tag_configr!   )r   r-   r   r   r   Úcreate_tag_openerx   s    zParenMatch.create_tag_openerc             C   sb   | j  |d ¡dkr"|d d }n|d }| j  d|d |d d |d |¡ | j  d| j¡ d S )Nr   )r   r   r	   z+1cr6   r   z-1c)r   r/   r8   r9   r!   )r   r-   Ú
rightindexr   r   r   Úcreate_tag_parens}   s
    $zParenMatch.create_tag_parensc             C   sR   | j  |d ¡dkr"|d d }n|d }| j  d|d |¡ | j  d| j¡ d S )Nr   )r   r   r	   z+1cr6   r   )r   r/   r8   r9   r!   )r   r-   r;   r   r   r   r3   †   s
    z ParenMatch.create_tag_expression)r   r   ZparensZ
expressionc             C   s>   |  j d7  _ | | j | j d¡fdd„}| jj t||¡ d S )Nr   r(   c             S   s2   ||j  d¡kr| |¡ n|jj t| | ¡ d S )Nr(   )r   Úindexr7   r   Ú
text_frameÚafterÚCHECK_DELAY)Úcallmer   Úcr=   r   r   r   rA       s    z+ParenMatch.set_timeout_none.<locals>.callme)r   r   r=   r   r>   r?   r@   )r   rA   r   r   r   r5   ™   s    zParenMatch.set_timeout_nonec             C   s0   |  j d7  _ | jj | j| | j fdd„¡ d S )Nr   c             S   s
   |   |¡S )N)r7   )r   rB   r   r   r   Ú<lambda>¯   ó    z-ParenMatch.set_timeout_last.<locals>.<lambda>)r   r   r>   r?   r   )r   r   r   r   r4   ¨   s    zParenMatch.set_timeout_last)N)Ú__name__Ú
__module__Ú__qualname__r   r$   r   Úclassmethodr#   r&   r'   r.   r1   r+   r   r7   r:   r<   r3   r2   r5   r4   r   r   r   r   r      s(   
	
r   Ú__main__)Úmainz!idlelib.idle_test.test_parenmatché   )Ú	verbosityN)Zidlelib.hyperparserr   Zidlelib.configr   r0   r@   r   r#   rE   ZunittestrJ   r   r   r   r   Ú<module>   s    &