B Ç©Š¢WÌã@sfdZddlmZddlmZddddœZdZGd d „d ƒZe ¡e d krbdd l m Z e d dddS)zàParenMatch -- 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@sœeZdZdZdZdZdd„Zedd„ƒZdd „Z d d „Z d d „Z dd„Z dd„Z d"dd„Zdd„Zdd„Zdd„Zdd„ZeeeedœZdd„Zd 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|j¡d|_d|_dS)Nr)ÚeditwinÚtextZbindÚRESTORE_VIRTUAL_EVENT_NAMEÚ restore_eventÚcounterÚis_restore_active)Úselfr ©rú7/opt/alt/python37/lib64/python3.7/idlelib/parenmatch.pyÚ__init__(s  zParenMatch.__init__cCsVtjddddd|_tjdddddd |_tjddd d d d |_t t ¡d ¡|_dS)NÚ extensionsr ZstyleÚopener)Údefaultz flash-delayÚintiô)ÚtyperÚbellÚbooléZhilite)rZ GetOptionÚSTYLEÚ FLASH_DELAYÚBELLZ GetHighlightZ CurrentThemeÚ HILITE_CONFIG)ÚclsrrrÚreload3s zParenMatch.reloadcCs0|js,x|jD]}|j |j|¡qWd|_dS)z5Activate mechanism to restore text from highlighting.TN)rÚRESTORE_SEQUENCESr Z event_addr)rÚseqrrrÚactivate_restore>s zParenMatch.activate_restorecCs0|jr,x|jD]}|j |j|¡qWd|_dS)zRemove restore event bindings.FN)rr$r Z event_deleter)rr%rrrÚdeactivate_restoreEs zParenMatch.deactivate_restorecCst|jdƒ ¡}| |¡dS)zAHandle editor 'show surrounding parens' event (menu or shortcut).ÚinsertÚbreak)rr Úget_surrounding_bracketsÚfinish_paren_event)rÚeventÚindicesrrrÚflash_paren_eventLs zParenMatch.flash_paren_eventcCsN|j d¡}|tkrdSt|jdƒ}| ¡s0dS| t|d¡}| |¡dS)zHandle user input of closer.z insert-1cNT)r ÚgetÚ_openersrr Z is_in_coder*r+)rr,ZcloserZhpr-rrrÚparen_closed_eventSs   zParenMatch.paren_closed_eventcCsT|dkr|jr|j ¡dS| ¡|j |j|j¡||ƒ|jrH|j n|j ƒdS)N) r r rr&Útagfuncsr/rÚcreate_tag_expressionrÚset_timeout_lastÚset_timeout_none)rr-rrrr+`s  zParenMatch.finish_paren_eventNcCs&|j d¡| ¡|jd7_dS)zRemove effect of doing match.ÚparenrN)r Z tag_deleter'r)rr,rrrrks zParenMatch.restore_eventcCs||jkr| ¡dS)N)rr)rZ timer_countrrrÚhandle_restore_timerqs zParenMatch.handle_restore_timercCs&|j d|d¡|j d|j¡dS)z'Highlight the single paren that matchesr6rN)r Útag_addÚ tag_configr!)rr-rrrÚcreate_tag_openerxszParenMatch.create_tag_openercCsb|j |d¡dkr"|dd}n|d}|j d|d|dd|d|¡|j d|j¡dS)z#Highlight the left and right parensr)rrr z+1cr6rz-1cN)r r/r8r9r!)rr-Ú rightindexrrrÚcreate_tag_parens}s $zParenMatch.create_tag_parenscCsR|j |d¡dkr"|dd}n|d}|j d|d|¡|j d|j¡dS)zHighlight the entire expressionr)rrr z+1cr6rN)r r/r8r9r!)rr-r;rrrr3†s z ParenMatch.create_tag_expression)rrZparensZ expressioncCs>|jd7_||j|j d¡fdd„}|jj t||¡dS)zSHighlight will remain until user input turns it off or the insert has movedrr(cSs2||j d¡kr| |¡n|jj t||¡dS)Nr()r Úindexr7r Ú text_frameÚafterÚ CHECK_DELAY)ÚcallmerÚcr=rrrrA s z+ParenMatch.set_timeout_none..callmeN)rr r=r r>r?r@)rrArrrr5™szParenMatch.set_timeout_nonecCs0|jd7_|jj |j||jfdd„¡dS)zFThe last highlight created will be removed after FLASH_DELAY millisecsrcSs | |¡S)N)r7)rrBrrrÚ¯óz-ParenMatch.set_timeout_last..N)rr r>r?r)rrrrr4¨szParenMatch.set_timeout_last)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr$rÚ classmethodr#r&r'r.r1r+rr7r:r<r3r2r5r4rrrrr s*     r Ú__main__)Úmainz!idlelib.idle_test.test_parenmatché)Ú verbosityN) rHZidlelib.hyperparserrZidlelib.configrr0r@r r#rEZunittestrKrrrrÚs   &