Re: More Help w/ Dialog Director Needed
Re: More Help w/ Dialog Director Needed
- Subject: Re: More Help w/ Dialog Director Needed
- From: Richard Morton <email@hidden>
- Date: Sun, 23 Sep 2001 15:34:02 +1000
Stephen Swift (aka Burnum)'s message of 22/9/01 1:28 PM contained:
>
...If there is a way
>
to get the dialog screen to quit using poly push buttons on auto dialog
>
please let me know, because I'm more familiar using that then the dd install
>
command.
My hunch is no, but the docs are excellent - have you searched them for
this?
>
In dd auto I can set a text field with a value of a variable. The variable
>
can be defined as a property. When the user enters text, it is saved for
>
next time the user runs the script.
>
This doesn't seem to work when I use the dd install method. Every time the
>
dialog is made, the text fields come up blank...
Most of the live examples given by the author declare the dialog
contents, or even the whole dialog itself, as a property. If you have a
string stored as a property - say 'editText' - & use this as the value of
a text field, that text field will display whatever was in 'editText'
when the script was compiled. It will never change unless you change the
string yourself & recompile. Here are two ways of getting around this.
The first is to declare the dialog's contents at run time - 'set dConts
to...' - instead of as a property - 'property dConts...'. As long as the
value of the text field points to the property 'editText', this should
always display whatever has been stored there from the last run.
Declaring the dialog's contents at run time can have disadvantages
sometimes though. It depends what you're doing. I tend to do as much as
possible at compile time to maximise run time speed.
The second is to set the value of the text field itself at runtime. This
can be done before the dialog is drawn, by something like:
set value of item 3 of dConts to editText
or after the dialog is on screen:
dd set value of item 3 of d to editText
The advantage of altering the dialog record, as opposed to the dialog
itself, is that no Apple Events are generated - it's faster.
This example, a modified version of the live dd shell I use, illustrates
the second method. It remembers dialog position, but doesn't use the
standard method for positioning it in the first place. Beware of line
wraps & Server Mangulation:
-- start script
-- dialog properties
property fontSpec : {null, null, null, {name:"Geneva", size:10},
{name:"Geneva", style:bold, size:10}}
property dSize : [364, 80] -- size of the dialog
property dBounds : [] -- this will be calculated unless another value
has been stored here
property dName : "Example Live dLog"
property editText : "Text stored in the property 'editText'. Change it &
see what happens."
-- dialog contents
property dConts : [,
{class:push button, bounds:[290, 50, 350, 70], name:"OK"}, ,
{class:push button, bounds:[210, 50, 270, 70], name:"Cancel"}, ,
{class:text field, bounds:[6, 12, 360, 24], value:editText,
justification:center} ,
]
if dBounds = [] then set dBounds to calcDialogPos from dSize -- calculate
position on screen
try
-- any initial value setting here
tell dConts to set value of item 3 to editText
dd install with fonts fontSpec with grayscale
set d to dd make dialog ,
{bounds:dBounds, style:movable dialog, name:dName, contents:dConts}
repeat
set i to dd interact with user
if i = 1 then -- 'OK'
set dBounds to dd get bounds of d -- save window position
set editText to dd get value of item 3 of d -- store the value back
in the property
exit repeat
else if i = 2 then -- 'Cancel'
exit repeat
else if i = 3 then -- text field
end if
end repeat
dd uninstall
on error errMsg number errNum
try
dd uninstall
end try
-- pass user cancel error
if errNum -128 then ,
display dialog errMsg & return & return & errNum buttons {"OK"} default
button 1
end try
-- calculate the bounds of the progress relative to the screen size
to calcDialogPos from dLogSize
tell application "Finder" to set deskSize to size of desktop's window
tell deskSize to set {w, h} to {item 1, (item 2) + 20} -- screen size
set L to (w div 2) - ((item 1 of dLogSize) div 2) -- x - central
set T to (h div 2) - (h div 4) -- y - a bit above centre
tell dLogSize to return [L, T, (L + (item 1)), (T + (item 2))]
end calcDialogPos
-- end script
Cheers,
Richard Morton
-- Great Lies of the Music Business: "We'll definitely come to the gig"