MathGroup Archive 2009

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

Search the Archive

Re: Help with ScriptSource in GUIKit

  • To: mathgroup at smc.vnet.net
  • Subject: [mg98542] Re: Help with ScriptSource in GUIKit
  • From: Raffy <raffy at mac.com>
  • Date: Sun, 12 Apr 2009 03:47:16 -0400 (EDT)
  • References: <grpi8i$lgi$1@smc.vnet.net>

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: nostalgia for old behaviour: graphics re-sizing
  • Next by Date: Re: Mathematica behavior using highlighting and keyboard arrows - BUG???
  • Previous by thread: Re: Change in NSolve algorithm
  • Next by thread: Re: Re: Help with ScriptSource in GUIKit