from GUI import Window, ModalDialog, Label, Button, TextField, application

def modal_dialog():
    global dlog ###
    dlog = ModalDialog(title = "Spanish Inquisition", size = (200, 140))
    dlog.place(Label(text = "Surprise!!!"), left = 20, top = 20)
    field = TextField()
    dlog.place(field, left = 20, top = 60, right = -20)
    field.become_target()
    def ok():
        dlog.dismiss(42)
    def cancel():
        dlog.dismiss(0)
    dlog.default_button = Button(title = "OK", action = ok)
    dlog.cancel_button = Button(title = "Cancel", action = cancel)
    dlog.place(dlog.default_button, right = -20, bottom = -20)
    dlog.place(dlog.cancel_button, left = 20, bottom = -20)
    dlog.center()
    result = dlog.present()
    print "Result =", result
    dlog.destroy()

win = Window(title = "Modal Dialogs", size = (200, 60))
dialog_button = Button(title = "Give Me A Dialog", action = modal_dialog)
win.place(dialog_button, left = 20, top = 20)
win.show()

instructions = """
Clicking the "Give Me A Dialog" button should pop up a modal
dialog centered on the screen, containing a label, a text
field, an OK button and a Cancel button.

While the dialog is up:
* Interaction with the main window should be prevented.
* Edit menu commands should be enabled as appropriate for the
  text field; other menu commands should be disabled.

Clicking the OK button or pressing Return or Enter should
dismiss the dialog and report "Result = 42".

Clicking the Cancel button or pressing Escape should
dismiss the dialog and report "Result = 0".

On platforms without an application-wide menu bar, the keyboard
equivalents of the edit menu commands should still work even if
no menus are available.
"""

print instructions
application().run()
