o
     JAf$                     @   sh   	 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r2d dl	m
Z
 e
ddd dS 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textbindRESTORE_VIRTUAL_EVENT_NAMErestore_eventcounteris_restore_active)selfr    r   )/usr/lib/python3.10/idlelib/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   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   s2   	 | j s| jD ]
}| j| j| qd| _ d S d S )NT)r   RESTORE_SEQUENCESr   Z	event_addr   r   seqr   r   r   activate_restore>      

zParenMatch.activate_restorec                 C   s2   	 | j r| jD ]
}| j| j| qd| _ d S d S )NF)r   r'   r   Zevent_deleter   r(   r   r   r   deactivate_restoreE   r+   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   sP   	 | j d}|tvrd S t| jd}| sd S |t| d}| | d S )Nz	insert-1cT)r   get_openersr   r   Z
is_in_coder/   r0   )r   r1   ZcloserZhpr2   r   r   r   paren_closed_eventS   s   
zParenMatch.paren_closed_eventc                 C   sZ   |d u r| j r| j  d S |   | j| j| j| | | jr'| j	  d S | j
  d S N)r#   r   r   r*   tagfuncsr4   r!   create_tag_expressionr"   set_timeout_lastset_timeout_noner   r2   r   r   r   r0   `   s   
zParenMatch.finish_paren_eventNc                 C   s(   	 | j d |   |  jd7  _d S )Nparenr    )r   Z
tag_deleter,   r   )r   r1   r   r   r   r   k   s   zParenMatch.restore_eventc                 C   s   || j kr|   d S d S r7   )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 )Nr=   r   )r   tag_add
tag_configr$   r<   r   r   r   create_tag_openerx   s   zParenMatch.create_tag_openerc                 C   sd   	 | j |d dv r|d d }n|d }| j d|d |d d |d | | j d| j d S )Nr    r   +1cr=   r   z-1cr   r4   r?   r@   r$   r   r2   Z
rightindexr   r   r   create_tag_parens}   s   $zParenMatch.create_tag_parensc                 C   sT   	 | j |d dv r|d d }n|d }| j d|d | | j d| j d S )Nr    r   rB   r=   r   rC   rD   r   r   r   r9      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   s4   ||j dkr|| d S |jjt| |  d S )Nr-   )r   indexr>   r   
text_frameafterCHECK_DELAY)callmer   crF   r   r   r   rJ      s   z+ParenMatch.set_timeout_none.<locals>.callme)r   r   rF   r   rG   rH   rI   )r   rJ   r   r   r   r;      s   

zParenMatch.set_timeout_nonec                 C   s2   	 |  j d7  _ | jj| j| | j fdd d S )Nr    c                 S   s
   |  |S r7   )r>   )r   rK   r   r   r   <lambda>   s   
 z-ParenMatch.set_timeout_last.<locals>.<lambda>)r   r   rG   rH   r"   )r   r   r   r   r:      s   zParenMatch.set_timeout_lastr7   )__name__
__module____qualname__r   r'   r   classmethodr&   r*   r,   r3   r6   r0   r   r>   rA   rE   r9   r8   r;   r:   r   r   r   r   r      s0    


	

r   __main__)mainz!idlelib.idle_test.test_parenmatch   )	verbosityN)Zidlelib.hyperparserr   Zidlelib.configr   r5   rI   r   r&   rM   ZunittestrR   r   r   r   r   <module>   s     &