Re: Nested DynamicModule and EventHandler
- To: mathgroup at smc.vnet.net
- Subject: [mg92431] Re: Nested DynamicModule and EventHandler
- From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
- Date: Tue, 30 Sep 2008 21:51:38 -0400 (EDT)
- Organization: Uni Leipzig
- References: <gbt317$ljd$1@smc.vnet.net>
- Reply-to: kuska at informatik.uni-leipzig.de
Hi,
buttonD[] fail because it call fd[] and fd[] has no c and b
defined:
fd[] := With[{b = {}, c = {0.5, 0.5}},
Column[{EventHandler[
Dynamic[Graphics[{Circle[c, 0.1], b},
PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True]],
"MouseDown" :> (c = MousePosition["Graphics", {}];
AppendTo[b, Point[c]])], Row[{"b ", InputField[Dynamic[b]]}]}]]
And can you explain *why* you use a construct like
buttonA[] := DynamicModule[{}, Button["button A", active := fa[],
ImageSize -> Automatic]];
where are the dynamic variables ??
Regards
Jens
Hugh Goyder wrote:
> I use modules to localise variables and to simplify code. In
> attempting to understand the additional complications of using
> DynamicModule in version 6 I am trying to sort out how to work with
> buttons, modules and EventHandlers.
>
> Below three of my buttons, with increasing complexity, work but the
> fourth, buttonD, fails. I can click points onto the graphic with the
> set-up of buttonC but not with buttonD. I am trying to get
> communication between the parent and child modules where points are
> introduced into the child module using the EventHandler. Thus with
> buttonD pressed clicking on the graphic should produce an additional
> primitive in the list maintained by the parent module. What is the
> correct way to do this?
>
> Thanks Hugh Goyder
>
>
> ClearAll[buttonA, buttonB, buttonC, buttonD];
> buttonA[] := DynamicModule[{}, Button["button A", active := fa[],
> ImageSize -> Automatic]];
> buttonB[] := DynamicModule[{}, Button["button B", active := fb[],
> ImageSize -> Automatic]];
> buttonC[] := DynamicModule[{}, Button["button C", active := fc[],
> ImageSize -> Automatic]];
> buttonD[] := DynamicModule[{}, Button["button D", active := fd[],
> ImageSize -> Automatic]];
>
> ClearAll[fa, fb, fc, fd];
> fa[] := DynamicModule[{}, Plot[x^2, {x, -2, 2}]];
> fb[] := DynamicModule[{a = 5}, Column[{Slider[Dynamic[a], {0, 10}],
> Dynamic[Plot[Sin[a*x], {x, 0, 2*Pi}]]}]];
> fc[] := DynamicModule[{b = {}, c = {0.5, 0.5}},
> Column[{EventHandler[Dynamic[Graphics[{Line[{{0, 0}, c}], b},
> PlotRange -> {{0, 1}, {0, 1}}, Frame -> True]],
>
> "MouseDown" :> (c = MousePosition["Graphics", {}];
> AppendTo[b, Point[c]])],
> Row[{"b ", InputField[Dynamic[b]]}]}]];
> fd[] := DynamicModule[{},
> Column[{EventHandler[Dynamic[Graphics[{Circle[c, 0.1], b},
> PlotRange -> {{-1, 1}, {-1, 1}}, Frame -> True]],
>
> "MouseDown" :> (c = MousePosition["Graphics", {}];
> AppendTo[b, Point[c]])],
> Row[{"b ", InputField[Dynamic[b]]}]}]]
>
> DynamicModule[{active = Graphics[{}], a, g,
> b = {Green, Point[{-0.25, -0.25}]},
> c = {0, 0}},
> Column[{Row[{buttonA[], buttonB[], buttonC[], buttonD[]}],
> Dynamic[active], Row[{"b (outer)", InputField[Dynamic[b]]}],
> Row[{"c ", InputField[Dynamic[c]]}],
> Row[{"active ", InputField[Dynamic[active]]}]}]]
>