<s> """<STR_LIT>""" <EOL> from HyperParser import HyperParser <EOL> from configHandler import idleConf <EOL> _openers = { '<STR_LIT:)>' : '<STR_LIT:(>' , '<STR_LIT:]>' : '<STR_LIT:[>' , '<STR_LIT:}>' : '<STR_LIT:{>' } <EOL> CHECK_DELAY = <NUM_LIT:100> <EOL> class ParenMatch : <EOL> """<STR_LIT>""" <EOL> menudefs = [ <EOL> ( '<STR_LIT>' , [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> ] ) <EOL> ] <EOL> STYLE = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> default = '<STR_LIT>' ) <EOL> FLASH_DELAY = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> type = '<STR_LIT:int>' , default = <NUM_LIT> ) <EOL> HILITE_CONFIG = idleConf . GetHighlight ( idleConf . CurrentTheme ( ) , '<STR_LIT>' ) <EOL> BELL = idleConf . GetOption ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> type = '<STR_LIT:bool>' , default = <NUM_LIT:1> ) <EOL> RESTORE_VIRTUAL_EVENT_NAME = "<STR_LIT>" <EOL> RESTORE_SEQUENCES = ( "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , "<STR_LIT>" ) <EOL> def __init__ ( self , editwin ) : <EOL> self . editwin = editwin <EOL> self . text = editwin . text <EOL> editwin . text . bind ( self . RESTORE_VIRTUAL_EVENT_NAME , <EOL> self . restore_event ) <EOL> self . counter = <NUM_LIT:0> <EOL> self . is_restore_active = <NUM_LIT:0> <EOL> self . set_style ( self . STYLE ) <EOL> def activate_restore ( self ) : <EOL> if not self . is_restore_active : <EOL> for seq in self . RESTORE_SEQUENCES : <EOL> self . text . event_add ( self . RESTORE_VIRTUAL_EVENT_NAME , seq ) <EOL> self . is_restore_active = True <EOL> def deactivate_restore ( self ) : <EOL> if self . is_restore_active : <EOL> for seq in self . RESTORE_SEQUENCES : <EOL> self . text . event_delete ( self . RESTORE_VIRTUAL_EVENT_NAME , seq ) <EOL> self . is_restore_active = False <EOL> def set_style ( self , style ) : <EOL> self . STYLE = style <EOL> if style == "<STR_LIT:default>" : <EOL> self . create_tag = self . create_tag_default <EOL> self . set_timeout = self . set_timeout_last <EOL> elif style == "<STR_LIT>" : <EOL> self . create_tag = self . create_tag_expression <EOL> self . set_timeout = self . set_timeout_none <EOL> def flash_paren_event ( self , event ) : <EOL> indices = HyperParser ( self . editwin , "<STR_LIT>" ) . get_surrounding_brackets ( ) <EOL> if indices is None : <EOL> self . warn_mismatched ( ) <EOL> return <EOL> self . activate_restore ( ) <EOL> self . create_tag ( indices ) <EOL> self . set_timeout_last ( ) <EOL> def paren_closed_event ( self , event ) : <EOL> closer = self . text . get ( "<STR_LIT>" ) <EOL> if closer not in _openers : <EOL> return <EOL> hp = HyperParser ( self . editwin , "<STR_LIT>" ) <EOL> if not hp . is_in_code ( ) : <EOL> return <EOL> indices = hp . get_surrounding_brackets ( _openers [ closer ] , True ) <EOL> if indices is None : <EOL> self . warn_mismatched ( ) <EOL> return <EOL> self . activate_restore ( ) <EOL> self . create_tag ( indices ) <EOL> self . set_timeout ( ) <EOL> def restore_event ( self , event = None ) : <EOL> self . text . tag_delete ( "<STR_LIT>" ) <EOL> self . deactivate_restore ( ) <EOL> self . counter += <NUM_LIT:1> <EOL> def handle_restore_timer ( self , timer_count ) : <EOL> if timer_count == self . counter : <EOL> self . restore_event ( ) <EOL> def warn_mismatched ( self ) : <EOL> if self . BELL : <EOL> self . text . bell ( ) <EOL> def create_tag_default ( self , indices ) : <EOL> """<STR_LIT>""" <EOL> self . text . tag_add ( "<STR_LIT>" , indices [ <NUM_LIT:0> ] ) <EOL> self . text . tag_config ( "<STR_LIT>" , self . HILITE_CONFIG ) <EOL> def create_tag_expression ( self , indices ) : <EOL> """<STR_LIT>""" <EOL> if self . text . get ( indices [ <NUM_LIT:1> ] ) in ( '<STR_LIT:)>' , '<STR_LIT:]>' , '<STR_LIT:}>' ) : <EOL> rightindex = indices [ <NUM_LIT:1> ] + "<STR_LIT>" <EOL> else : <EOL> rightindex = indices [ <NUM_LIT:1> ] <EOL> self . text . tag_add ( "<STR_LIT>" , indices [ <NUM_LIT:0> ] , rightindex ) <EOL> self . text . tag_config ( "<STR_LIT>" , self . HILITE_CONFIG ) <EOL> def set_timeout_none ( self ) : <EOL> """<STR_LIT>""" <EOL> self . counter += <NUM_LIT:1> <EOL> def callme ( callme , self = self , c = self . counter , <EOL> index = self . text . index ( "<STR_LIT>" ) ) : <EOL> if index != self . text . index ( "<STR_LIT>" ) : <EOL> self . handle_restore_timer ( c ) <EOL> else : <EOL> self . editwin . text_frame . after ( CHECK_DELAY , callme , callme ) <EOL> self . editwin . text_frame . after ( CHECK_DELAY , callme , callme ) <EOL> def set_timeout_last ( self ) : <EOL> """<STR_LIT>""" <EOL> self . counter += <NUM_LIT:1> <EOL> self . editwin . text_frame . after ( self . FLASH_DELAY , <EOL> lambda self = self , c = self . counter : self . handle_restore_timer ( c ) ) </s>
