Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cc38688

Browse files
committed
Updated Message, question, YNC and progress dialogs for Appearance. Password
remains to be done, and maybe we should convert everything to movablemodal too and make things like question look nicer.
1 parent 2d76c25 commit cc38688

2 files changed

Lines changed: 33 additions & 47 deletions

File tree

Mac/Lib/EasyDialogs.py

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
bar.label( *newlabel ) -- get or set text label.
1111
1212
More documentation in each function.
13-
This module uses DLOG resources 256, 257 and 258.
13+
This module uses DLOG resources 260 and on.
1414
Based upon STDWIN dialogs with the same names and functions.
1515
"""
1616

@@ -35,7 +35,7 @@ def lf2cr(text):
3535
text = text[:253] + '\311'
3636
return text
3737

38-
def Message(msg, id=256, ok=None):
38+
def Message(msg, id=260, ok=None):
3939
"""Display a MESSAGE string.
4040
4141
Return when the user clicks the OK button or presses Return.
@@ -47,19 +47,19 @@ def Message(msg, id=256, ok=None):
4747
if not d:
4848
print "Can't get DLOG resource with id =", id
4949
return
50-
tp, h, rect = d.GetDialogItem(2)
50+
h = d.GetDialogItemAsControl(2)
5151
SetDialogItemText(h, lf2cr(msg))
5252
if ok != None:
53-
tp, h, rect = d.GetDialogItem(1)
54-
h.as_Control().SetControlTitle(ok)
53+
h = d.GetDialogItemAsControl(1)
54+
h.SetControlTitle(ok)
5555
d.SetDialogDefaultItem(1)
5656
while 1:
5757
n = ModalDialog(None)
5858
if n == 1:
5959
return
6060

6161

62-
def AskString(prompt, default = "", id=257, ok=None, cancel=None):
62+
def AskString(prompt, default = "", id=261, ok=None, cancel=None):
6363
"""Display a PROMPT string and a text entry field with a DEFAULT string.
6464
6565
Return the contents of the text entry field when the user clicks the
@@ -76,28 +76,28 @@ def AskString(prompt, default = "", id=257, ok=None, cancel=None):
7676
if not d:
7777
print "Can't get DLOG resource with id =", id
7878
return
79-
tp, h, rect = d.GetDialogItem(3)
79+
h = d.GetDialogItemAsControl(3)
8080
SetDialogItemText(h, lf2cr(prompt))
81-
tp, h, rect = d.GetDialogItem(4)
81+
h = d.GetDialogItemAsControl(4)
8282
SetDialogItemText(h, lf2cr(default))
8383
d.SelectDialogItemText(4, 0, 999)
8484
# d.SetDialogItem(4, 0, 255)
8585
if ok != None:
86-
tp, h, rect = d.GetDialogItem(1)
87-
h.as_Control().SetControlTitle(ok)
86+
h = d.GetDialogItemAsControl(1)
87+
h.SetControlTitle(ok)
8888
if cancel != None:
89-
tp, h, rect = d.GetDialogItem(2)
90-
h.as_Control().SetControlTitle(cancel)
89+
h = d.GetDialogItemAsControl(2)
90+
h.SetControlTitle(cancel)
9191
d.SetDialogDefaultItem(1)
9292
d.SetDialogCancelItem(2)
9393
while 1:
9494
n = ModalDialog(None)
9595
if n == 1:
96-
tp, h, rect = d.GetDialogItem(4)
96+
h = d.GetDialogItemAsControl(4)
9797
return cr2lf(GetDialogItemText(h))
9898
if n == 2: return None
9999

100-
def AskPassword(prompt, default='', id=257):
100+
def AskPassword(prompt, default='', id=264):
101101
"""Display a PROMPT string and a text entry field with a DEFAULT string.
102102
The string is displayed as bullets only.
103103
@@ -114,9 +114,9 @@ def AskPassword(prompt, default='', id=257):
114114
if not d:
115115
print "Can't get DLOG resource with id =", id
116116
return
117-
tp, h, rect = d.GetDialogItem(3) # STATIC TEXT ITEM <= prompt
117+
h = d.GetDialogItemAsControl(3) # STATIC TEXT ITEM <= prompt
118118
SetDialogItemText(h, lf2cr(prompt))
119-
tp, h, rect = d.GetDialogItem(4) # EDIT TEXT ITEM
119+
h = d.GetDialogItemAsControl(4) # EDIT TEXT ITEM
120120
bullets = '\245'*len(default)
121121
SetDialogItemText(h, bullets )
122122
d.SelectDialogItemText(4, 999, 999)
@@ -167,7 +167,7 @@ def AskPassword(prompt, default='', id=257):
167167
apply(MacOS.SchedParams, oldschedparams)
168168
return string
169169

