3 § f$ã@sfdZddlmZddlmZddddœZdZGd d „d ƒZejƒe d krbdd l m Z e d dd�dS)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œeZdZdZdZd%Zdd„Zed d „ƒZd d „Z d d„Z dd„Z dd„Z dd„Z d&dd„Zdd„Zdd„Zdd„Zdd„Zeeeed œZd!d"„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<>ú ú ú úcCs0||_|j|_|jj|j|jƒd|_d|_dS)Nr)ÚeditwinÚtextZbindÚRESTORE_VIRTUAL_EVENT_NAMEÚ restore_eventÚcounterÚis_restore_active)Úselfr©rú7/opt/alt/python36/lib64/python3.6/idlelib/parenmatch.pyÚ__init__(s  zParenMatch.__init__cCsVtjddddd�|_tjdddddd �|_tjddd d d d �|_tjtjƒ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]}|jj|j|ƒqWd|_dS)z5Activate mechanism to restore text from highlighting.TN)rÚRESTORE_SEQUENCESrZ event_addr)rÚseqrrrÚactivate_restore>s zParenMatch.activate_restorecCs0|jr,x|jD]}|jj|j|ƒqWd|_dS)zRemove restore event bindings.FN)rr(rZ event_deleter)rr)rrrÚdeactivate_restoreEs zParenMatch.deactivate_restorecCst|jdƒjƒ}|j|ƒ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|jjdƒ}|tkrdSt|jdƒ}|jƒs0dS|jt|dƒ}|j|ƒdS)zHandle user input of closer.z insert-1cNT)rÚgetÚ_openersrrZ is_in_coder.r/)rr0ZcloserZhpr1rrrÚparen_closed_eventSs   zParenMatch.paren_closed_eventcCsT|dkr|jr|jjƒdS|jƒ|jj|j|jƒ||ƒ|jrH|j n|j ƒdS)N) r$rrr*Útagfuncsr3r"Úcreate_tag_expressionr#Úset_timeout_lastÚset_timeout_none)rr1rrrr/`s  zParenMatch.finish_paren_eventNcCs&|jjdƒ|jƒ|jd7_dS)zRemove effect of doing match.Úparenr!N)rZ tag_deleter+r)rr0rrrrks zParenMatch.restore_eventcCs||jkr|jƒdS)N)rr)rZ timer_countrrrÚhandle_restore_timerqs zParenMatch.handle_restore_timercCs&|jjd|dƒ|jjd|jƒdS)z'Highlight the single paren that matchesr:rN)rÚtag_addÚ tag_configr%)rr1rrrÚcreate_tag_openerxszParenMatch.create_tag_openercCsb|jj|dƒd kr"|dd}n|d}|jjd|d|dd|d|ƒ|jjd|jƒd S) z#Highlight the left and right parensr!rrr z+1cr:rz-1cN)rrr )rr3r<r=r%)rr1Ú rightindexrrrÚcreate_tag_parens}s $zParenMatch.create_tag_parenscCsR|jj|dƒd kr"|dd}n|d}|jjd|d|ƒ|jjd|jƒdS) zHighlight the entire expressionr!rrr z+1cr:rN)rrr )rr3r<r=r%)rr1r?rrrr7†s z ParenMatch.create_tag_expression)rrZparensZ expressioncCs>|jd7_||j|jjdƒfdd„}|jjjt||ƒdS)zSHighlight will remain until user input turns it off or the insert has movedr!r,cSs2||jjdƒkr|j|ƒn|jjjt||ƒdS)Nr,)rÚindexr;rÚ text_frameÚafterÚ CHECK_DELAY)ÚcallmerÚcrArrrrE s z+ParenMatch.set_timeout_none..callmeN)rrrArrBrCrD)rrErrrr9™szParenMatch.set_timeout_nonecCs0|jd7_|jjj|j||jfdd„ƒdS)zFThe last highlight created will be removed after FLASH_DELAY millisecsr!cSs |j|ƒS)N)r;)rrFrrrÚ¯sz-ParenMatch.set_timeout_last..N)rrrBrCr#)rrrrr8¨szParenMatch.set_timeout_last)r r rr)N)Ú__name__Ú __module__Ú __qualname__Ú__doc__rr(rÚ classmethodr'r*r+r2r5r/rr;r>r@r7r6r9r8rrrrr s,     r Ú__main__)Úmainz!idlelib.idle_test.test_parenmatché)Ú verbosityN) rKZidlelib.hyperparserrZidlelib.configrr4rDr r'rHZunittestrNrrrrÚs   &