Clarify portability and main program.
[python/dscho.git] / Lib / lib-tk / tkMessageBox.py
bloba6de8c657a5ed23e900d7c64f9cee78966cd9d85
2 # Instant Python
3 # $Id$
5 # tk common message boxes
7 # this module provides an interface to the native message boxes
8 # available in Tk 4.2 and newer.
10 # written by Fredrik Lundh, May 1997
14 # options (all have default values):
16 # - default: which button to make default (one of the reply codes)
18 # - icon: which icon to display (see below)
20 # - message: the message to display
22 # - parent: which window to place the dialog on top of
24 # - title: dialog title
26 # - type: dialog type; that is, which buttons to display (see below)
29 from tkCommonDialog import Dialog
32 # constants
34 # icons
35 ERROR = "error"
36 INFO = "info"
37 QUESTION = "question"
38 WARNING = "warning"
40 # types
41 ABORTRETRYIGNORE = "abortretryignore"
42 OK = "ok"
43 OKCANCEL = "okcancel"
44 RETRYCANCEL = "retrycancel"
45 YESNO = "yesno"
46 YESNOCANCEL = "yesnocancel"
48 # replies
49 ABORT = "abort"
50 RETRY = "retry"
51 IGNORE = "ignore"
52 OK = "ok"
53 CANCEL = "cancel"
54 YES = "yes"
55 NO = "no"
59 # message dialog class
61 class Message(Dialog):
62 "A message box"
64 command = "tk_messageBox"
68 # convenience stuff
70 def _show(title=None, message=None, icon=None, type=None, **options):
71 if icon: options["icon"] = icon
72 if type: options["type"] = type
73 if title: options["title"] = title
74 if message: options["message"] = message
75 return apply(Message, (), options).show()
77 def showinfo(title=None, message=None, **options):
78 "Show an info message"
79 return apply(_show, (title, message, INFO, OK), options)
81 def showwarning(title=None, message=None, **options):
82 "Show a warning message"
83 return apply(_show, (title, message, WARNING, OK), options)
85 def showerror(title=None, message=None, **options):
86 "Show an error message"
87 return apply(_show, (title, message, ERROR, OK), options)
89 def askquestion(title=None, message=None, **options):
90 "Ask a question"
91 return apply(_show, (title, message, QUESTION, YESNO), options)
93 def askokcancel(title=None, message=None, **options):
94 "Ask if operation should proceed; return true if the answer is ok"
95 s = apply(_show, (title, message, QUESTION, OKCANCEL), options)
96 return s == OK
98 def askyesno(title=None, message=None, **options):
99 "Ask a question; return true if the answer is yes"
100 s = apply(_show, (title, message, QUESTION, YESNO), options)
101 return s == YES
103 def askretrycancel(title=None, message=None, **options):
104 "Ask if operation should be retried; return true if the answer is yes"
105 s = apply(_show, (title, message, WARNING, RETRYCANCEL), options)
106 return s == RETRY
109 # --------------------------------------------------------------------
110 # test stuff
112 if __name__ == "__main__":
114 print "info", showinfo("Spam", "Egg Information")
115 print "warning", showwarning("Spam", "Egg Warning")
116 print "error", showerror("Spam", "Egg Alert")
117 print "question", askquestion("Spam", "Question?")
118 print "proceed", askokcancel("Spam", "Proceed?")
119 print "yes/no", askyesno("Spam", "Got it?")
120 print "try again", askretrycancel("Spam", "Try again?")