<s> """<STR_LIT>""" <EOL> from Tkinter import * <EOL> class SimpleDialog : <EOL> def __init__ ( self , master , <EOL> text = '<STR_LIT>' , buttons = [ ] , default = None , cancel = None , <EOL> title = None , class_ = None ) : <EOL> if class_ : <EOL> self . root = Toplevel ( master , class_ = class_ ) <EOL> else : <EOL> self . root = Toplevel ( master ) <EOL> if title : <EOL> self . root . title ( title ) <EOL> self . root . iconname ( title ) <EOL> self . message = Message ( self . root , text = text , aspect = <NUM_LIT> ) <EOL> self . message . pack ( expand = <NUM_LIT:1> , fill = BOTH ) <EOL> self . frame = Frame ( self . root ) <EOL> self . frame . pack ( ) <EOL> self . num = default <EOL> self . cancel = cancel <EOL> self . default = default <EOL> self . root . bind ( '<STR_LIT>' , self . return_event ) <EOL> for num in range ( len ( buttons ) ) : <EOL> s = buttons [ num ] <EOL> b = Button ( self . frame , text = s , <EOL> command = ( lambda self = self , num = num : self . done ( num ) ) ) <EOL> if num == default : <EOL> b . config ( relief = RIDGE , borderwidth = <NUM_LIT:8> ) <EOL> b . pack ( side = LEFT , fill = BOTH , expand = <NUM_LIT:1> ) <EOL> self . root . protocol ( '<STR_LIT>' , self . wm_delete_window ) <EOL> self . _set_transient ( master ) <EOL> def _set_transient ( self , master , relx = <NUM_LIT:0.5> , rely = <NUM_LIT> ) : <EOL> widget = self . root <EOL> widget . withdraw ( ) <EOL> widget . transient ( master ) <EOL> widget . update_idletasks ( ) <EOL> if master . winfo_ismapped ( ) : <EOL> m_width = master . winfo_width ( ) <EOL> m_height = master . winfo_height ( ) <EOL> m_x = master . winfo_rootx ( ) <EOL> m_y = master . winfo_rooty ( ) <EOL> else : <EOL> m_width = master . winfo_screenwidth ( ) <EOL> m_height = master . winfo_screenheight ( ) <EOL> m_x = m_y = <NUM_LIT:0> <EOL> w_width = widget . winfo_reqwidth ( ) <EOL> w_height = widget . winfo_reqheight ( ) <EOL> x = m_x + ( m_width - w_width ) * relx <EOL> y = m_y + ( m_height - w_height ) * rely <EOL> if x + w_width > master . winfo_screenwidth ( ) : <EOL> x = master . winfo_screenwidth ( ) - w_width <EOL> elif x < <NUM_LIT:0> : <EOL> x = <NUM_LIT:0> <EOL> if y + w_height > master . winfo_screenheight ( ) : <EOL> y = master . winfo_screenheight ( ) - w_height <EOL> elif y < <NUM_LIT:0> : <EOL> y = <NUM_LIT:0> <EOL> widget . geometry ( "<STR_LIT>" % ( x , y ) ) <EOL> widget . deiconify ( ) <EOL> def go ( self ) : <EOL> self . root . wait_visibility ( ) <EOL> self . root . grab_set ( ) <EOL> self . root . mainloop ( ) <EOL> self . root . destroy ( ) <EOL> return self . num <EOL> def return_event ( self , event ) : <EOL> if self . default is None : <EOL> self . root . bell ( ) <EOL> else : <EOL> self . done ( self . default ) <EOL> def wm_delete_window ( self ) : <EOL> if self . cancel is None : <EOL> self . root . bell ( ) <EOL> else : <EOL> self . done ( self . cancel ) <EOL> def done ( self , num ) : <EOL> self . num = num <EOL> self . root . quit ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> def test ( ) : <EOL> root = Tk ( ) <EOL> def doit ( root = root ) : <EOL> d = SimpleDialog ( root , <EOL> text = "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" , <EOL> buttons = [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] , <EOL> default = <NUM_LIT:0> , <EOL> cancel = <NUM_LIT:2> , <EOL> title = "<STR_LIT>" ) <EOL> print d . go ( ) <EOL> t = Button ( root , text = '<STR_LIT>' , command = doit ) <EOL> t . pack ( ) <EOL> q = Button ( root , text = '<STR_LIT>' , command = t . quit ) <EOL> q . pack ( ) <EOL> t . mainloop ( ) <EOL> test ( ) </s>
