Re: GuiKit, Script[] and external function
- To: mathgroup at smc.vnet.net
- Subject: [mg50997] Re: [mg50970] GuiKit, Script[] and external function
- From: jeffa at wolfram.com
- Date: Fri, 1 Oct 2004 04:48:15 -0400 (EDT)
- References: <200409300852.EAA26496@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
> hi all. > > Using the GuiKit, i have a script such as : > > ref = GUILoad[ > Widget["Frame", { > ... > Script[myFunction[]]; > ... > }]; > > myFunction[] is defined in another package, calles with Needs[`]. > > But the GUILoad does not allow to call an external function in a > Script[] block. I should define it this way : > Script[myFunction[]:=(...)]; > in the Widget block. > > How can I call this external-defined function in the Script[] block Hello, The GUIKit documentation goes over this in the online help section GUIKit -> Building GUIs -> Advanced Topics -> Scoping of Scripts Essentially, GUIKit definitions use their own $ContextPath for loaded contexts separate from your global kernel loaded packages. This is both to prevent symbols and definitions in your kernel session affecting GUIKit definition Script[] code and vis versa. All you need to do is load any required packages with a separate initial Script[Needs["MyPackage`"]] and all the packages symbols and definitions will be available to the following Script[] blocks of the GUIKit definition throughout its lifetime. For example, a simple illustration of this is: GUIRun[ Widget["Button", {"text" -> "Print", Script[ Needs["Graphics`Colors`"];], BindEvent["action", Script[printColor[]]], Script[ printColor[] := Print[Red ];] }] ] But you will notice that the Red definition and loading of Graphics`Colors` is internal to the GUIKit definition and not defined in your global kernel session. Additionally if you separately called Needs["Graphics`Colors`"] in your kernel session, GUIKit script blocks would not know the definitions of 'Red' unless you added the Script[ Needs["Graphics`Colors`"];] Those familiar with webMathematica will recognize this encapsulation and separate $ContextPath nature Thank you, Jeff Adams Wolfram Research