Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 1 | """Easy to use dialogs. |
| 2 | |
| 3 | Message(msg) -- display a message and an OK button. |
| 4 | AskString(prompt, default) -- ask for a string, display OK and Cancel buttons. |
Just van Rossum | cdcc0f0 | 1999-02-15 00:04:05 +0000 | [diff] [blame] | 5 | AskPassword(prompt, default) -- like AskString(), but shows text as bullets. |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 6 | AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons. |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 7 | bar = Progress(label, maxvalue) -- Display a progress bar |
| 8 | bar.set(value) -- Set value |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 9 | bar.inc( *amount ) -- increment value by amount (default=1) |
| 10 | bar.label( *newlabel ) -- get or set text label. |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 11 | |
| 12 | More documentation in each function. |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 13 | This module uses DLOG resources 260 and on. |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 14 | Based upon STDWIN dialogs with the same names and functions. |
| 15 | """ |
| 16 | |
Jack Jansen | e4b4038 | 1995-07-17 13:25:15 +0000 | [diff] [blame] | 17 | from Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 18 | import Qd |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 19 | import QuickDraw |
Jack Jansen | b92268a | 1999-02-10 22:38:44 +0000 | [diff] [blame] | 20 | import Dialogs |
| 21 | import Windows |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 22 | import Dlg,Win,Evt,Events # sdm7g |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 23 | import Ctl |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 24 | import MacOS |
| 25 | import string |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 26 | from ControlAccessor import * # Also import Controls constants |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 27 | |
| 28 | def cr2lf(text): |
| 29 | if '\r' in text: |
| 30 | text = string.join(string.split(text, '\r'), '\n') |
| 31 | return text |
| 32 | |
| 33 | def lf2cr(text): |
| 34 | if '\n' in text: |
| 35 | text = string.join(string.split(text, '\n'), '\r') |
Jack Jansen | d5af7bd | 1998-09-28 10:37:08 +0000 | [diff] [blame] | 36 | if len(text) > 253: |
| 37 | text = text[:253] + '\311' |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 38 | return text |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 39 | |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 40 | def Message(msg, id=260, ok=None): |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 41 | """Display a MESSAGE string. |
| 42 | |
| 43 | Return when the user clicks the OK button or presses Return. |
| 44 | |
| 45 | The MESSAGE string can be at most 255 characters long. |
| 46 | """ |
| 47 | |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 48 | d = GetNewDialog(id, -1) |
| 49 | if not d: |
| 50 | print "Can't get DLOG resource with id =", id |
| 51 | return |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 52 | h = d.GetDialogItemAsControl(2) |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 53 | SetDialogItemText(h, lf2cr(msg)) |
Jack Jansen | 208c15a | 1999-02-16 16:06:39 +0000 | [diff] [blame] | 54 | if ok != None: |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 55 | h = d.GetDialogItemAsControl(1) |
| 56 | h.SetControlTitle(ok) |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 57 | d.SetDialogDefaultItem(1) |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 58 | while 1: |
| 59 | n = ModalDialog(None) |
| 60 | if n == 1: |
| 61 | return |
| 62 | |
| 63 | |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 64 | def AskString(prompt, default = "", id=261, ok=None, cancel=None): |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 65 | """Display a PROMPT string and a text entry field with a DEFAULT string. |
| 66 | |
| 67 | Return the contents of the text entry field when the user clicks the |
| 68 | OK button or presses Return. |
| 69 | Return None when the user clicks the Cancel button. |
| 70 | |
| 71 | If omitted, DEFAULT is empty. |
| 72 | |
| 73 | The PROMPT and DEFAULT strings, as well as the return value, |
| 74 | can be at most 255 characters long. |
| 75 | """ |
| 76 | |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 77 | d = GetNewDialog(id, -1) |
| 78 | if not d: |
| 79 | print "Can't get DLOG resource with id =", id |
| 80 | return |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 81 | h = d.GetDialogItemAsControl(3) |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 82 | SetDialogItemText(h, lf2cr(prompt)) |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 83 | h = d.GetDialogItemAsControl(4) |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 84 | SetDialogItemText(h, lf2cr(default)) |
Jack Jansen | d61f92b | 1999-01-22 13:14:06 +0000 | [diff] [blame] | 85 | d.SelectDialogItemText(4, 0, 999) |
Jack Jansen | e4b4038 | 1995-07-17 13:25:15 +0000 | [diff] [blame] | 86 | # d.SetDialogItem(4, 0, 255) |
Jack Jansen | 208c15a | 1999-02-16 16:06:39 +0000 | [diff] [blame] | 87 | if ok != None: |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 88 | h = d.GetDialogItemAsControl(1) |
| 89 | h.SetControlTitle(ok) |
Jack Jansen | 208c15a | 1999-02-16 16:06:39 +0000 | [diff] [blame] | 90 | if cancel != None: |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 91 | h = d.GetDialogItemAsControl(2) |
| 92 | h.SetControlTitle(cancel) |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 93 | d.SetDialogDefaultItem(1) |
| 94 | d.SetDialogCancelItem(2) |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 95 | while 1: |
| 96 | n = ModalDialog(None) |
| 97 | if n == 1: |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 98 | h = d.GetDialogItemAsControl(4) |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 99 | return cr2lf(GetDialogItemText(h)) |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 100 | if n == 2: return None |
| 101 | |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 102 | def AskPassword(prompt, default='', id=264, ok=None, cancel=None): |
Jack Jansen | b92268a | 1999-02-10 22:38:44 +0000 | [diff] [blame] | 103 | """Display a PROMPT string and a text entry field with a DEFAULT string. |
| 104 | The string is displayed as bullets only. |
| 105 | |
| 106 | Return the contents of the text entry field when the user clicks the |
| 107 | OK button or presses Return. |
| 108 | Return None when the user clicks the Cancel button. |
| 109 | |
| 110 | If omitted, DEFAULT is empty. |
| 111 | |
| 112 | The PROMPT and DEFAULT strings, as well as the return value, |
| 113 | can be at most 255 characters long. |
| 114 | """ |
| 115 | d = GetNewDialog(id, -1) |
| 116 | if not d: |
| 117 | print "Can't get DLOG resource with id =", id |
| 118 | return |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 119 | h = d.GetDialogItemAsControl(3) |
Jack Jansen | b92268a | 1999-02-10 22:38:44 +0000 | [diff] [blame] | 120 | SetDialogItemText(h, lf2cr(prompt)) |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 121 | pwd = d.GetDialogItemAsControl(4) |
Jack Jansen | b92268a | 1999-02-10 22:38:44 +0000 | [diff] [blame] | 122 | bullets = '\245'*len(default) |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 123 | ## SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets) |
| 124 | SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag, default) |
| 125 | d.SelectDialogItemText(4, 0, 999) |
| 126 | Ctl.SetKeyboardFocus(d, pwd, kControlEditTextPart) |
| 127 | if ok != None: |
| 128 | h = d.GetDialogItemAsControl(1) |
| 129 | h.SetControlTitle(ok) |
| 130 | if cancel != None: |
| 131 | h = d.GetDialogItemAsControl(2) |
| 132 | h.SetControlTitle(cancel) |
Jack Jansen | b92268a | 1999-02-10 22:38:44 +0000 | [diff] [blame] | 133 | d.SetDialogDefaultItem(Dialogs.ok) |
| 134 | d.SetDialogCancelItem(Dialogs.cancel) |
Jack Jansen | b92268a | 1999-02-10 22:38:44 +0000 | [diff] [blame] | 135 | while 1: |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 136 | n = ModalDialog(None) |
| 137 | if n == 1: |
| 138 | h = d.GetDialogItemAsControl(4) |
| 139 | return cr2lf(GetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag)) |
| 140 | if n == 2: return None |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 141 | |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 142 | def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262): |
Jack Jansen | cf2efc6 | 1999-02-25 22:05:45 +0000 | [diff] [blame] | 143 | """Display a QUESTION string which can be answered with Yes or No. |
| 144 | |
| 145 | Return 1 when the user clicks the Yes button. |
| 146 | Return 0 when the user clicks the No button. |
| 147 | Return -1 when the user clicks the Cancel button. |
| 148 | |
| 149 | When the user presses Return, the DEFAULT value is returned. |
| 150 | If omitted, this is 0 (No). |
| 151 | |
| 152 | The QUESTION strign ca be at most 255 characters. |
| 153 | """ |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 154 | |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 155 | d = GetNewDialog(id, -1) |
| 156 | if not d: |
| 157 | print "Can't get DLOG resource with id =", id |
| 158 | return |
| 159 | # Button assignments: |
| 160 | # 1 = default (invisible) |
| 161 | # 2 = Yes |
| 162 | # 3 = No |
| 163 | # 4 = Cancel |
| 164 | # The question string is item 5 |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 165 | h = d.GetDialogItemAsControl(5) |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 166 | SetDialogItemText(h, lf2cr(question)) |
Jack Jansen | 3f5aef7 | 1997-06-20 16:23:37 +0000 | [diff] [blame] | 167 | if yes != None: |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 168 | h = d.GetDialogItemAsControl(2) |
| 169 | h.SetControlTitle(yes) |
Jack Jansen | 3f5aef7 | 1997-06-20 16:23:37 +0000 | [diff] [blame] | 170 | if no != None: |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 171 | h = d.GetDialogItemAsControl(3) |
| 172 | h.SetControlTitle(no) |
Jack Jansen | 3f5aef7 | 1997-06-20 16:23:37 +0000 | [diff] [blame] | 173 | if cancel != None: |
Jack Jansen | 208c15a | 1999-02-16 16:06:39 +0000 | [diff] [blame] | 174 | if cancel == '': |
| 175 | d.HideDialogItem(4) |
| 176 | else: |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 177 | h = d.GetDialogItemAsControl(4) |
| 178 | h.SetControlTitle(cancel) |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 179 | d.SetDialogCancelItem(4) |
Jack Jansen | 0b690db | 1996-04-10 14:49:41 +0000 | [diff] [blame] | 180 | if default == 1: |
| 181 | d.SetDialogDefaultItem(2) |
| 182 | elif default == 0: |
| 183 | d.SetDialogDefaultItem(3) |
| 184 | elif default == -1: |
| 185 | d.SetDialogDefaultItem(4) |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 186 | while 1: |
| 187 | n = ModalDialog(None) |
| 188 | if n == 1: return default |
| 189 | if n == 2: return 1 |
| 190 | if n == 3: return 0 |
| 191 | if n == 4: return -1 |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 192 | |
| 193 | |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 194 | |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 195 | |
| 196 | screenbounds = Qd.qd.screenBits.bounds |
| 197 | screenbounds = screenbounds[0]+4, screenbounds[1]+4, \ |
| 198 | screenbounds[2]-4, screenbounds[3]-4 |
| 199 | |
| 200 | |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 201 | class ProgressBar: |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 202 | def __init__(self, title="Working...", maxval=100, label="", id=263): |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 203 | self.maxval = maxval |
| 204 | self.curval = -1 |
Jack Jansen | 3f5aef7 | 1997-06-20 16:23:37 +0000 | [diff] [blame] | 205 | self.d = GetNewDialog(id, -1) |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 206 | self.title(title) |
| 207 | self.label(label) |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 208 | self._update(0) |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 209 | self.d.DrawDialog() |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 210 | |
| 211 | def __del__( self ): |
Jack Jansen | 48c5527 | 1997-05-13 15:41:07 +0000 | [diff] [blame] | 212 | self.d.BringToFront() |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 213 | self.d.HideWindow() |
| 214 | del self.d |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 215 | |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 216 | def title(self, newstr=""): |
| 217 | """title(text) - Set title of progress window""" |
Jack Jansen | 48c5527 | 1997-05-13 15:41:07 +0000 | [diff] [blame] | 218 | self.d.BringToFront() |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 219 | w = self.d.GetDialogWindow() |
| 220 | w.SetWTitle(newstr) |
| 221 | |
| 222 | def label( self, *newstr ): |
| 223 | """label(text) - Set text in progress box""" |
Jack Jansen | 48c5527 | 1997-05-13 15:41:07 +0000 | [diff] [blame] | 224 | self.d.BringToFront() |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 225 | if newstr: |
Jack Jansen | a5a4981 | 1998-07-01 15:47:44 +0000 | [diff] [blame] | 226 | self._label = lf2cr(newstr[0]) |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 227 | text_h = self.d.GetDialogItemAsControl(2) |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 228 | SetDialogItemText(text_h, self._label) |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 229 | |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 230 | def _update(self, value): |
Jack Jansen | 58fa818 | 1999-11-05 15:53:10 +0000 | [diff] [blame] | 231 | maxval = self.maxval |
| 232 | if maxval == 0: |
| 233 | # XXXX Quick fix. Should probably display an unknown duration |
| 234 | value = 0 |
| 235 | maxval = 1 |
Jack Jansen | cc38688 | 1999-12-12 22:57:51 +0000 | [diff] [blame] | 236 | if maxval > 32767: |
| 237 | value = int(value/(maxval/32767.0)) |
| 238 | maxval = 32767 |
| 239 | progbar = self.d.GetDialogItemAsControl(3) |
| 240 | progbar.SetControlMaximum(maxval) |
| 241 | progbar.SetControlValue(value) |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 242 | # Test for cancel button |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 243 | |
| 244 | ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1 ) |
| 245 | if ready : |
| 246 | what,msg,when,where,mod = ev |
| 247 | part = Win.FindWindow(where)[0] |
| 248 | if Dlg.IsDialogEvent(ev): |
| 249 | ds = Dlg.DialogSelect(ev) |
| 250 | if ds[0] and ds[1] == self.d and ds[-1] == 1: |
| 251 | raise KeyboardInterrupt, ev |
| 252 | else: |
| 253 | if part == 4: # inDrag |
| 254 | self.d.DragWindow(where, screenbounds) |
| 255 | else: |
| 256 | MacOS.HandleEvent(ev) |
| 257 | |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 258 | |
Jack Jansen | 58fa818 | 1999-11-05 15:53:10 +0000 | [diff] [blame] | 259 | def set(self, value, max=None): |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 260 | """set(value) - Set progress bar position""" |
Jack Jansen | 58fa818 | 1999-11-05 15:53:10 +0000 | [diff] [blame] | 261 | if max != None: |
| 262 | self.maxval = max |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 263 | if value < 0: value = 0 |
| 264 | if value > self.maxval: value = self.maxval |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 265 | self.curval = value |
Jack Jansen | 3a87f5b | 1995-11-14 10:13:49 +0000 | [diff] [blame] | 266 | self._update(value) |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 267 | |
| 268 | def inc(self, n=1): |
| 269 | """inc(amt) - Increment progress bar position""" |
| 270 | self.set(self.curval + n) |
| 271 | |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 272 | def test(): |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 273 | import time |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 274 | |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 275 | Message("Testing EasyDialogs.") |
| 276 | ok = AskYesNoCancel("Do you want to proceed?") |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 277 | ok = AskYesNoCancel("Do you want to identify?", yes="Identify", no="No") |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 278 | if ok > 0: |
Jack Jansen | d61f92b | 1999-01-22 13:14:06 +0000 | [diff] [blame] | 279 | s = AskString("Enter your first name", "Joe") |
Jack Jansen | 60429e0 | 1999-12-13 16:07:01 +0000 | [diff] [blame] | 280 | s2 = AskPassword("Okay %s, tell us your nickname"%s, s, cancel="None") |
| 281 | if not s2: |
| 282 | Message("%s has no secret nickname"%s) |
| 283 | else: |
| 284 | Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2)) |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 285 | text = ( "Working Hard...", "Hardly Working..." , |
| 286 | "So far, so good!", "Keep on truckin'" ) |
| 287 | bar = ProgressBar("Progress, progress...", 100) |
| 288 | try: |
Jack Jansen | 3368cb7 | 1997-06-12 10:51:18 +0000 | [diff] [blame] | 289 | appsw = MacOS.SchedParams(1, 0) |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 290 | for i in range(100): |
| 291 | bar.set(i) |
| 292 | time.sleep(0.1) |
| 293 | if i % 10 == 0: |
| 294 | bar.label(text[(i/10) % 4]) |
| 295 | bar.label("Done.") |
| 296 | time.sleep(0.3) # give'em a chance to see the done. |
| 297 | finally: |
| 298 | del bar |
Jack Jansen | 3368cb7 | 1997-06-12 10:51:18 +0000 | [diff] [blame] | 299 | apply(MacOS.SchedParams, appsw) |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 300 | |
| 301 | |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 302 | |
| 303 | |
Guido van Rossum | 8f4b6ad | 1995-04-05 09:18:35 +0000 | [diff] [blame] | 304 | if __name__ == '__main__': |
Jack Jansen | 1d63d8c | 1997-05-12 15:44:14 +0000 | [diff] [blame] | 305 | try: |
| 306 | test() |
| 307 | except KeyboardInterrupt: |
| 308 | Message("Operation Canceled.") |
| 309 | |