From: Michael on 21 Jul 2010 07:11 On 7/20/2010 2:40 AM, Patrick Scheibe wrote: > Hi, > > even *in* a DynamicModule you have to use Dynamic to *mark* the that > should be > updated dynamically On 7/20/2010 4:55 AM, Istv=E1n Zachar wrote: > I think the answer for your DynamicModule-related question is: > DynamicModule *does not* wrap its local variables in Dynamic. It is > never stated in the Documentation. Ah of course... silly mistake. I originally was trying to use the Block[] approach, because I don't really want the full functionality of DynamicModule[] - for instance the persistance between sessions, as this code is eventually going in a pop-up window, and the inability to easily share the variable outside the scope of the dynamic module. But I guess I can make it work this way... :) I suppose the surprise of Block variables disappearing inside Dynamic really threw me for a curve, and I am still puzzled as to what is going on. In my opinion if these two don't work together it really should be documented under both Dynamic and Block under the "Possible Issues" section. Thank you both for your help. Michael
From: John Fultz on 22 Jul 2010 05:42 On Wed, 21 Jul 2010 07:11:41 -0400 (EDT), Michael wrote: > On 7/20/2010 2:40 AM, Patrick Scheibe wrote: >> Hi, >> >> even *in* a DynamicModule you have to use Dynamic to *mark* the that >> should be >> updated dynamically >> > On 7/20/2010 4:55 AM, Istv==E1n Zachar wrote: >> I think the answer for your DynamicModule-related question is: >> DynamicModule *does not* wrap its local variables in Dynamic. It is >> never stated in the Documentation. >> > Ah of course... silly mistake. > > I originally was trying to use the Block[] approach, because I don't > really want the full functionality of DynamicModule[] - for instance the > persistance between sessions, as this code is eventually going in a > pop-up window, and the inability to easily share the variable outside > the scope of the dynamic module. But I guess I can make it work this > way... :) > > I suppose the surprise of Block variables disappearing inside Dynamic > really threw me for a curve, and I am still puzzled as to what is going > on. In my opinion if these two don't work together it really should be > documented under both Dynamic and Block under the "Possible Issues" > section. > > > Thank you both for your help. > > Michael DynamicModule has an option called UnsavedVariables which you can use for what you want. I didn't look at your original code, but I think I probably know why your use of Block and Dynamic together failed. The principal point is that Block introduces an environment where variables can be temporarily redefined, but that environment evaporates the moment Block is finished evaluating. The contents of a Dynamic never even begin evaluating until well after the Shift-Enter evaluation is over. So, if your code were like this: Block[{x == 5}, Dynamic[x]] then it's kind of like expecting this to return 5: Block[{x == 5}, 0]; x because the evaluation of the contents of Dynamic is so out-of-band, it might as well be like a completely different evaluation. And, in this case, the syntax coloring is a huge indicator that something probably unwanted is going to happen. Sincerely, John Fultz jfultz(a)wolfram.com User Interface Group Wolfram Research, Inc.
From: John Fultz on 27 Jul 2010 04:15 On Mon, 26 Jul 2010 11:06:56 -0700, Michael wrote: > On 7/22/2010 2:42 AM, John Fultz wrote: >> [...] >> I didn't look at your original code, but I think I probably know why >> your use of >> Block and Dynamic together failed. The principal point is that Block >> introduces >> an environment where variables can be temporarily redefined, but that >> environment evaporates the moment Block is finished evaluating. The >> contents of >> a Dynamic never even begin evaluating until well after the Shift-Enter >> evaluation is over. >> [...] >> > Hi again John, > > I'm seeing a similar thing happen when I use DynamicModule: > > xyz == "A"; > f[] :== DynamicModule[{tmp == "A"}, > CreateDialog[{ > PopupMenu[Dynamic[tmp], {"A", "B", "C", "D"}], > PopupMenu[Dynamic[xyz], {"A", "B", "C", "D"}] > }] > ]; > Button["Test", f[]] > > If I click on the "Test" button, I don't see the value of "tmp" being > changed when I pick different options from the pop up menu, but I *do* > see the value of "xyz" being changed when I pick different options from > its pop up menu. > > However, if I execute f[] directly, it works for both cases. Shouldn't > clicking the button produce identical results to calling whatever is > defined for its action? There seems to be something related to using a > dynamic module variable, perhaps it loses its definition during a Button > call or something. > >> Sincerely, >> >> John Fultz >> jfultz(a)wolfram.com >> User Interface Group >> Wolfram Research, Inc. >> > > Best Regards, > > Michael You need to read up on DynamicModule wormholes. In the help viewer, type: tutorial/AdvancedDynamicFunctionality and DynamicModule wormholes are the very last topic. However, they're also the very most advanced. You really should read the both the introductory tutorial here... tutorial/IntroductionToDynamic and the advanced tutorial, in their entirety, in sequence. Doing so will help you to understand both why the above failure happens and the best method for resolving it. Sincerely, John Fultz jfultz(a)wolfram.com User Interface Group Wolfram Research, Inc.
|
Pages: 1 Prev: Brillouin function for a Ferromagnet Next: Axes all around |