annotate Mac/Lib/EasyDialogs.py @ 5817:48b94de85bf3 legacy-trunk

Extensive changes by AMK.
author Guido van Rossum <guido@python.org>
date Thu, 17 Jul 1997 16:29:42 +0000
parents 20e639986fb9
children 66f0540656a0
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
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
8 bar.inc( *amount ) -- increment value by amount (default=1)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
9 bar.label( *newlabel ) -- get or set text label.
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
10
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 More documentation in each function.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 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
13 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
14 """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
16 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
17 import Qd
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
18 import QuickDraw
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
19 import Dlg,Win,Evt,Events # sdm7g
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
20
5749
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
21 def Message(msg, id=256):
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
22 """Display a MESSAGE string.
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 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
25
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 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
27 """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
28
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 d = GetNewDialog(id, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
30 if not d:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 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
32 return
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
33 tp, h, rect = d.GetDialogItem(2)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
34 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
35 d.SetDialogDefaultItem(1)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 while 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
37 n = ModalDialog(None)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 if n == 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 return
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
5749
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
42 def AskString(prompt, default = "", id=257):
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 """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
44
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 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
46 OK button or presses Return.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
47 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
48
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 If omitted, DEFAULT is empty.
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
50
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 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
52 can be at most 255 characters long.
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
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
55 id = 257
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
56 d = GetNewDialog(id, -1)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
57 if not d:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
58 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
59 return
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
60 tp, h, rect = d.GetDialogItem(3)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
61 SetDialogItemText(h, prompt)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
62 tp, h, rect = d.GetDialogItem(4)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
63 SetDialogItemText(h, default)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
64 # 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
65 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
66 d.SetDialogCancelItem(2)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 while 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
68 n = ModalDialog(None)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
69 if n == 1:
2837
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
70 tp, h, rect = d.GetDialogItem(4)
b988a4aca6f9 Various toolbox routines have gotten new names.
Jack Jansen <jack.jansen@cwi.nl>
parents: 2632
diff changeset
71 return GetDialogItemText(h)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
72 if n == 2: return None
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
5749
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
75 def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=258):
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
76 ## """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
77 ##
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
78 ## 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
79 ## 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
80 ## 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
81 ##
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
82 ## 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
83 ## If omitted, this is 0 (No).
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
84 ##
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
85 ## 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
86 ## """
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
87
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)
5749
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
100 if yes != None:
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
101 tp, h, rect = d.GetDialogItem(2)
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
102 h.as_Control().SetControlTitle(yes)
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
103 if no != None:
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
104 tp, h, rect = d.GetDialogItem(3)
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
105 h.as_Control().SetControlTitle(no)
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
106 if cancel != None:
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
107 tp, h, rect = d.GetDialogItem(4)
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
108 h.as_Control().SetControlTitle(cancel)
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
109 d.SetDialogCancelItem(4)
3500
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
110 if default == 1:
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
111 d.SetDialogDefaultItem(2)
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
112 elif default == 0:
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
113 d.SetDialogDefaultItem(3)
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
114 elif default == -1:
eae70d7f2ec7 Added region argument to various ...Update calls.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3467
diff changeset
115 d.SetDialogDefaultItem(4)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
116 while 1:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
117 n = ModalDialog(None)
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
118 if n == 1: return default
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
119 if n == 2: return 1
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
120 if n == 3: return 0
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
121 if n == 4: return -1
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
122
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
123
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
124
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
125
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
126 screenbounds = Qd.qd.screenBits.bounds
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
127 screenbounds = screenbounds[0]+4, screenbounds[1]+4, \
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
128 screenbounds[2]-4, screenbounds[3]-4
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
129
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
130
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
131 class ProgressBar:
5749
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
132 def __init__(self, title="Working...", maxval=100, label="", id=259):
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
133 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
134 self.curval = -1
5749
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
135 self.d = GetNewDialog(id, -1)
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
136 self.title(title)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
137 self.label(label)
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
138 self._update(0)
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
139
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
140 def __del__( self ):
5487
ed0394484082 Add a few more BringToFont calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 5480
diff changeset
141 self.d.BringToFront()
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
142 self.d.HideWindow()
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
143 del self.d
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
144
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
145 def title(self, newstr=""):
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
146 """title(text) - Set title of progress window"""
5487
ed0394484082 Add a few more BringToFont calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 5480
diff changeset
147 self.d.BringToFront()
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
148 w = self.d.GetDialogWindow()
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
149 w.SetWTitle(newstr)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
150
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
151 def label( self, *newstr ):
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
152 """label(text) - Set text in progress box"""
5487
ed0394484082 Add a few more BringToFont calls
Jack Jansen <jack.jansen@cwi.nl>
parents: 5480
diff changeset
153 self.d.BringToFront()
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
154 if newstr:
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
155 self._label = newstr[0]
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
156 tp, text_h, rect = self.d.GetDialogItem(2)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
157 SetDialogItemText(text_h, self._label)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
158
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
159
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
160 def _update(self, value):
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
161 self.d.BringToFront()
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
162 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
163 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
164
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
165 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
166
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
167 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
168 l, t, r, b = inner_rect
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
169
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
170 Qd.ForeColor(QuickDraw.blackColor)
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
171 Qd.BackColor(QuickDraw.blackColor)
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
172 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
173
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
174 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
175 Qd.BackColor(QuickDraw.whiteColor)
4413
77d3d3013692 Fixed flashing in ProgressBar update.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4353
diff changeset
176 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
177
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
178 # Restore settings
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
179 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
180 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
181
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
182 # Test for cancel button
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
183
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
184 ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1 )
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
185 if ready :
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
186 what,msg,when,where,mod = ev
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
187 part = Win.FindWindow(where)[0]
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
188 if Dlg.IsDialogEvent(ev):
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
189 ds = Dlg.DialogSelect(ev)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
190 if ds[0] and ds[1] == self.d and ds[-1] == 1:
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
191 raise KeyboardInterrupt, ev
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
192 else:
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
193 if part == 4: # inDrag
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
194 self.d.DragWindow(where, screenbounds)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
195 else:
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
196 MacOS.HandleEvent(ev)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
197
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
198
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
199 def set(self, value):
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
200 """set(value) - Set progress bar position"""
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
201 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
202 if value > self.maxval: value = self.maxval
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
203 self.curval = value
3252
467e0f2d678a Added a ProgressBar() class (which shows a progress bar). Needs new
Jack Jansen <jack.jansen@cwi.nl>
parents: 2837
diff changeset
204 self._update(value)
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
205
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
206 def inc(self, n=1):
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
207 """inc(amt) - Increment progress bar position"""
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
208 self.set(self.curval + n)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
209
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
210 def test():
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
211 import time
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
212 import MacOS
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
213
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
214 Message("Testing EasyDialogs.")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
215 ok = AskYesNoCancel("Do you want to proceed?")
5749
20e639986fb9 Allow specifying own resources for all dialogs
Jack Jansen <jack.jansen@cwi.nl>
parents: 5735
diff changeset
216 ok = AskYesNoCancel("Do you want to identify?", yes="Indentify", no="Don't identify")
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
217 if ok > 0:
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
218 s = AskString("Enter your first name")
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
219 Message("Thank you,\015%s" % `s`)
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
220 text = ( "Working Hard...", "Hardly Working..." ,
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
221 "So far, so good!", "Keep on truckin'" )
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
222 bar = ProgressBar("Progress, progress...", 100)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
223 try:
5735
634728d8bc98 Replaced MacOS.EnableAppSwitch with MacOS.SchedParams
Jack Jansen <jack.jansen@cwi.nl>
parents: 5487
diff changeset
224 appsw = MacOS.SchedParams(1, 0)
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
225 for i in range(100):
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
226 bar.set(i)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
227 time.sleep(0.1)
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
228 if i % 10 == 0:
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
229 bar.label(text[(i/10) % 4])
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
230 bar.label("Done.")
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
231 time.sleep(0.3) # give'em a chance to see the done.
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
232 finally:
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
233 del bar
5735
634728d8bc98 Replaced MacOS.EnableAppSwitch with MacOS.SchedParams
Jack Jansen <jack.jansen@cwi.nl>
parents: 5487
diff changeset
234 apply(MacOS.SchedParams, appsw)
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
235
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
236
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
237
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
238
2632
75e9e56b5f9b two new modules for the Mac toolbox
Guido van Rossum <guido@python.org>
parents:
diff changeset
239 if __name__ == '__main__':
5480
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
240 try:
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
241 test()
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
242 except KeyboardInterrupt:
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
243 Message("Operation Canceled.")
b96176c9a853 Fixes to progress bar by SDM, modified by Jack:
Jack Jansen <jack.jansen@cwi.nl>
parents: 4413
diff changeset
244