o =?h$@sjdZddlmZddlmZddddZdZGd d d Zee d kr3dd l m Z e d dddSdS)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([{)]}dc@seZdZdZdZdZddZeddZdd Z d d Z d d Z ddZ ddZ d"ddZddZddZddZddZeeeedZddZd d!ZdS)# 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<>)z z z zcCs0||_|j|_|j|j|jd|_d|_dS)Nr)editwintextZbindRESTORE_VIRTUAL_EVENT_NAME restore_eventcounteris_restore_active)selfr r9/opt/alt/python310/lib64/python3.10/idlelib/parenmatch.py__init__(s  zParenMatch.__init__cCsVtjddddd|_tjdddddd |_tjddd d d d |_ttd |_dS)N extensionsr Zstyleopener)defaultz flash-delayinti)typerbellboolZhilite)rZ GetOptionSTYLE FLASH_DELAYBELLZ GetHighlightZ CurrentTheme HILITE_CONFIG)clsrrrreload3s    zParenMatch.reloadcCs0|js|jD] }|j|j|qd|_dSdS)z5Activate mechanism to restore text from highlighting.TN)rRESTORE_SEQUENCESrZ event_addrrseqrrractivate_restore>   zParenMatch.activate_restorecCs0|jr|jD] }|j|j|qd|_dSdS)zRemove restore event bindings.FN)rr%rZ event_deleterr&rrrdeactivate_restoreEr)zParenMatch.deactivate_restorecCst|jd}||dS)zAHandle editor 'show surrounding parens' event (menu or shortcut).insertbreak)rr get_surrounding_bracketsfinish_paren_event)reventindicesrrrflash_paren_eventLs  zParenMatch.flash_paren_eventcCsN|jd}|tvr dSt|jd}|sdS|t|d}||dS)zHandle user input of closer.z insert-1cNT)rget_openersrr Z is_in_coder-r.)rr/ZcloserZhpr0rrrparen_closed_eventSs   zParenMatch.paren_closed_eventcCsZ|dur|jr|jdS||j|j|j|||jr'|j dS|j dSN) r!rrr(tagfuncsr2rcreate_tag_expressionr set_timeout_lastset_timeout_nonerr0rrrr.`s zParenMatch.finish_paren_eventNcCs&|jd||jd7_dS)zRemove effect of doing match.parenrN)rZ tag_deleter*r)rr/rrrrks zParenMatch.restore_eventcCs||jkr |dSdSr5)rr)rZ timer_countrrrhandle_restore_timerqs  zParenMatch.handle_restore_timercCs&|jd|d|jd|jdS)z'Highlight the single paren that matchesr;rN)rtag_add tag_configr"r:rrrcreate_tag_openerxszParenMatch.create_tag_openercCsb|j|ddvr|dd}n|d}|jd|d|dd|d||jd|jdS)z#Highlight the left and right parensrr+1cr;rz-1cNrr2r=r>r"rr0Z rightindexrrrcreate_tag_parens}s $zParenMatch.create_tag_parenscCsR|j|ddvr|dd}n|d}|jd|d||jd|jdS)zHighlight the entire expressionrrr@r;rNrArBrrrr7s z ParenMatch.create_tag_expression)rrZparensZ expressioncCs>|jd7_||j|jdfdd}|jjt||dS)zSHighlight will remain until user input turns it off or the insert has movedrr+cSs4||jdkr||dS|jjt||dS)Nr+)rindexr<r text_frameafter CHECK_DELAY)callmercrDrrrrHsz+ParenMatch.set_timeout_none..callmeN)rrrDr rErFrG)rrHrrrr9s   zParenMatch.set_timeout_nonecCs0|jd7_|jj|j||jfdddS)zFThe last highlight created will be removed after FLASH_DELAY millisecsrcSs ||Sr5)r<)rrIrrrs z-ParenMatch.set_timeout_last..N)rr rErFr )rrrrr8s zParenMatch.set_timeout_lastr5)__name__ __module__ __qualname____doc__rr%r classmethodr$r(r*r1r4r.rr<r?rCr7r6r9r8rrrrr s0      r __main__)mainz!idlelib.idle_test.test_parenmatch) verbosityN) rNZidlelib.hyperparserrZidlelib.configrr3rGr r$rKZunittestrQrrrrs   &