From: István on 19 Jan 2010 05:16 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(a)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
From: David Park on 20 Jan 2010 06:46 Does this work for you: Panel(a)DynamicModule[ {x = True, y, assign}, Attributes[assign] = HoldAll; assign[x_, y_] := y = x; assign[x, y]; Grid[{{"", "A", "B"}, {"w/ assign:", RadioButton[Dynamic[x, (x = #; assign[x, y]) &], True], RadioButton[Dynamic[x, (x = #; assign[x, y]) &], 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}}]] David Park djmpark(a)comcast.net http://home.comcast.net/~djmpark/ From: Istv=E1n [mailto:replicatorzed(a)gmail.com] 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(a)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
From: Patrick Scheibe on 20 Jan 2010 06:45 Hi, it matters that your assign and initialize functions have DownValues. Panel(a)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[];)] Cheers Patrick On Tue, 2010-01-19 at 05:14 -0500, István 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(a)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 >
From: Ariel Sepulveda on 20 Jan 2010 06:48 This seems to work fine: Panel(a)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(a)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(a)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 > >
From: Norbert P. on 20 Jan 2010 06:50
Hi Istv=E1n, this is one of the weird behaviors of DynamicModule. The dynamic functionality is awesome, but I find it very hard to create a more involved interface due to the unpredictability of the components. More involved means anything more than the simple demos from demonstrations.wolfram.com. Even though the documentation is quite extensive, many details are missing. I was staring at your code for quite a while =) It turns out that it still contains a lot of clutter. You could've stripped most of it and you'd get: In[1]:= DynamicModule[{something}, 1, Initialization:>(something:=(Print["you should never see this!"]);) ] Out[1]= 1 During evaluation of In[1]:= you should never see this! As you can see, DynamicModule evaluates its variables, even though I wouldn't expect it to do it. Is there anything about it in the documentation? The solution for you is to define functions not as OwnValues as above, but as DownValues, as in: In[2]:= DynamicModule[{something}, 1, Initialization:>(something[]:=(Print["you should never see this!"]);) ] Out[2]= 1 In this case, something doesn't get evaluated and it works the way you expect. So try Panel(a)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[];)] For some reason, DynamicModule evaluates its variables whenever I assign to x as in the following code by clicking the first radio button (it evaluates it twice!!), but not when I press the second: DynamicModule[{x=False,something,i=0}, {RadioButton[Dynamic[x,(x=#)&],True],RadioButton[Dynamic [x],False],Dynamic[i]},Initialization:>(something:=(Print["init",i+ +]))] It would be great to hear from someone who knows more about the internal working of DynamicModule. My all-time favourite bug is: In[3]:= DynamicModule[{x=Sequence[]},1] During evaluation of In[3]:= Transpose::nmtx: The first two levels of the one-dimensional list {{Hold[x]},{}} cannot be transposed. >> Out[3]= Manipulate`Dump`eDynamicModule[Transpose [Manipulate`Dump`heldsetting[{{Hold[x]},{}}]],1,DynamicModuleValues:> {}] Compare that to ordinary module: In[4]:= Module[{x=Sequence[]},1] Out[4]= 1 I discovered it a couple days after buying Mathematica 6, still excited about the new dynamic functionality. That was pretty disappointing;) Best, Norbert On Jan 19, 2:16 am, Istv=E1n <replicator...(a)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(a)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 |