Re: How to find which variable caused the trigger in Manipulate[]
- To: mathgroup at smc.vnet.net
- Subject: [mg104136] Re: How to find which variable caused the trigger in Manipulate[]
- From: "Nasser M. Abbasi" <nma at 12000.org>
- Date: Tue, 20 Oct 2009 04:54:32 -0400 (EDT)
- References: <hav105$47o$1@smc.vnet.net>
"John Fultz" <jfultz at wolfram.com> wrote in message news:hav105$47o$1 at smc.vnet.net... > This looks to me like a bug, but one that is very simple to work around. > Use > Rule instead of RuleDelayed for the Refresh. I.e., > > Manipulate[ > Row[{Dynamic[Refresh[r = process["x "]; "", TrackedSymbols -> {x}]], > Dynamic[Refresh[r = process["y "]; "", TrackedSymbols -> {y}]], > Dynamic[Refresh[Text[r], TrackedSymbols -> {x, y}]]}], {x, 0, > 1}, {y, 0, 1}, {r, "", "", ControlType -> None}, > Initialization :> (process[s_String] := > Module[{}, Text[StringJoin[s, DateString[]]]])] > > After a bit of experimentation, my advice is to completely avoid > RuleDelayed > with the TrackedSymbols option. > > Sincerely, > > John Fultz > jfultz at wolfram.com > User Interface Group > Wolfram Research, Inc. > Version 7, on windows XP. Hello, I am afraid there is a slight technical problem with the above approach, which is preventing my demo from being accepted. I have been trying to solve it for the last day or so, but no luck. Before I give up and recode the whole demo, once again, to use a more standard approach, I thought I'll describe the problem found and see may be there is a solution I am not seeing. This might be a 'bug' or might be a feature, I am not sure. Background: When using Manipulate, and then closing the notebook, and opening it, Manipulate will remember the values of the control as they were before closing the notebook. This way, the screen will look the same way it was before closing the notebook. Try it on any Manipulate and you'll see. Mathematica saves in the notebook the values of the control variables. So if one has a slider "x", at say some value 7, and then they close/reopen the notebook, then they will see the slider back at the same position, ie. at 7. The problem with the solution we have now as shown above, is that this does not work any more. Manipulate will not remember the slider position, unless the slider happened to be the LAST one in the Row[{}] shown. This is a very simple example to illustrate: This is a Manipulate with 2 sliders. Manipulate[Row[{ Dynamic[Refresh[r = x; "", TrackedSymbols -> {x}]], Dynamic[Refresh[r = y; "", TrackedSymbols -> {y}]], Dynamic[Refresh[Text[r], TrackedSymbols -> {y, x}]]} ], {x, 0, 1, 0.01}, {y, 0, 1, 0.01}, {r, "", "", ControlType -> None} ] The above works fine. But notice that the first entry in Row[{}] is for the x control variable, and the second entry is for the y control variable. Now if you move the "x" slider and note the position it is at. Now save the notebook, close it, and reopen it. Notice that the "x" slider is NOT at the same position it is in. It is back to zero. Do the same now, but with the "y" slider, and repeat the same process, then you will see when you reopen the notebook that the "y" slider is at the SAME position it was before closing the file. Why Manipulate remembers the position of "y" and not for "x"? This is because the line which says Dynamic[Refresh[r = y; "", TrackedSymbols -> {y}]] happened to be the last entry in Row[{}] where the r variable is being set. Changing the order of the Row[{}] lines, changes the above behavior. So, I am trying to solve this problem. But I have no idea how Mathematica does these things internally, so I have been doing lots of trial and error trying to find out why. But no luck yet. I need a way to use the same approach as above, but have Manipulate remember ALL the sliders positions as they were before closing the file, not just the last one in the Row[{....}]. It seems that Row[{...}] is not the right thing to use for this, I tried Grid, Column, and nothing helped, or may be this is a bug? May be some one has any other ideas, please let me know. I can ofcourse recode the whole thing to use a pull-down menu and let the user select the action to do, and avoid all this Dynamic[Refresh[...]]] but I think that Mathematica should be able to support such a design for the interface. Thanks, --Nasser