summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2001-08-27 15:24:07 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2001-08-27 15:24:07 (GMT)
commit911e87de6f283e2326422c6746dd296511368a76 (patch)
tree14965e66895164dd270b80054f6edfdea1b28654 /Mac
parente259e5980c0a0889024ee99e4879a80fa8cd2086 (diff)
downloadcpython-911e87de6f283e2326422c6746dd296511368a76.zip
cpython-911e87de6f283e2326422c6746dd296511368a76.tar.gz
cpython-911e87de6f283e2326422c6746dd296511368a76.tar.bz2
Patch by Dean Draayer: support for indeterminate progress bars. You
get these by specifying maxval=0, which is now also the default. Untested.
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Lib/EasyDialogs.py64
1 files changed, 37 insertions, 27 deletions
diff --git a/Mac/Lib/EasyDialogs.py b/Mac/Lib/EasyDialogs.py
index 68ad58e..277d6d0 100644
--- a/Mac/Lib/EasyDialogs.py
+++ b/Mac/Lib/EasyDialogs.py
@@ -214,19 +214,19 @@ screenbounds = Qd.qd.screenBits.bounds
screenbounds = screenbounds[0]+4, screenbounds[1]+4, \
screenbounds[2]-4, screenbounds[3]-4
-
+kControlProgressBarIndeterminateTag = 'inde' # from Controls.py
+
+
class ProgressBar:
- def __init__(self, title="Working...", maxval=100, label="", id=263):
+ def __init__(self, title="Working...", maxval=0, label="", id=263):
self.w = None
self.d = None
- self.maxval = maxval
- self.curval = -1
self.d = GetNewDialog(id, -1)
self.w = self.d.GetDialogWindow()
self.label(label)
- self._update(0)
- self.d.AutoSizeDialog()
self.title(title)
+ self.set(0, maxval)
+ self.d.AutoSizeDialog()
self.w.ShowWindow()
self.d.DrawDialog()
@@ -248,24 +248,23 @@ class ProgressBar:
if newstr:
self._label = lf2cr(newstr[0])
text_h = self.d.GetDialogItemAsControl(2)
- SetDialogItemText(text_h, self._label)
-
+ SetDialogItemText(text_h, self._label)
+
def _update(self, value):
maxval = self.maxval
- if maxval == 0:
- # XXXX Quick fix. Should probably display an unknown duration
- value = 0
- maxval = 1
- if maxval > 32767:
- value = int(value/(maxval/32767.0))
- maxval = 32767
- progbar = self.d.GetDialogItemAsControl(3)
- progbar.SetControlMaximum(maxval)
- progbar.SetControlValue(value)
+ if maxval == 0: # an indeterminate bar
+ Ctl.IdleControls(self.w) # spin the barber pole
+ else: # a determinate bar
+ if maxval > 32767:
+ value = int(value/(maxval/32767.0))
+ maxval = 32767
+ progbar = self.d.GetDialogItemAsControl(3)
+ progbar.SetControlMaximum(maxval)
+ progbar.SetControlValue(value) # set the bar length
+
# Test for cancel button
-
ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1 )
- if ready :
+ if ready :
what,msg,when,where,mod = ev
part = Win.FindWindow(where)[0]
if Dlg.IsDialogEvent(ev):
@@ -286,8 +285,15 @@ class ProgressBar:
"""set(value) - Set progress bar position"""
if max != None:
self.maxval = max
- if value < 0: value = 0
- if value > self.maxval: value = self.maxval
+ bar = self.d.GetDialogItemAsControl(3)
+ if max <= 0: # indeterminate bar
+ bar.SetControlData(0,kControlProgressBarIndeterminateTag,'\x01')
+ else: # determinate bar
+ bar.SetControlData(0,kControlProgressBarIndeterminateTag,'\x00')
+ if value < 0:
+ value = 0
+ elif value > self.maxval:
+ value = self.maxval
self.curval = value
self._update(value)
@@ -540,18 +546,22 @@ def test():
Message("%s has no secret nickname"%s)
else:
Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2))
- text = ( "Working Hard...", "Hardly Working..." ,
+ text = ( "Working Hard...", "Hardly Working..." ,
"So far, so good!", "Keep on truckin'" )
- bar = ProgressBar("Progress, progress...", 100)
+ bar = ProgressBar("Progress, progress...", 0, label="Ramping up...")
try:
appsw = MacOS.SchedParams(1, 0)
- for i in range(100):
+ for i in xrange(20):
+ bar.inc()
+ time.sleep(0.05)
+ bar.set(0,100)
+ for i in xrange(100):
bar.set(i)
- time.sleep(0.1)
+ time.sleep(0.05)
if i % 10 == 0:
bar.label(text[(i/10) % 4])
bar.label("Done.")
- time.sleep(0.3) # give'em a chance to see the done.
+ time.sleep(1.0) # give'em a chance to see "Done."
finally:
del bar
apply(MacOS.SchedParams, appsw)