[Pythonmac-SIG] OS8/AppearanceMgr-savvy ProgressBar [was: new EasyDialogs]
Steven D. Majewski
sdm7g@virginia.edu
Fri, 5 Mar 1999 15:27:54 -0500 (EST)
To add an OS8/AppearanceMgr-savvy Progress indicator to a dialog,
you need to add a CNTL resource, with a ProcID that is the CDEF
for the progress indicator, and put this CNTL into the DITL for
the DLOG:
DLOG -> DITL -> CNTL,
CNTL.ProcID = CDEF for Progress Indicator = 80 ( 5 * 16 )
The visual update becomes a lot simpler. Once the control max
is set, you just have to call SetControlValue().
Having to require new resources for Python code snippets is a bit of a
pain (and having things defined in a separate resource isn't as much
of a gain for Python as it is for compiled C/C++).
I was trying to figure out how to do it all from Code but I got
stumped in a couple of places. AppendDITL can add items to the dialog,
but the have to be in a DITL, and the path to get from an object
(like the Control returned by NewControl) to a (DITL) resource isn't
very clear.
I found a way that seems to punt around that, but I'm not sure how
kosher it is.
I get the user-item from the existing progress dialog:
useri = self.d.GetDialogItem(3)
create a new control in the dialog window with the rect from
that user-item:
self.c = Ctl.NewControl( self.d, useri[2],"ProgressBar", 1, 0, 0,
self.maxval, 80, 0 )
[ 80 is CDEF for progress indicator )
and reset the dialog item to the new control:
self.d.SetDialogItem( 3, 3, self.c.as_Resource(),useri[2] )
[ second 3 indicates item is a Control. ]
The last step is probably not necessary for this in Python, as the
control is kept in a instance var, and you don't need to fetch it
from the dialog item, however, I'm trying to see if that works in
general for controls, or do you have to go back to ResEdit to
do this sort of patch. ( I'll have to try it on a control that
has some event interaction to find out though, as progress indicator
is just output -- which is why that last step is prob. not required.)
Here's an unguaranteed, minimally tested addition to the newdlg code
that puts up a Real OS8 progress bar. ( I also changed the test
code to call AMProgressBar() creator rather than ProgressBar(). )
import Ctl
class AMProgressBar(ProgressBar):
def __init__(self, title="Working...", maxval=100, label="",id=259 ):
self.maxval = maxval
self.curval = 0
self.d = GetNewDialog(id, -1)
useri = self.d.GetDialogItem(3)
self.c = Ctl.NewControl( self.d, useri[2],"ProgressBar", 1, 0, 0, self.maxval, 80, 0 )
self.d.SetDialogItem( 3, 3, self.c.as_Resource(),useri[2] )
self.title(title)
self.label(label)
self.d.DrawDialog()
self.appsw = MacOS.SchedParams(1, 0)
def _update(self,value):
self.c.SetControlValue(value)
# Test for cancel button
if Handle1Event( self.d, None, 1 ) == 1:
raise KeyboardInterrupt, 'Cancel'
---| Steven D. Majewski (804-982-0831) <sdm7g@Virginia.EDU> |---
---| Department of Molecular Physiology and Biological Physics |---
---| University of Virginia Health Sciences Center |---
---| P.O. Box 10011 Charlottesville, VA 22906-0011 |---
Caldera Open Linux: "Powerful and easy to use!" -- Microsoft(*)
(*) <http://www.pathfinder.com/fortune/1999/03/01/mic.html>