<s> from Tkinter import * <EOL> import SearchEngine <EOL> from SearchDialogBase import SearchDialogBase <EOL> def _setup ( text ) : <EOL> root = text . _root ( ) <EOL> engine = SearchEngine . get ( root ) <EOL> if not hasattr ( engine , "<STR_LIT>" ) : <EOL> engine . _searchdialog = SearchDialog ( root , engine ) <EOL> return engine . _searchdialog <EOL> def find ( text ) : <EOL> pat = text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> return _setup ( text ) . open ( text , pat ) <EOL> def find_again ( text ) : <EOL> return _setup ( text ) . find_again ( text ) <EOL> def find_selection ( text ) : <EOL> return _setup ( text ) . find_selection ( text ) <EOL> class SearchDialog ( SearchDialogBase ) : <EOL> def create_widgets ( self ) : <EOL> f = SearchDialogBase . create_widgets ( self ) <EOL> self . make_button ( "<STR_LIT>" , self . default_command , <NUM_LIT:1> ) <EOL> def default_command ( self , event = None ) : <EOL> if not self . engine . getprog ( ) : <EOL> return <EOL> if self . find_again ( self . text ) : <EOL> self . close ( ) <EOL> def find_again ( self , text ) : <EOL> if not self . engine . getpat ( ) : <EOL> self . open ( text ) <EOL> return False <EOL> if not self . engine . getprog ( ) : <EOL> return False <EOL> res = self . engine . search_text ( text ) <EOL> if res : <EOL> line , m = res <EOL> i , j = m . span ( ) <EOL> first = "<STR_LIT>" % ( line , i ) <EOL> last = "<STR_LIT>" % ( line , j ) <EOL> try : <EOL> selfirst = text . index ( "<STR_LIT>" ) <EOL> sellast = text . index ( "<STR_LIT>" ) <EOL> if selfirst == first and sellast == last : <EOL> text . bell ( ) <EOL> return False <EOL> except TclError : <EOL> pass <EOL> text . tag_remove ( "<STR_LIT>" , "<STR_LIT:1.0>" , "<STR_LIT:end>" ) <EOL> text . tag_add ( "<STR_LIT>" , first , last ) <EOL> text . mark_set ( "<STR_LIT>" , self . engine . isback ( ) and first or last ) <EOL> text . see ( "<STR_LIT>" ) <EOL> return True <EOL> else : <EOL> text . bell ( ) <EOL> return False <EOL> def find_selection ( self , text ) : <EOL> pat = text . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if pat : <EOL> self . engine . setcookedpat ( pat ) <EOL> return self . find_again ( text ) </s>
