
    d$                         d Z ddlmZ ddlmZ ddddZdZ G d	 d
          Ze                                 e	dk    rddl
mZ  edd           dS dS )zParenMatch -- 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.
    )HyperParser)idleConf([{)]}d   c                       e Zd ZdZdZdZd Zed             Zd Z	d Z
d Zd	 Zd
 ZddZd Zd Zd Zd ZeeeedZd Zd ZdS )
ParenMatcha'  Highlight matching openers and closers, (), [], and {}.

    There are three supported styles of paren matching.  When a right
    paren (opener) is typed:

    opener -- highlight the matching left paren (closer);
    parens -- highlight the left and right parens (opener and closer);
    expression -- highlight the entire expression from opener to closer.
    (For back compatibility, 'default' is a synonym for 'opener').

    Flash-delay is the maximum milliseconds the highlighting remains.
    Any cursor movement (key press or click) before that removes the
    highlight.  If flash-delay is 0, there is no maximum.

    TODO:
    - Augment bell() with mismatch warning in status window.
    - Highlight when cursor is moved to the right of a closer.
      This might be too expensive to check.
    z<<parenmatch-check-restore>>)z
<KeyPress>z<ButtonPress>z<Key-Return>z<Key-BackSpace>c                     || _         |j        | _        |j                            | j        | j                   d| _        d| _        d S )Nr   )editwintextbindRESTORE_VIRTUAL_EVENT_NAMErestore_eventcounteris_restore_active)selfr   s     $  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/idlelib/parenmatch.py__init__zParenMatch.__init__(   sN    L	 	$9,	. 	. 	.!"    c                    t          j        dddd          | _        t          j        ddddd	          | _        t          j        ddd
dd	          | _        t          j        t          j                    d          | _        d S )N
extensionsr   styleopener)defaultzflash-delayinti  )typer   bellbool   hilite)r   	GetOptionSTYLEFLASH_DELAYBELLGetHighlightCurrentThemeHILITE_CONFIG)clss    r   reloadzParenMatch.reload3   s    &gxA A A	",\-eCQ Q Q%\&vqJ J J$1(2G2I2I2:< <r   c                 z    | j         s3| j        D ]"}| j                            | j        |           #d| _         dS dS )z5Activate mechanism to restore text from highlighting.TN)r   RESTORE_SEQUENCESr   	event_addr   r   seqs     r   activate_restorezParenMatch.activate_restore>   sW    % 	*- J J	##D$CSIIII%)D"""	* 	*r   c                 z    | j         r3| j        D ]"}| j                            | j        |           #d| _         dS dS )zRemove restore event bindings.FN)r   r0   r   event_deleter   r2   s     r   deactivate_restorezParenMatch.deactivate_restoreE   sW    ! 	+- M M	&&t'FLLLL%*D"""	+ 	+r   c                 ~    t          | j        d                                          }|                     |           dS )zAHandle editor 'show surrounding parens' event (menu or shortcut).insertbreak)r   r   get_surrounding_bracketsfinish_paren_event)r   eventindicess      r   flash_paren_eventzParenMatch.flash_paren_eventL   s;    t|X66,,.. 	(((wr   c                    | j                             d          }|t          vrdS t          | j        d          }|                                sdS |                    t          |         d          }|                     |           dS )zHandle user input of closer.z	insert-1cNT)r   get_openersr   r   
is_in_coder;   r<   )r   r=   closerhpr>   s        r   paren_closed_eventzParenMatch.paren_closed_eventS   s     {++!!F{33}} 	F--hv.>EE(((r   c                    |"| j         r| j                                         d S |                                   | j                            | j        | j                  | |            | j        r| j	        n| j
                     d S N)r)   r   r"   r4   tagfuncsrA   r'   create_tag_expressionr(   set_timeout_lastset_timeout_noner   r>   s     r   r<   zParenMatch.finish_paren_event`   s    ?ty?INNFA$*d&@AA$PPP
2$"2 
2		 1	5 	5 	5 	5 	5r   Nc                     | j                             d           |                                  | xj        dz  c_        dS )zRemove effect of doing match.parenr$   N)r   
tag_deleter7   r   )r   r=   s     r   r   zParenMatch.restore_eventk   s>    	W%%%!!!r   c                 H    || j         k    r|                                  d S d S rH   )r   r   )r   timer_counts     r   handle_restore_timerzParenMatch.handle_restore_timerq   s/    $,&&      '&r   c                     | j                             d|d                    | j                             d| j                   dS )z'Highlight the single paren that matchesrO   r   N)r   tag_add
tag_configr,   rM   s     r   create_tag_openerzParenMatch.create_tag_openerx   s?    	'71:...	Wd&899999r   c                    | j                             |d                   dv r|d         dz   }n|d         }| j                             d|d         |d         dz   |dz   |           | j                             d| j                   dS )z#Highlight the left and right parensr$   r   +1crO   r   z-1cNr   rA   rU   rV   r,   r   r>   
rightindexs      r   create_tag_parenszParenMatch.create_tag_parens}   s    9==$$77 E)JJ J	'71:wqz%/?EAQS]^^^	Wd&899999r   c                     | j                             |d                   dv r|d         dz   }n|d         }| j                             d|d         |           | j                             d| j                   dS )zHighlight the entire expressionr$   r   rY   rO   r   NrZ   r[   s      r   rJ   z ParenMatch.create_tag_expression   sw    9==$$77 E)JJ J	'71:z:::	Wd&899999r   )r   r   parens
expressionc                     | xj         dz  c_         | | j         | j                            d          fd}| j        j                            t          ||           dS )zSHighlight will remain until user input turns it off
        or the insert has movedr$   r9   c                     ||j                             d          k    r|                    |           d S |j        j                            t          | |            d S )Nr9   )r   indexrS   r   
text_frameafterCHECK_DELAY)callmer   crc   s       r   rg   z+ParenMatch.set_timeout_none.<locals>.callme   sX    	1111))!,,,,,'--k66JJJJJr   N)r   r   rc   r   rd   re   rf   )r   rg   s     r   rL   zParenMatch.set_timeout_none   si     	 $22	K 	K 	K 	K 	%%k66BBBBBr   c                     | xj         dz  c_         | j        j                            | j        | | j         fd           dS )zFThe last highlight created will be removed after FLASH_DELAY millisecsr$   c                 ,    |                      |          S rH   )rS   )r   rh   s     r   <lambda>z-ParenMatch.set_timeout_last.<locals>.<lambda>   s    d.G.G.J.J r   N)r   r   rd   re   r(   )r   s    r   rK   zParenMatch.set_timeout_last   sV     	%%JJJ	L 	L 	L 	L 	Lr   rH   )__name__
__module____qualname____doc__r   r0   r   classmethodr.   r4   r7   r?   rF   r<   r   rS   rW   r]   rJ   rI   rL   rK    r   r   r   r      s4        ( "@<	# 	# 	# < < [<* * *+ + +    	5 	5 	5   ! ! !: : :
: : :: : : $$#+	
 
HC C CL L L L Lr   r   __main__)mainz!idlelib.idle_test.test_parenmatch   )	verbosityN)ro   idlelib.hyperparserr   idlelib.configr   rB   rf   r   r.   rl   unittestrs   rq   r   r   <module>ry      s     , + + + + + # # # # # #$$bL bL bL bL bL bL bL bLJ       zD	,:::::: r   