Re: Dynamic GUI problem III.

*To*: mathgroup at smc.vnet.net*Subject*: [mg89501] Re: [mg89382] Dynamic GUI problem III.*From*: John Fultz <jfultz at wolfram.com>*Date*: Wed, 11 Jun 2008 03:17:30 -0400 (EDT)*Reply-to*: jfultz at wolfram.com

On Sun, 8 Jun 2008 02:30:01 -0400 (EDT), zac wrote: > ... and again an unexpected behaviour: > > h = {5, 4, 3, 2, 1}; > n = 2; > Slider[Dynamic[n], {0, 5, 1}] > a = Dynamic[Take[h, n]]; > TogglerBar[Dynamic[b], a] > > TogglerBar is not evaluated at end. Any idea? > Istvan There are some limitations in the controls about where you can put a Dynamic...especially in controls like TogglerBar for the argument that provides a list of choices. The limitation is easy to work around, though, by wrapping the control itself in dynamic. In your example, it would be this... h = {5, 4, 3, 2, 1}; n = 2; Slider[Dynamic[n], {0, 5, 1}] Dynamic[TogglerBar[Dynamic[b], Take[h, n]]] > another GUI related question. > How to save a list of dynamic values into one variable after allowing > the user to input them through e.g. separate sliders, when the actual > length of the list (and number of sliders) is not determined > preceedingly (here it is 3, but say it can change)? > > n = 3; > a = Table[RandomReal[], {n}]; > x = Table[Slider[a[[i]], ImageSize -> 50], {i, n}] > Dynamic[Setting[x]] > > The last line of code clearly won't work, since all sliders were > called without any dynamic content. > Any suggestions? > > Istvan Zachar Similarly, here, you can wrap the Dynamic around the entire third line (not around the right-hand side of the =, or else you'll change how x is assigned). Also, there's a mistake here in that the resulting value of the Slider doesn't get assigned to a[[i]] because no Dynamic is wrapped around a[[i]]. But you can't just wrap Dynamic around it because Dynamic doesn't evaluate its arguments, and you need some way to plug in the explicit values of i without fully evaluating a[[i]]. Here's one way to do your example... n = 3; a = Table[RandomReal[], {n}]; x = Dynamic[ Table[With[{i = i}, Slider[Dynamic[a[[i]]], ImageSize -> 50]], {i, n}]] Dynamic[Setting[x]] and to confirm that it works, subsequently evaluate... AppendTo[a, RandomReal[]]; n = 4; If you haven't already, you should completely read and work through all of the examples in the following tutorials in the help system (just type these into the search field of the help system)... tutorial/IntroductionToDynamic tutorial/AdvancedDynamicFunctionality Sincerely, John Fultz jfultz at wolfram.com User Interface Group Wolfram Research, Inc.