Re: Dynamic GUI problems
- To: mathgroup at smc.vnet.net
- Subject: [mg89406] Re: Dynamic GUI problems
- From: Szabolcs <szhorvat at gmail.com>
- Date: Mon, 9 Jun 2008 02:25:18 -0400 (EDT)
- References: <g2dbji$9ks$1@smc.vnet.net>
On Jun 7, 9:58 am, zac <replicator... at gmail.com> wrote: > Dear Group, > > building a GUI is highly non-intuitive for me, although I almost felt > I understand the behaviour of dynamic interactivity. > > I. Problem - Master swich does not control semi-independent sub- > switches > This is the classic "set all/none switch" situation, with allowing the > sub-switches to be set by the user individually. Switching the > checkbox works, but hitting the buttons won't update checkboxes. > > master = False; > def = {False, True}; > > {Button["All", master = All], Button["None", master = None]} > {Dynamic[master], Dynamic[sub1], Dynamic[sub2]} > {sub1, sub2} = > Table[DynamicModule[{i = i}, > Switch[master, All, True, None, False, _, def[[i]]]], {i, 2}]; > {Checkbox[Dynamic[sub1]], Checkbox[Dynamic[sub2]]} There are many misunderstandings here. First, you probably wanted to make the Swicth dynamic (i.e. Dynamic@Switch instead of Switch), but this still won't give the result that you expect. It is important to understand that Dynamic is only about formatting. Dynamic[x] will not evaluate to the value of x. It will stay as Dynamic[x], however it will be *displayed* as the value of x by the FrontEnd in StandardForm (but not in InputForm: try seeing the InputForm of these expressions to see what I mean). The displayed form of Dynamic[x] will be updated (and x will be re-evaluated) whenever x changes value. But it is important to note that this only happens when this expression is actually visible on screen. So you cannot reply on side effects of x being evaluated inside a Dynamic because the evaluation will only happen when it is really needed for refreshing the display. It is early in the morning here, I hope I didn't mess up this explanation completely ... So the solution is to set all directly in the button: Button["All", sub1 = True; sub2 = True] Button["None", sub1 = False; sub2 = False] > > II. Problem - Checkbox in label of TabView does not work > > TabView[{ > Checkbox[Dynamic[x]] -> Dynamic[x], > "..." -> "" > }] No idea about this one. Just don't put the checkbox in the label ... > > Any ideas how to solve them? > > Istvan Zachar