170-
def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=258):
170+
def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262):
171171
"""Display a QUESTION string which can be answered with Yes or No.
172172
173173
Return 1 when the user clicks the Yes button.
@@ -190,20 +190,20 @@ def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=258
190190
# 3 = No
191191
# 4 = Cancel
192192
# The question string is item 5
193-
tp, h, rect = d.GetDialogItem(5)
193+
h = d.GetDialogItemAsControl(5)
194194
SetDialogItemText(h, lf2cr(question))
195195
if yes != None:
196-
tp, h, rect = d.GetDialogItem(2)
197-
h.as_Control().SetControlTitle(yes)
196+
h = d.GetDialogItemAsControl(2)
197+
h.SetControlTitle(yes)
198198
if no != None:
199-
tp, h, rect = d.GetDialogItem(3)
200-
h.as_Control().SetControlTitle(no)
199+
h = d.GetDialogItemAsControl(3)
200+
h.SetControlTitle(no)
201201
if cancel != None:
202202
if cancel == '':
203203
d.HideDialogItem(4)
204204
else:
205-
tp, h, rect = d.GetDialogItem(4)
206-
h.as_Control().SetControlTitle(cancel)
205+
h = d.GetDialogItemAsControl(4)
206+
h.SetControlTitle(cancel)
207207
d.SetDialogCancelItem(4)
208208
if default == 1:
209209
d.SetDialogDefaultItem(2)
@@ -227,13 +227,14 @@ def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=258
227227

228228

229229
class ProgressBar:
230-
def __init__(self, title="Working...", maxval=100, label="", id=259):
230+
def __init__(self, title="Working...", maxval=100, label="", id=263):
231231
self.maxval = maxval
232232
self.curval = -1
233233
self.d = GetNewDialog(id, -1)
234234
self.title(title)
235235
self.label(label)
236236
self._update(0)
237+
self.d.DrawDialog()
237238

238239
def __del__( self ):
239240
self.d.BringToFront()
@@ -251,7 +252,7 @@ def label( self, *newstr ):
251252
self.d.BringToFront()
252253
if newstr:
253254
self._label = lf2cr(newstr[0])
254-
tp, text_h, rect = self.d.GetDialogItem(2)
255+
text_h = self.d.GetDialogItemAsControl(2)
255256
SetDialogItemText(text_h, self._label)
256257

257258
def _update(self, value):
@@ -260,27 +261,12 @@ def _update(self, value):
260261
# XXXX Quick fix. Should probably display an unknown duration
261262
value = 0
262263
maxval = 1
263-
self.d.BringToFront()
264-
tp, h, bar_rect = self.d.GetDialogItem(3)
265-
Qd.SetPort(self.d)
266-
267-
Qd.FrameRect(bar_rect) # Draw outline
268-
269-
inner_rect = Qd.InsetRect(bar_rect, 1, 1)
270-
l, t, r, b = inner_rect
271-
272-
Qd.ForeColor(QuickDraw.blackColor)
273-
Qd.BackColor(QuickDraw.blackColor)
274-
Qd.PaintRect((l, t, int(l + (r-l)*value/maxval), b)) # Draw bar
275-
276-
Qd.ForeColor(QuickDraw.whiteColor)
277-
Qd.BackColor(QuickDraw.whiteColor)
278-
Qd.PaintRect((int(l + (r-l)*value/maxval), t, r, b)) # Clear rest
279-
280-
# Restore settings
281-
Qd.ForeColor(QuickDraw.blackColor)
282-
Qd.BackColor(QuickDraw.whiteColor)
283-
264+
if maxval > 32767:
265+
value = int(value/(maxval/32767.0))
266+
maxval = 32767
267+
progbar = self.d.GetDialogItemAsControl(3)
268+
progbar.SetControlMaximum(maxval)
269+
progbar.SetControlValue(value)
284270
# Test for cancel button
285271

286272
ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1 )

Mac/Resources/dialogs.rsrc

228 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)