Re: MathLink and GUIKit
- To: mathgroup at smc.vnet.net
- Subject: [mg57509] Re: MathLink and GUIKit
- From: Maxim <ab_def at prontomail.com>
- Date: Tue, 31 May 2005 04:59:00 -0400 (EDT)
- References: <200505240912.FAA19099@smc.vnet.net> <d71j58$489$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
On Wed, 25 May 2005 10:14:00 +0000 (UTC), Jeff Adams <jeffa at wolfram.com>
wrote:
> At 04:12 AM 5/24/2005, Goyan wrote:
>> Hi all,
>>
>> I have a written C++ function called HSeg which I can call it after
>> using "Install[]" using Mathlink, however, when I dont seem to be able
>> to call the function within the GUIKit. My code is as the following:
>>
>> HSegButton = GUIRun[
>> Widget["Panel", {Widget["
>> Button", {"text" -> "HSeg", BindEvent["mouseClicked",
>> Script[HSeg[img]]]]}]}
>> ]
>> ]
>>
>> Can anyone help me with this?
>>
>> Thank you in advance.
>>
>> Goyan
>
> Hello,
>
> Each GUIKit definition by default runs within a protected $ContextPath
> which does not include the Global` context.
> When you call Install[] on your function outside the definition above
> the symbol HSeg is most likely in the Global` context.
>
> You can include the Global` context with the call to GUIRun above
> using the option IncludedScriptContexts -> {"Global`"}
>
> You can read more about how contexts are handled with GUIKit definitions
> in the Help Browser documentation under
> GUIKit -> Building GUIs -> Advanced Topics -> Scoping of Scripts
>
> Jeff Adams
> Wolfram Research
>
I'd just like to mention that, strictly speaking, this is not the whole
explanation. Normally if we write something like y := x, then x is created
in the Global` context when this line is parsed by the interpreter, and
regardless of the setting of $Context or $ContextPath at the moment when
Global`y is evaluated, it will always return Global`x. Script does
something different; most likely it applies ToString to its arguments.
The resulting behaviour is rather strange:
(*starting with a fresh kernel*)
<<guikit`
BeginPackage["a`"];
x = 1;
EndPackage[]
GUIRun[
Widget["Button", {"text" -> "Print",
BindEvent["action",
Script[Print[a`x]]]
}]
]
prints x but then
Global`x = 2;
GUIRun[
Widget["Button", {"text" -> "Print",
BindEvent["action",
Script[Print[a`x]]]
}]
]
prints 1. In the first case ToString[Unevaluated@ Print[a`x]] returns
"Print[x]" (Mathematica omits the context prefix when possible), and
ToExpression["Print[x]"] is evaluated in a different context (say,
hidden`), creating and using the new symbol hidden`x, because a` isn't on
$ContextPath within Script. In the second case ToString[Unevaluated@
Print[a`x]] returns "Print[a`x]", which doesn't change its meaning inside
hidden`. So one always has to remember whether Mathematica shortens a`x to
just x or leaves the name in the fully qualified form a`x.
Another implication is that Script can hide only symbols that explicitly
appear in the arguments:
(*starting with a fresh kernel*)
<<guikit`
x := 1
a`y := x
GUIRun[
Widget["Button", {"text" -> "Print",
BindEvent["action",
Script[Print[{x, a`y}]]]
}]
]
This will print {x, 1}.
Maxim Rytin
m.r at inbox.ru
- References:
- MathLink and GUIKit
- From: Goyan <goyanian@gmail.com>
- MathLink and GUIKit