<s> import sys <EOL> from threading import currentThread <EOL> from Tkinter import ( Tk , Toplevel , Frame , Listbox , Label , Button , Entry , <EOL> BOTH , END , LEFT , W ) <EOL> class _TkDialog ( Toplevel ) : <EOL> _left_button = '<STR_LIT:OK>' <EOL> _right_button = '<STR_LIT>' <EOL> def __init__ ( self , message , value = None , ** extra ) : <EOL> self . _prevent_execution_with_timeouts ( ) <EOL> self . _parent = self . _get_parent ( ) <EOL> Toplevel . __init__ ( self , self . _parent ) <EOL> self . _initialize_dialog ( ) <EOL> self . _create_body ( message , value , ** extra ) <EOL> self . _create_buttons ( ) <EOL> self . _result = None <EOL> def _prevent_execution_with_timeouts ( self ) : <EOL> if '<STR_LIT>' not in sys . platform and currentThread ( ) . getName ( ) != '<STR_LIT>' : <EOL> raise RuntimeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> def _get_parent ( self ) : <EOL> parent = Tk ( ) <EOL> parent . withdraw ( ) <EOL> return parent <EOL> def _initialize_dialog ( self ) : <EOL> self . title ( '<STR_LIT>' ) <EOL> self . grab_set ( ) <EOL> self . protocol ( "<STR_LIT>" , self . _right_button_clicked ) <EOL> self . bind ( "<STR_LIT>" , self . _right_button_clicked ) <EOL> self . minsize ( <NUM_LIT> , <NUM_LIT> ) <EOL> self . geometry ( "<STR_LIT>" % self . _get_center_location ( ) ) <EOL> self . _bring_to_front ( ) <EOL> def _get_center_location ( self ) : <EOL> x = ( self . winfo_screenwidth ( ) - self . winfo_reqwidth ( ) ) / <NUM_LIT:2> <EOL> y = ( self . winfo_screenheight ( ) - self . winfo_reqheight ( ) ) / <NUM_LIT:2> <EOL> return x , y <EOL> def _bring_to_front ( self ) : <EOL> self . attributes ( '<STR_LIT>' , True ) <EOL> self . attributes ( '<STR_LIT>' , False ) <EOL> def _create_body ( self , message , value , ** extra ) : <EOL> frame = Frame ( self ) <EOL> Label ( frame , text = message , anchor = W , justify = LEFT , wraplength = <NUM_LIT> ) . pack ( fill = BOTH ) <EOL> selector = self . _create_selector ( frame , value , ** extra ) <EOL> if selector : <EOL> selector . pack ( fill = BOTH ) <EOL> selector . focus_set ( ) <EOL> frame . pack ( padx = <NUM_LIT:5> , pady = <NUM_LIT:5> , expand = <NUM_LIT:1> , fill = BOTH ) <EOL> def _create_selector ( self , frame , value ) : <EOL> return None <EOL> def _create_buttons ( self ) : <EOL> frame = Frame ( self ) <EOL> self . _create_button ( frame , self . _left_button , <EOL> self . _left_button_clicked ) <EOL> self . _create_button ( frame , self . _right_button , <EOL> self . _right_button_clicked ) <EOL> frame . pack ( ) <EOL> def _create_button ( self , parent , label , callback ) : <EOL> if label : <EOL> button = Button ( parent , text = label , width = <NUM_LIT:10> , command = callback ) <EOL> button . pack ( side = LEFT , padx = <NUM_LIT:5> , pady = <NUM_LIT:5> ) <EOL> def _left_button_clicked ( self , event = None ) : <EOL> if self . _validate_value ( ) : <EOL> self . _result = self . _get_value ( ) <EOL> self . _close ( ) <EOL> def _validate_value ( self ) : <EOL> return True <EOL> def _get_value ( self ) : <EOL> return None <EOL> def _close ( self ) : <EOL> self . _parent . destroy ( ) <EOL> def _right_button_clicked ( self , event = None ) : <EOL> self . _result = self . _get_right_button_value ( ) <EOL> self . _close ( ) <EOL> def _get_right_button_value ( self ) : <EOL> return None <EOL> def show ( self ) : <EOL> self . wait_window ( self ) <EOL> return self . _result <EOL> class MessageDialog ( _TkDialog ) : <EOL> _right_button = None <EOL> class InputDialog ( _TkDialog ) : <EOL> def __init__ ( self , message , default = '<STR_LIT>' , hidden = False ) : <EOL> _TkDialog . __init__ ( self , message , default , hidden = hidden ) <EOL> def _create_selector ( self , parent , default , hidden ) : <EOL> self . _entry = Entry ( parent , show = '<STR_LIT:*>' if hidden else '<STR_LIT>' ) <EOL> self . _entry . insert ( <NUM_LIT:0> , default ) <EOL> self . _entry . select_range ( <NUM_LIT:0> , END ) <EOL> return self . _entry <EOL> def _get_value ( self ) : <EOL> return self . _entry . get ( ) <EOL> class SelectionDialog ( _TkDialog ) : <EOL> def __init__ ( self , message , values ) : <EOL> _TkDialog . __init__ ( self , message , values ) <EOL> def _create_selector ( self , parent , values ) : <EOL> self . _listbox = Listbox ( parent ) <EOL> for item in values : <EOL> self . _listbox . insert ( END , item ) <EOL> return self . _listbox <EOL> def _validate_value ( self ) : <EOL> return bool ( self . _listbox . curselection ( ) ) <EOL> def _get_value ( self ) : <EOL> return self . _listbox . get ( self . _listbox . curselection ( ) ) <EOL> class PassFailDialog ( _TkDialog ) : <EOL> _left_button = '<STR_LIT>' <EOL> _right_button = '<STR_LIT>' <EOL> def _get_value ( self ) : <EOL> return True <EOL> def _get_right_button_value ( self ) : <EOL> return False </s>
