summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>1995-11-14 10:13:49 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>1995-11-14 10:13:49 (GMT)
commit3a87f5bb09558e8015ed7fed5e71b1bbb17c121d (patch)
tree04abdb5c9ff33db8a3630672fd5dfbac6806d033 /Mac
parente48aa966c1f11ee6d66fc96a92dc4972d52353b8 (diff)
downloadcpython-3a87f5bb09558e8015ed7fed5e71b1bbb17c121d.zip
cpython-3a87f5bb09558e8015ed7fed5e71b1bbb17c121d.tar.gz
cpython-3a87f5bb09558e8015ed7fed5e71b1bbb17c121d.tar.bz2
Added a ProgressBar() class (which shows a progress bar). Needs new
resource.
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Lib/EasyDialogs.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/Mac/Lib/EasyDialogs.py b/Mac/Lib/EasyDialogs.py
index dc668b0..3dfe9f3 100644
--- a/Mac/Lib/EasyDialogs.py
+++ b/Mac/Lib/EasyDialogs.py
@@ -3,6 +3,8 @@
Message(msg) -- display a message and an OK button.
AskString(prompt, default) -- ask for a string, display OK and Cancel buttons.
AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons.
+bar = Progress(label, maxvalue) -- Display a progress bar
+bar.set(value) -- Set value
More documentation in each function.
This module uses DLOG resources 256, 257 and 258.
@@ -10,6 +12,12 @@ Based upon STDWIN dialogs with the same names and functions.
"""
from Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog
+import Qd
+import addpack
+addpack.addpack('Tools')
+addpack.addpack('bgen')
+addpack.addpack('qd')
+import QuickDraw
def Message(msg):
@@ -27,6 +35,7 @@ def Message(msg):
return
tp, h, rect = d.GetDialogItem(2)
SetDialogItemText(h, msg)
+ d.SetDialogDefaultItem(1)
while 1:
n = ModalDialog(None)
if n == 1:
@@ -56,6 +65,8 @@ def AskString(prompt, default = ""):
tp, h, rect = d.GetDialogItem(4)
SetDialogItemText(h, default)
# d.SetDialogItem(4, 0, 255)
+ d.SetDialogDefaultItem(1)
+ d.SetDialogCancelItem(2)
while 1:
n = ModalDialog(None)
if n == 1:
@@ -90,12 +101,60 @@ def AskYesNoCancel(question, default = 0):
# The question string is item 5
tp, h, rect = d.GetDialogItem(5)
SetDialogItemText(h, question)
+ d.SetDialogCancelItem(4)
+ if default in (2, 3, 4):
+ d.SetDialogDefaultItem(default)
while 1:
n = ModalDialog(None)
if n == 1: return default
if n == 2: return 1
if n == 3: return 0
if n == 4: return -1
+
+class ProgressBar:
+ def __init__(self, label="Working...", maxval=100):
+ self.label = label
+ self.maxval = maxval
+ self.curval = -1
+ self.d = GetNewDialog(259, -1)
+ tp, text_h, rect = self.d.GetDialogItem(2)
+ SetDialogItemText(text_h, "Progress...")
+ self._update(0)
+
+ def _update(self, value):
+ tp, h, bar_rect = self.d.GetDialogItem(3)
+ Qd.SetPort(self.d)
+
+ Qd.FrameRect(bar_rect) # Draw outline
+
+ inner_rect = Qd.InsetRect(bar_rect, 1, 1)
+ Qd.ForeColor(QuickDraw.whiteColor)
+ Qd.BackColor(QuickDraw.whiteColor)
+ Qd.PaintRect(inner_rect) # Clear internal
+
+ l, t, r, b = inner_rect
+ r = int(l + (r-l)*value/self.maxval)
+ inner_rect = l, t, r, b
+ Qd.ForeColor(QuickDraw.blackColor)
+ Qd.BackColor(QuickDraw.blackColor)
+ Qd.PaintRect(inner_rect) # Draw bar
+
+ # Restore settings
+ Qd.ForeColor(QuickDraw.blackColor)
+ Qd.BackColor(QuickDraw.whiteColor)
+
+ # Test for cancel button
+ if ModalDialog(self._filterfunc) == 1:
+ raise KeyboardInterrupt
+
+ def _filterfunc(self, d, e, *more):
+ return 2 # XXXX For now, this disables the cancel button
+
+ def set(self, value):
+ if value < 0: value = 0
+ if value > self.maxval: value = self.maxval
+ self._update(value)
+
def test():
@@ -104,6 +163,10 @@ def test():
if ok > 0:
s = AskString("Enter your first name")
Message("Thank you,\015%s" % `s`)
+ bar = ProgressBar("Counting...", 100)
+ for i in range(100):
+ bar.set(i)
+ del bar
if __name__ == '__main__':