Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Re: Help with ScriptSource in GUIKit

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98563] Re: [mg98542] Re: Help with ScriptSource in GUIKit
  • From: "Paul Ellsmore" <paul.ellsmore at nanion.co.uk>
  • Date: Mon, 13 Apr 2009 03:31:32 -0400 (EDT)
  • References: <grpi8i$lgi$1@smc.vnet.net> <200904120747.DAA27191@smc.vnet.net>

Thanks, Raffy, I think I understand how SriptSource is meant to work now,
but I still have problems.

Your first suggestion:
GUIRun[Widget["Button", {
    "Text" -> "Update",
    BindEvent["Action", Script[update[]]],
    Script[{}, ScriptSource -> "targetNB.m"]
}]]
Fails with error message:
GUIRun::err : The following GUIKit runtime error occurred :
Unable to load Script source :targetNB.m.

Both targetNB.m and the notebook that calls it are in the folder specified
by Directory[] - is that OK, or do I have to put targetNB.m in a special
location?

I am not sure what targetNB.m should contain - at the moment it has a single
line of code:
update[] := Print["Clicked"];

Is that correct?

In the real life version, I want to execute an entire notebook (1500
individual cells, all grouped into a single cell for execution). Can I
simply wrap update[] (or some other function definition)around the whole
notebook?

Your second example works, but gives the error/warning:
SetDelayed::write: Tag Null in Null[] is Protected.
In this example, does update[] have to be defined in the same notebook as
the GUI? If so, this kinda defeats the object, doesn't it? 

Thanks,

Paul.



-----Original Message-----
From: Raffy [mailto:raffy at mac.com] 
Sent: 12 April 2009 08:47
To: mathgroup at smc.vnet.net
Subject: [mg98563] [mg98542] Re: Help with ScriptSource in GUIKit

On Apr 11, 12:52 am, "Paul Ellsmore" <paul.ellsm... at nanion.co.uk>
wrote:
> Anyone out there familiar with GUIKit?
>
> Here is a simple GUI that Prints "Clicked" when you push the button.
>
> In[1829]:=
>
> ref = GUIRun[Widget["Button", {"text" -> "Update", BindEvent["action",
> Script[{Print["Clicked"]}]]}],
>
>     IncludedScriptContexts -> {$Context}];
>
> I want the button to execute a large block of code, and the GUIKit
> documentation suggests I use the ScriptSource function:
>
> In[1827]:=
>
> Needs["GUIKit`"];
>
> ref = GUIRun[Widget["Button", {"text" -> "Update", BindEvent["action",
> Script[{}, ScriptSource -> "targetNB.m"]]}],
>
>     IncludedScriptContexts -> {$Context}];
>
> In this test case, targetNB.m just has the code Print["Clicked"] in it.
> Nothing happens when I click the button, no error message, no "clicked" g=
ets
> printed. I have put the GUI notebook and the targetNB.m file in the same
> folder, and set Directory to that folder. The documentation for ScriptSou=
rce
> is appalling (no surprise there), but I assume that the contents of
> targetNB.m will effectively be pasted into the Script function. Is this t=
oo
> naive?
>
> Note that if I specify a non-existent m file for ScriptSource, I get no
> error message. Am I doing something clearly dumb? Is there a better way t=
o
> make some GUI "action" run a separate notebook or m file?
>
> BTW, I realise that GUIKit is (pretty much) obsolete, and I will be (am, =
in
> parallel) developing a V7 GUI from built-in code, but we have a lot of
> legacy V5 notebooks, and GUIKit is actually a pretty easy way to interfac=
e
> with them (apart from little issues like this one!).
>
> Thanks,
>
> Paul.
>
> Dr. Paul A. Ellsmore
>
> Nanion Limited
>
> Oxford Centre for Innovation
>
> Mill Street
>
> Oxford
>
> United Kingdom
>
> OX2 0JX
>
> Tel: +44 (0) 1865 811175
>
> Fax: +44 (0) 1865 248594
>

Usually, the Script[{}, ScriptSource -> "targetNB.m"] is called once
inside a GUI construct to load a large set of external definitions; it
works kinda like Get[] but automatically loads into the script context
which isn't known until after the GUI is run/loaded.

Using this concept, the BindEvent action should just call to a
function defined in this external file.

GUIRun[Widget["Button", {
    "Text" -> "Update",
    BindEvent["Action", Script[update[]]],
    Script[{}, ScriptSource -> "targetNB.m"]
}]]

Although, after writing numerous large GUIKit apps, I prefer the
following:

update[] := Print["Clicked"];

GUIRun[Widget["Button", {"Text" -> "Update", BindEvent["Action", Script
[update[]]]}], IncludedScriptContexts->{"Global`"}]

This way, as your program is running, you can make changes to your
functions and the modifications are available immediately because they
are not buried in some private context.

Additionally, you could define your own package, or context, if you
don't want full access to the Global` space.



  • Prev by Date: Re: Re: Replace Table[Sum...]...] with Functional code
  • Next by Date: Re: Scaling JPEGs or TIFFs inside PDF slides (using Illustrator)?
  • Previous by thread: Re: Help with ScriptSource in GUIKit
  • Next by thread: Re: Help with ScriptSource in GUIKit