Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v9 / lib / python2.4 / lib-tk / tkMessageBox.py
CommitLineData
920dae64
AT
1#
2# Instant Python
3# $Id: tkMessageBox.py,v 1.3 2004/09/18 16:01:23 loewis Exp $
4#
5# tk common message boxes
6#
7# this module provides an interface to the native message boxes
8# available in Tk 4.2 and newer.
9#
10# written by Fredrik Lundh, May 1997
11#
12
13#
14# options (all have default values):
15#
16# - default: which button to make default (one of the reply codes)
17#
18# - icon: which icon to display (see below)
19#
20# - message: the message to display
21#
22# - parent: which window to place the dialog on top of
23#
24# - title: dialog title
25#
26# - type: dialog type; that is, which buttons to display (see below)
27#
28
29from tkCommonDialog import Dialog
30
31#
32# constants
33
34# icons
35ERROR = "error"
36INFO = "info"
37QUESTION = "question"
38WARNING = "warning"
39
40# types
41ABORTRETRYIGNORE = "abortretryignore"
42OK = "ok"
43OKCANCEL = "okcancel"
44RETRYCANCEL = "retrycancel"
45YESNO = "yesno"
46YESNOCANCEL = "yesnocancel"
47
48# replies
49ABORT = "abort"
50RETRY = "retry"
51IGNORE = "ignore"
52OK = "ok"
53CANCEL = "cancel"
54YES = "yes"
55NO = "no"
56
57
58#
59# message dialog class
60
61class Message(Dialog):
62 "A message box"
63
64 command = "tk_messageBox"
65
66
67#
68# convenience stuff
69
70def _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 res = Message(**options).show()
76 # In some Tcl installations, Tcl converts yes/no into a boolean
77 if isinstance(res, bool):
78 if res: return YES
79 return NO
80 return res
81
82def showinfo(title=None, message=None, **options):
83 "Show an info message"
84 return _show(title, message, INFO, OK, **options)
85
86def showwarning(title=None, message=None, **options):
87 "Show a warning message"
88 return _show(title, message, WARNING, OK, **options)
89
90def showerror(title=None, message=None, **options):
91 "Show an error message"
92 return _show(title, message, ERROR, OK, **options)
93
94def askquestion(title=None, message=None, **options):
95 "Ask a question"
96 return _show(title, message, QUESTION, YESNO, **options)
97
98def askokcancel(title=None, message=None, **options):
99 "Ask if operation should proceed; return true if the answer is ok"
100 s = _show(title, message, QUESTION, OKCANCEL, **options)
101 return s == OK
102
103def askyesno(title=None, message=None, **options):
104 "Ask a question; return true if the answer is yes"
105 s = _show(title, message, QUESTION, YESNO, **options)
106 return s == YES
107
108def askretrycancel(title=None, message=None, **options):
109 "Ask if operation should be retried; return true if the answer is yes"
110 s = _show(title, message, WARNING, RETRYCANCEL, **options)
111 return s == RETRY
112
113
114# --------------------------------------------------------------------
115# test stuff
116
117if __name__ == "__main__":
118
119 print "info", showinfo("Spam", "Egg Information")
120 print "warning", showwarning("Spam", "Egg Warning")
121 print "error", showerror("Spam", "Egg Alert")
122 print "question", askquestion("Spam", "Question?")
123 print "proceed", askokcancel("Spam", "Proceed?")
124 print "yes/no", askyesno("Spam", "Got it?")
125 print "try again", askretrycancel("Spam", "Try again?")