Re: [NTLK] Help with Newtonscript

From: Paul Guyot (pguyot_at_kallisys.net)
Date: Tue Jun 03 2003 - 23:38:11 PDT


Il me semble que le 4/06/03 ā 1:22 -0500, Michael Burks nous racontait:
>Or at least I will, once I get some
>help with how to pass variables to linked subviews. It's got me totally
>stumped, can't figure it out. I'm trying to open a protoFloatNGo that is a
>linked subview to my main app. I want to change the protoStaticText on the
>floatNGo to a variable declared in my main app. But, I can't do it, I can't
>seem to use GetVariable to do it, I even thought, hey, why shouldn't I just
>give up. And I will, if I can't get any help with this.

You don't need to use GetVariable. I never use this method actually,
since NewtonScript's slot access does what I need in 99.9% of the
cases.

You need a reference to your view. I never tried to use linked
subview (I guess you mean the thing in NTK). Instead I use the
GetLayout trick:

self.subFloater := BuildContext(GetLayout("Sub Floater"));

(where "Sub Floater" is the name of the file with your layout). This
stores the reference in the subFloater slot of self.

GetLayout refers to the prototype you've defined. BuildContext will
create an object based on this prototype and make it ready for being
opened with:

self.subFloater:open();

(here "self." is optional, I usually include it for clarity since
subFloater is not a local variable but a slot of self).

then, you can change the text. To do this, you need the object based
on protoStaticText to be declared (say as myStaticText). NTK provides
this into information or something like this; for it to work, you
need to first declare the base view (the floater), for example as
"base", then you need to declare the static text to "base".

In the end, changing the text should be done with something like:
SetValue(self.subFloater.myStaticText, 'text, "New Text");

I might have not provided the parameters in the correct order, but
this is the idea.

myStaticText slot of subFloater will be NIL until subFloater is open.

Consequently, if you want to set the text just before the floater
opens (say, if your floater is a message box and you want to open it
with a custom message), this is not the best way to proceed. Usually,
I achieve this by setting the text in the viewSetupFormScript or
viewSetupChildrenScript of the floater (or view) object. Save the
text in one of its slots and then open it, the
viewSetupChildrenScript will be called and you'll change the text
there.

Finally, you probably want to encapsulate this with methods instead
of accessing the slots.

In the first case, relace:
SetValue(self.subFloater.myStaticText, 'text, "New Text");

with
self.subFloater:SetStaticText("New Text");

and define a method on the floater called SetStaticText that will do
the actual SetValue call.

For the second case, I think I would define a method that will do the
job of building the context, saving the text and then opening the
floater. I'd invoke it with:
GetLayout("Sub Floater"):OpenWithMessage("New Text");

HTH,

Paul

-- 
NPDS: http://newton.kallisys.net:8080/
Apache: http://www.kallisys.com/
-- 
This is the NewtonTalk list - http://www.newtontalk.net/ for all inquiries
List FAQ/Etiquette/Terms: http://www.newtontalk.net/faq.html
Official Newton FAQ: http://www.chuma.org/newton/faq/


This archive was generated by hypermail 2.1.5 : Fri Jun 06 2003 - 08:25:16 PDT