annotate Mac/Lib/EasyDialogs.py @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents 77d3d3013692
children b96176c9a853
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
1 """Easy to use dialogs.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 Message(msg) -- display a message and an OK button.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
4 AskString(prompt, default) -- ask for a string, display OK and Cancel buttons.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons.
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
6 bar = Progress(label, maxvalue) -- Display a progress bar
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
7 bar.set(value) -- Set value
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
8
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 More documentation in each function.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 This module uses DLOG resources 256, 257 and 258.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 Based upon STDWIN dialogs with the same names and functions.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
13
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
14 from Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
15 import Qd
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
16 import QuickDraw
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 def Message(msg):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 """Display a MESSAGE string.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
21
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 Return when the user clicks the OK button or presses Return.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
23
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 The MESSAGE string can be at most 255 characters long.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
25 """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
26
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
27 id = 256
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
28 d = GetNewDialog(id, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 if not d:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 print "Can't get DLOG resource with id =", id
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 return
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
32 tp, h, rect = d.GetDialogItem(2)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
33 SetDialogItemText(h, msg)
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
34 d.SetDialogDefaultItem(1)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
35 while 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 n = ModalDialog(None)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 if n == 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 return
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
39
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 def AskString(prompt, default = ""):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 """Display a PROMPT string and a text entry field with a DEFAULT string.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
43
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
44 Return the contents of the text entry field when the user clicks the
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 OK button or presses Return.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
46 Return None when the user clicks the Cancel button.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
48 If omitted, DEFAULT is empty.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
49
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
50 The PROMPT and DEFAULT strings, as well as the return value,
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 can be at most 255 characters long.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
54 id = 257
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 d = GetNewDialog(id, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 if not d:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 print "Can't get DLOG resource with id =", id
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 return
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
59 tp, h, rect = d.GetDialogItem(3)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
60 SetDialogItemText(h, prompt)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
61 tp, h, rect = d.GetDialogItem(4)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
62 SetDialogItemText(h, default)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
63 # d.SetDialogItem(4, 0, 255)
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
64 d.SetDialogDefaultItem(1)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
65 d.SetDialogCancelItem(2)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 while 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 n = ModalDialog(None)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 if n == 1:
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
69 tp, h, rect = d.GetDialogItem(4)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
70 return GetDialogItemText(h)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
71 if n == 2: return None
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
72
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 def AskYesNoCancel(question, default = 0):
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
75 ## """Display a QUESTION string which can be answered with Yes or No.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 ##
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
77 ## Return 1 when the user clicks the Yes button.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 ## Return 0 when the user clicks the No button.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
79 ## Return -1 when the user clicks the Cancel button.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
80 ##
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
81 ## When the user presses Return, the DEFAULT value is returned.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 ## If omitted, this is 0 (No).
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
83 ##
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 ## The QUESTION strign ca be at most 255 characters.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 ## """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
86
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
87 id = 258
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
88 d = GetNewDialog(id, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
89 if not d:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
90 print "Can't get DLOG resource with id =", id
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 return
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 # Button assignments:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 # 1 = default (invisible)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
94 # 2 = Yes
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
95 # 3 = No
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
96 # 4 = Cancel
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
97 # The question string is item 5
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
98 tp, h, rect = d.GetDialogItem(5)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
99 SetDialogItemText(h, question)
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
100 d.SetDialogCancelItem(4)
3500
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
101 if default == 1:
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
102 d.SetDialogDefaultItem(2)
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
103 elif default == 0:
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
104 d.SetDialogDefaultItem(3)
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
105 elif default == -1:
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
106 d.SetDialogDefaultItem(4)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
107 while 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
108 n = ModalDialog(None)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
109 if n == 1: return default
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
110 if n == 2: return 1
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
111 if n == 3: return 0
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
112 if n == 4: return -1
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
113
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
114 class ProgressBar:
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
115 def __init__(self, label="Working...", maxval=100):
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
116 self.label = label
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
117 self.maxval = maxval
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
118 self.curval = -1
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
119 self.d = GetNewDialog(259, -1)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
120 tp, text_h, rect = self.d.GetDialogItem(2)
4413
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
121 SetDialogItemText(text_h, label)
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
122 self._update(0)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
123
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
124 def _update(self, value):
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
125 tp, h, bar_rect = self.d.GetDialogItem(3)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
126 Qd.SetPort(self.d)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
127
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
128 Qd.FrameRect(bar_rect) # Draw outline
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
129
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
130 inner_rect = Qd.InsetRect(bar_rect, 1, 1)
4413
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
131 l, t, r, b = inner_rect
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
132
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
133 Qd.ForeColor(QuickDraw.blackColor)
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
134 Qd.BackColor(QuickDraw.blackColor)
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
135 Qd.PaintRect((l, t, int(l + (r-l)*value/self.maxval), b)) # Draw bar
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
136
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
137 Qd.ForeColor(QuickDraw.whiteColor)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
138 Qd.BackColor(QuickDraw.whiteColor)
4413
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
139 Qd.PaintRect((int(l + (r-l)*value/self.maxval), t, r, b)) # Clear rest
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
140
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
141 # Restore settings
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
142 Qd.ForeColor(QuickDraw.blackColor)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
143 Qd.BackColor(QuickDraw.whiteColor)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
144
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
145 # Test for cancel button
4353
aac8a99a1f9c Fixed progressbar cleanup
Jack Jansen <jack.jansen@cwi.nl>
parents: 3500
diff changeset
146 if ModalDialog(_ProgressBar_filterfunc) == 1:
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
147 raise KeyboardInterrupt
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
148
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
149 def set(self, value):
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
150 if value < 0: value = 0
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
151 if value > self.maxval: value = self.maxval
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
152 self._update(value)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
153
4353
aac8a99a1f9c Fixed progressbar cleanup
Jack Jansen <jack.jansen@cwi.nl>
parents: 3500
diff changeset
154 def _ProgressBar_filterfunc(*args):
aac8a99a1f9c Fixed progressbar cleanup
Jack Jansen <jack.jansen@cwi.nl>
parents: 3500
diff changeset
155 return 2 # Disabled, for now.
aac8a99a1f9c Fixed progressbar cleanup
Jack Jansen <jack.jansen@cwi.nl>
parents: 3500
diff changeset
156
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 def test():
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
158 Message("Testing EasyDialogs.")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
159 ok = AskYesNoCancel("Do you want to proceed?")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
160 if ok > 0:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
161 s = AskString("Enter your first name")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 Message("Thank you,\015%s" % `s`)
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
163 bar = ProgressBar("Counting...", 100)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
164 for i in range(100):
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
165 bar.set(i)
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
166 del bar
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
167
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
168
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
169 if __name__ == '__main__':
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
170 test()