ž pyMaγc@s^dZddlmZddlmZidd6dd6dd 6Zd ZGd d „d ƒZd S(uςParenMatch -- An IDLE extension 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. i(u HyperParser(uidleConfu(u)u[u]u{u}idcBsL|EeZdZdZdd1gfgZejdddddƒZejddd d d dd ƒZej ej ƒd ƒZ ejdddd dddƒZ dZ d2Zdd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd0d"d#„Zd$d%„Zd&d'„Zd(d)„Zd*d+„Zd,d-„Zd.d/„Zd0S(3u ParenMatchu€Highlight matching parentheses There are three supported style of paren matching, based loosely on the Emacs options. The style is select based on the HILITE_STYLE attribute; it can be changed used the set_style method. The supported styles are: default -- When a right paren is typed, highlight the matching left paren for 1/2 sec. expression -- When a right paren is typed, highlight the entire expression from the left paren to the right paren. TODO: - extend IDLE with configuration dialog to change options - implement rest of Emacs highlight styles (see below) - print mismatch warning in IDLE status window Note: In Emacs, there are several styles of highlight where the matching paren is highlighted whenever the cursor is immediately to the right of a right paren. I don't know how to do that in Tk, so I haven't bothered. uedituShow surrounding parensu<>u extensionsustyleudefaultu expressionu flash-delayutypeuintiτuhiliteubellubooliu<>u u u ucCsT||_|j|_|jj|j|jƒd|_d|_|j|jƒdS(Ni( ueditwinutextubinduRESTORE_VIRTUAL_EVENT_NAMEu restore_eventucounteruis_restore_activeu set_styleuSTYLE(uselfueditwin((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyu__init__;s     uParenMatch.__init__cCsC|js?x'|jD]}|jj|j|ƒqWd|_ndS(NT(uis_restore_activeuRESTORE_SEQUENCESutextu event_adduRESTORE_VIRTUAL_EVENT_NAMEuTrue(uselfuseq((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyuactivate_restoreGs uParenMatch.activate_restorecCsC|jr?x'|jD]}|jj|j|ƒqWd|_ndS(NF(uis_restore_activeuRESTORE_SEQUENCESutextu event_deleteuRESTORE_VIRTUAL_EVENT_NAMEuFalse(uselfuseq((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyudeactivate_restoreMs uParenMatch.deactivate_restorecCs[||_|dkr0|j|_|j|_n'|dkrW|j|_|j|_ndS(Nudefaultu expression(uSTYLEucreate_tag_defaultu create_taguset_timeout_lastu set_timeoutucreate_tag_expressionuset_timeout_none(uselfustyle((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyu set_styleSs     uParenMatch.set_stylecCsWt|jdƒjƒ}|dkr2|jƒdS|jƒ|j|ƒ|jƒdS(Nuinsert(u HyperParserueditwinuget_surrounding_bracketsuNoneuwarn_mismatcheduactivate_restoreu create_taguset_timeout_last(uselfueventuindices((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyuflash_paren_event\s    uParenMatch.flash_paren_eventcCs™|jjdƒ}|tkr"dSt|jdƒ}|jƒsDdS|jt|dƒ}|dkrt|j ƒdS|j ƒ|j |ƒ|j ƒdS(Nu insert-1cT( utextugetu_openersu HyperParserueditwinu is_in_codeuget_surrounding_bracketsuTrueuNoneuwarn_mismatcheduactivate_restoreu create_tagu set_timeout(uselfueventucloseruhpuindices((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyuparen_closed_eventes      uParenMatch.paren_closed_eventcCs-|jjdƒ|jƒ|jd7_dS(Nupareni(utextu tag_deleteudeactivate_restoreucounter(uselfuevent((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyu restore_eventus uParenMatch.restore_eventcCs ||jkr|jƒndS(N(ucounteru restore_event(uselfu timer_count((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyuhandle_restore_timerzsuParenMatch.handle_restore_timercCs|jr|jjƒndS(N(uBELLutextubell(uself((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyuwarn_mismatched~s uParenMatch.warn_mismatchedcCs1|jjd|dƒ|jjd|jƒdS(u'Highlight the single paren that matchesupareniN(utextutag_addu tag_configu HILITE_CONFIG(uselfuindices((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyucreate_tag_default…suParenMatch.create_tag_defaultcCsk|jj|dƒd kr-|dd}n |d}|jjd|d|ƒ|jjd|jƒdS( uHighlight the entire expressioniu)u]u}u+1cupareniN(u)u]u}(utextugetutag_addu tag_configu HILITE_CONFIG(uselfuindicesu rightindex((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyucreate_tag_expressionŠs  u ParenMatch.create_tag_expressioncCsP|jd7_||j|jjdƒdd„}|jjjt||ƒdS(uSHighlight will remain until user input turns it off or the insert has movediuinsertcSsE||jjdƒkr(|j|ƒn|jjjt||ƒdS(Nuinsert(utextuindexuhandle_restore_timerueditwinu text_frameuafteru CHECK_DELAY(ucallmeuselfucuindex((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyucallmesu+ParenMatch.set_timeout_none..callmeN(ucounterutextuindexueditwinu text_frameuafteru CHECK_DELAY(uselfucallme((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyuset_timeout_none–s uParenMatch.set_timeout_nonecCs;|jd7_|jjj|j||jdd„ƒdS(u7The last highlight created will be removed after .5 secicSs |j|ƒS(N(uhandle_restore_timer(uselfuc((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyu«su-ParenMatch.set_timeout_last..N(ucounterueditwinu text_frameuafteru FLASH_DELAY(uself((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyuset_timeout_last₯suParenMatch.set_timeout_lastN(uShow surrounding parensu<>(u u u u(u__name__u __module__u __qualname__u__doc__umenudefsuidleConfu GetOptionuSTYLEu FLASH_DELAYu GetHighlightu CurrentThemeu HILITE_CONFIGuBELLuRESTORE_VIRTUAL_EVENT_NAMEuRESTORE_SEQUENCESu__init__uactivate_restoreudeactivate_restoreu set_styleuflash_paren_eventuparen_closed_eventuNoneu restore_eventuhandle_restore_timeruwarn_mismatcheducreate_tag_defaultucreate_tag_expressionuset_timeout_noneuset_timeout_last(u __locals__((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyu ParenMatchs4        u ParenMatchN(u__doc__uidlelib.HyperParseru HyperParseruidlelib.configHandleruidleConfu_openersu CHECK_DELAYu ParenMatch(((u7/opt/alt/python33/lib64/python3.3/idlelib/ParenMatch.pyus