1 """Easy to use dialogs.
3 Message(msg) -- display a message and an OK button.
4 AskString(prompt, default) -- ask for a string, display OK and Cancel buttons.
5 AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons.
7 More documentation in each function.
8 This module uses DLOG resources 256, 257 and 258.
9 Based upon STDWIN dialogs with the same names and functions.
12 from Dlg
import GetNewDialog
, SetIText
, GetIText
, ModalDialog
16 """Display a MESSAGE string.
18 Return when the user clicks the OK button or presses Return.
20 The MESSAGE string can be at most 255 characters long.
24 d
= GetNewDialog(id, -1)
26 print "Can't get DLOG resource with id =", id
28 tp
, h
, rect
= d
.GetDItem(2)
36 def AskString(prompt
, default
= ""):
37 """Display a PROMPT string and a text entry field with a DEFAULT string.
39 Return the contents of the text entry field when the user clicks the
40 OK button or presses Return.
41 Return None when the user clicks the Cancel button.
43 If omitted, DEFAULT is empty.
45 The PROMPT and DEFAULT strings, as well as the return value,
46 can be at most 255 characters long.
50 d
= GetNewDialog(id, -1)
52 print "Can't get DLOG resource with id =", id
54 tp
, h
, rect
= d
.GetDItem(3)
56 tp
, h
, rect
= d
.GetDItem(4)
62 tp
, h
, rect
= d
.GetDItem(4)
64 if n
== 2: return None
67 def AskYesNoCancel(question
, default
= 0):
68 ## """Display a QUESTION string which can be answered with Yes or No.
70 ## Return 1 when the user clicks the Yes button.
71 ## Return 0 when the user clicks the No button.
72 ## Return -1 when the user clicks the Cancel button.
74 ## When the user presses Return, the DEFAULT value is returned.
75 ## If omitted, this is 0 (No).
77 ## The QUESTION strign ca be at most 255 characters.
81 d
= GetNewDialog(id, -1)
83 print "Can't get DLOG resource with id =", id
86 # 1 = default (invisible)
90 # The question string is item 5
91 tp
, h
, rect
= d
.GetDItem(5)
95 if n
== 1: return default
102 Message("Testing EasyDialogs.")
103 ok
= AskYesNoCancel("Do you want to proceed?")
105 s
= AskString("Enter your first name")
106 Message("Thank you,\015%s" % `s`
)
109 if __name__
== '__main__':