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

MathGroup Archive 2010

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

Search the Archive

Re: Initialization problem in a DynamicModule

  • To: mathgroup at smc.vnet.net
  • Subject: [mg106654] Re: [mg106634] Initialization problem in a DynamicModule
  • From: Ariel Sepulveda <ariel.sepulveda at prontoanalytics.com>
  • Date: Wed, 20 Jan 2010 06:48:41 -0500 (EST)
  • References: <201001191014.FAA29115@smc.vnet.net>

This seems to work fine:

Panel@DynamicModule[{x, y, assign, initialize},
  initialize[];
  assign[];
  Grid[{{"", "A", "B"}, {"w/ assign:",
     RadioButton[Dynamic[x, (x = #; assign[]) &], True],
     RadioButton[Dynamic[x, (x = #; assign[]) &], False]},
    {"w/o assign:", RadioButton[Dynamic@x, True],
     RadioButton[Dynamic@x, False]},
    {"value:", Dynamic@x}},
   Dividers -> {False, {False, True, True, True, False}},
   Alignment -> {Left, {Center}}],
  Initialization :> (assign[] := (y =
       x);(*further variables to update*)
    initialize[] := (x = True;);(*initialization function*))]

I assume that the problem is that you should initialize at the beginning of
the code and not inside the initialization script.  Recall that
DynamicModule remembers all local variables so, once defined you don't need
to have them reinitialized every time the Initialization is evaluated (i.e.
everytime the DynamicModule is evaluated the first time in a Mathematica
session).  Besides, if you try to initialize inside Initialization, you
would be asking the DynamicModule to redefine local variables in each new
session, and that is not what is expected from DynamicModule but local
variables should keep latest session values.

Hope this helps.

Ariel Sepulveda

On Tue, Jan 19, 2010 at 6:14 AM, Istv=E1n <replicatorzed at gmail.com> wrote:

> Dear Group,
>
> I have some problem with a complex interface inside a DynamicModule.
> This is a toy version of the program, which can fully reproduce the
> malfunction:
>
> Panel@DynamicModule[
>  {x, y, assign, initialize},
>
>  Grid[{
>    {"", "A", "B"},
>    {"w/ assign:", RadioButton[Dynamic[x, (x = #; assign) &], True],
>     RadioButton[Dynamic[x, (x = #; assign) &], False]},
>    {"w/o assign:", RadioButton[Dynamic@x, True],
>     RadioButton[Dynamic@x, False]},
>    {"value:", Dynamic@x}
>    }, Dividers -> {False, {False, True, True, True, False}},
>   Alignment -> {Left, {Center}}],
>
>  Initialization :> (
>    assign := (y = x);(* further variables to update *)
>    initialize := (x = True; assign); (* initialization function *)
>    initialize;
>    )
>  ]
>
> Now for some reason, the radiobuttons do not function as intended (at
> least as I want).
> The following clicking orders do not work:
>
> [w/ + B] then [w/ + A]
> [w/o + B] then [w/ + A]
>
> these work correctly:
>
> [w/ + B] then [w/o + A]
> [w/o + B] then [w/o + A]
>
> I guess, that the problem is with the "initialize" (or the "assign")
> function. Any idea?
> Thanks in advance
>
> Istv=E1n
>
>



  • Prev by Date: Re: More /.{I->-1} craziness, con brio
  • Next by Date: Re: Plotting date-time series in 3D how to handle date-time to plot
  • Previous by thread: Re: Re: Initialization problem in a DynamicModule
  • Next by thread: Re: Re: Initialization problem in a