<s> '''<STR_LIT>''' <EOL> import Tkinter as tk <EOL> import ttk <EOL> class SearchBox ( ttk . Entry ) : <EOL> image1 = None <EOL> image2 = None <EOL> def __init__ ( self , parent , * args , ** kwargs ) : <EOL> ttk . Entry . __init__ ( self , parent , * args , ** kwargs ) <EOL> self . parent = parent <EOL> if self . image1 is None : <EOL> self . _initialize_style ( ) <EOL> self . cancel_label = tk . Label ( self , image = self . cancel_image , background = "<STR_LIT>" , <EOL> borderwidth = <NUM_LIT:0> , highlightthickness = <NUM_LIT:0> , <EOL> cursor = "<STR_LIT>" ) <EOL> self . cancel_label . place ( relx = <NUM_LIT:1.0> , rely = <NUM_LIT> , anchor = "<STR_LIT:e>" , x = - <NUM_LIT:8> ) <EOL> self . cancel_label . bind ( "<STR_LIT>" , self . _on_cancel ) <EOL> self . bind ( "<STR_LIT>" , self . _on_cancel ) <EOL> def _on_cancel ( self , event ) : <EOL> self . delete ( <NUM_LIT:0> , "<STR_LIT:end>" ) <EOL> self . cancel ( ) <EOL> return "<STR_LIT>" <EOL> def cancel ( self ) : <EOL> pass <EOL> def focus ( self ) : <EOL> ttk . Entry . focus ( self ) <EOL> self . selection_range ( <NUM_LIT:0> , "<STR_LIT:end>" ) <EOL> def _initialize_style ( self ) : <EOL> self . normal_image = tk . PhotoImage ( data = image_data , format = "<STR_LIT>" ) <EOL> self . focus_image = tk . PhotoImage ( data = image_data , format = "<STR_LIT>" ) <EOL> self . cancel_image = tk . PhotoImage ( data = cancel_image_data ) <EOL> ttk . Style ( ) . element_create ( "<STR_LIT>" , <EOL> "<STR_LIT:image>" , self . cancel_image , <EOL> sticky = "<STR_LIT:e>" ) <EOL> ttk . Style ( ) . element_create ( "<STR_LIT>" , <EOL> "<STR_LIT:image>" , self . normal_image , ( "<STR_LIT>" , self . focus_image ) , <EOL> border = ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) , sticky = "<STR_LIT>" ) <EOL> ttk . Style ( ) . layout ( "<STR_LIT>" , [ <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : <NUM_LIT:1> , "<STR_LIT>" : [ <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : [ <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT:right>" } ) , <EOL> ( "<STR_LIT>" , { "<STR_LIT>" : "<STR_LIT>" } ) , <EOL> ] } ) , <EOL> ] } ) <EOL> ] ) <EOL> self . configure ( style = "<STR_LIT>" , width = <NUM_LIT> ) <EOL> class SearchEntry ( SearchBox ) : <EOL> def __init__ ( self , parent , * args , ** kwargs ) : <EOL> SearchBox . __init__ ( self , parent , * args , ** kwargs ) <EOL> validatecommand = ( self . register ( self . _on_validate ) , "<STR_LIT>" ) <EOL> self . _stringvar = tk . StringVar ( ) <EOL> self . configure ( validate = "<STR_LIT:key>" , validatecommand = validatecommand , <EOL> textvariable = self . _stringvar ) <EOL> self . bind ( "<STR_LIT>" , self . _on_next ) <EOL> self . bind ( "<STR_LIT>" , self . _on_next ) <EOL> self . bind ( "<STR_LIT>" , self . _on_previous ) <EOL> self . bind ( "<STR_LIT>" , self . _on_next ) <EOL> self . bind ( "<STR_LIT>" , self . _on_next ) <EOL> def _on_previous ( self , event ) : <EOL> self . previous ( ) <EOL> return "<STR_LIT>" <EOL> def _on_next ( self , event ) : <EOL> self . next ( ) <EOL> return "<STR_LIT>" <EOL> def cancel ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . reset ( ) <EOL> target = self . parent . get_search_target ( ) <EOL> target . focus ( ) <EOL> def next ( self ) : <EOL> '''<STR_LIT>''' <EOL> target = self . parent . get_search_target ( ) <EOL> search_range = target . tag_nextrange ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if ( len ( search_range ) == <NUM_LIT:2> and <EOL> target . compare ( "<STR_LIT>" , "<STR_LIT>" , search_range [ <NUM_LIT:1> ] ) and <EOL> target . compare ( "<STR_LIT>" , "<STR_LIT>" , search_range [ <NUM_LIT:0> ] ) ) : <EOL> search_range = target . tag_nextrange ( "<STR_LIT>" , search_range [ <NUM_LIT:1> ] ) <EOL> if len ( search_range ) == <NUM_LIT:0> : <EOL> search_range = target . tag_nextrange ( "<STR_LIT>" , <NUM_LIT:1.0> ) <EOL> self . bell ( ) <EOL> if len ( search_range ) == <NUM_LIT:0> : <EOL> self . bell ( ) <EOL> else : <EOL> self . _mark_current ( * search_range ) <EOL> def previous ( self ) : <EOL> '''<STR_LIT>''' <EOL> target = self . parent . get_search_target ( ) <EOL> search_range = target . tag_prevrange ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> if ( len ( search_range ) == <NUM_LIT:2> and <EOL> target . compare ( "<STR_LIT>" , "<STR_LIT>" , search_range [ <NUM_LIT:1> ] ) and <EOL> target . compare ( "<STR_LIT>" , "<STR_LIT>" , search_range [ <NUM_LIT:0> ] ) ) : <EOL> search_range = target . tag_prevrange ( "<STR_LIT>" , search_range [ <NUM_LIT:0> ] ) <EOL> if len ( search_range ) == <NUM_LIT:0> : <EOL> search_range = target . tag_prevrange ( "<STR_LIT>" , "<STR_LIT:end>" ) <EOL> self . bell ( ) <EOL> if len ( search_range ) == <NUM_LIT:0> : <EOL> self . bell ( ) <EOL> else : <EOL> self . _mark_current ( * search_range ) <EOL> def _on_validate ( self , P ) : <EOL> '''<STR_LIT>''' <EOL> self . reset ( ) <EOL> if len ( P ) > <NUM_LIT:0> : <EOL> self . begin ( P ) <EOL> return True <EOL> def begin ( self , pattern , start = "<STR_LIT>" ) : <EOL> '''<STR_LIT>''' <EOL> target = self . parent . get_search_target ( ) <EOL> self . reset ( ) <EOL> start = target . index ( start ) <EOL> range1 = ( start , "<STR_LIT:end>" ) <EOL> if target . compare ( start , "<STR_LIT>" , "<STR_LIT:1.0>" ) : <EOL> range2 = ( "<STR_LIT:1.0>" , start ) <EOL> else : <EOL> range2 = ( ) <EOL> command = [ target . _w , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> command . append ( pattern ) <EOL> result1 = self . tk . call ( tuple ( command + [ "<STR_LIT>" , "<STR_LIT:end>" ] ) ) <EOL> result2 = self . tk . call ( tuple ( command + [ "<STR_LIT:1.0>" , "<STR_LIT>" ] ) ) <EOL> result = list ( result1 ) + list ( reversed ( result2 ) ) <EOL> if len ( result ) > <NUM_LIT:0> : <EOL> i = result [ <NUM_LIT:0> ] <EOL> self . _mark_current ( i , "<STR_LIT>" % ( i , len ( pattern ) ) ) <EOL> for index in result : <EOL> target . tag_add ( "<STR_LIT>" , index , "<STR_LIT>" % ( index , len ( pattern ) ) ) <EOL> def _mark_current ( self , start , end ) : <EOL> '''<STR_LIT>''' <EOL> target = self . parent . get_search_target ( ) <EOL> target . tag_remove ( "<STR_LIT>" , <NUM_LIT:1.0> , "<STR_LIT:end>" ) <EOL> target . tag_add ( "<STR_LIT>" , start , end ) <EOL> target . tag_remove ( "<STR_LIT>" , <NUM_LIT:1.0> , "<STR_LIT:end>" ) <EOL> target . tag_add ( "<STR_LIT>" , start , end ) <EOL> target . mark_set ( "<STR_LIT>" , start ) <EOL> target . tag_raise ( "<STR_LIT>" ) <EOL> target . tag_raise ( "<STR_LIT>" ) <EOL> target . see ( start ) <EOL> def reset ( self ) : <EOL> '''<STR_LIT>''' <EOL> target = self . parent . get_search_target ( ) <EOL> target . tag_configure ( "<STR_LIT>" , background = "<STR_LIT>" , foreground = "<STR_LIT>" ) <EOL> target . tag_configure ( "<STR_LIT>" , <EOL> background = target . tag_cget ( "<STR_LIT>" , "<STR_LIT>" ) , <EOL> foreground = target . tag_cget ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> target . tag_remove ( "<STR_LIT>" , <NUM_LIT:1.0> , "<STR_LIT:end>" ) <EOL> target . tag_remove ( "<STR_LIT>" , <NUM_LIT:1.0> , "<STR_LIT:end>" ) <EOL> target . tag_raise ( "<STR_LIT>" ) <EOL> target . tag_raise ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> target . tag_raise ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> cancel_image_data = '''<STR_LIT>''' <EOL> image_data = '''<STR_LIT>''' <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> root = tk . Tk ( ) <EOL> e1 = SearchEntry ( root ) <EOL> e1 . pack ( side = "<STR_LIT>" ) <EOL> root . mainloop ( ) </s>
