U .c$@sfdZddlmZddlmZddddZdZGd d d Zee d krbdd l m Z e d dddS)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 r7/opt/alt/python38/lib64/python3.8/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.reloadcCs,|js(|jD]}|j|j|q d|_dS)z5Activate mechanism to restore text from highlighting.TN)rRESTORE_SEQUENCESrZ event_addrrseqrrractivate_restore>s zParenMatch.activate_restorecCs,|jr(|jD]}|j|j|q d|_dS)zRemove restore event bindings.FN)rr%rZ event_deleterr&rrrdeactivate_restoreEs 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}|tkrdSt|jd}|s0dS|t|d}||dS)zHandle user input of closer.z insert-1cNT)rget_openersrr Z is_in_coder,r-)rr.ZcloserZhpr/rrrparen_closed_eventSs   zParenMatch.paren_closed_eventcCsT|dkr|jr|jdS||j|j|j|||jrH|j n|j dSN) r!rrr(tagfuncsr1rcreate_tag_expressionr set_timeout_lastset_timeout_nonerr/rrrr-`s  zParenMatch.finish_paren_eventNcCs&|jd||jd7_dS)zRemove effect of doing match.parenrN)rZ tag_deleter)r)rr.rrrrks zParenMatch.restore_eventcCs||jkr|dSr4)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"r9rrrcreate_tag_openerxszParenMatch.create_tag_openercCsb|j|ddkr"|dd}n|d}|jd|d|dd|d||jd|jdS)z#Highlight the left and right parensrr+1cr:rz-1cNrr1r<r=r"rr/Z rightindexrrrcreate_tag_parens}s $zParenMatch.create_tag_parenscCsR|j|ddkr"|dd}n|d}|jd|d||jd|jdS)zHighlight the entire expressionrrr?r:rNr@rArrrr6s 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*cSs2||jdkr||n|jjt||dS)Nr*)rindexr;r text_frameafter CHECK_DELAY)callmercrCrrrrGs z+ParenMatch.set_timeout_none..callmeN)rrrCr rDrErF)rrGrrrr8s  zParenMatch.set_timeout_nonecCs0|jd7_|jj|j||jfdddS)zFThe last highlight created will be removed after FLASH_DELAY millisecsrcSs ||Sr4)r;)rrHrrrz-ParenMatch.set_timeout_last..N)rr rDrEr )rrrrr7s zParenMatch.set_timeout_last)N)__name__ __module__ __qualname____doc__rr%r classmethodr$r(r)r0r3r-rr;r>rBr6r5r8r7rrrrr s.       r __main__)mainz!idlelib.idle_test.test_parenmatch) verbosityN) rNZidlelib.hyperparserrZidlelib.configrr2rFr r$rKZunittestrQrrrrs   &