Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Dynamic GUI problems

  • To: mathgroup at smc.vnet.net
  • Subject: [mg89431] Re: Dynamic GUI problems
  • From: Szabolcs Horvát <szhorvat at gmail.com>
  • Date: Mon, 9 Jun 2008 02:30:02 -0400 (EDT)
  • References: <g2dbji$9ks$1@smc.vnet.net> <g2fuco$2ha$1@smc.vnet.net>

David Bailey wrote:
> zac 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]]}
>>
>>
>> II. Problem - Checkbox in label of TabView does not work
>>
>> TabView[{
>>   Checkbox[Dynamic[x]] -> Dynamic[x],
>>   "..." -> ""
>>   }]
>>
>>
>> Any ideas how to solve them?
>>
>> Istvan Zachar
>>
> The first problem is that the expressions for sub1 and sub2 do not 
> contain the Dynamic wrapper. The easiest way is to code the two separately:
> 
> master = False;
> def = {False, True};
> 
> {Button["All", master = All], Button["None", master = None]}
> {Dynamic[master], Dynamic[sub1], Dynamic[sub2]}
> sub1 = Dynamic[Switch[master, All, True, None, False, _, def[[1]]]];
> sub2 = Dynamic[Switch[master, All, True, None, False, _, def[[2]]]];
> 
> {Checkbox[Dynamic[sub1]], Checkbox[Dynamic[sub2]]}
> 
> In the second problem, you are trying to put a checkbox into the label 
> of a tabview. This would be a very unusual thing to do in a GUI - you 
> really need a name or an image there - and probably has never been 
> designed to work.
> 

Google Groups ate my reply to this question, and I have not saved it ... 
so let me try again (hopefully this other news provider will be more 
reliable):

Dynamic[x] does not evaluate to the value of x.  The expression stays as 
Dynamic[x],  but the front end *displays* it as the value of x.  (It is 
possible to see this by using FullForm/InputForm).  Thus Dynamic[x] 
should not be used as a value.

This is why David's solution does not work correctly either (try using 
the checkboxes, and then the buttons again).

Furthermore, one should never rely on side effects of the evaluation of 
an expression inside Dynamic.  It is important to remember that the 
expression inside Dynamic is *not* re-evaluated unless it needs to be 
displayed.  (E.g. it is only re-evaluated when the displayed Dynamic is 
scrolled into view, and not at the moment when x changes.)

A working solution looks something like this:

setAll[value_] := (sub1 = sub2 = value)

{sub1, sub2} = {True, False}

{Button["All", setAll[True]], Button["None", setAll[False]]}

{Checkbox[Dynamic[sub1]], Checkbox[Dynamic[sub2]]}


  • Prev by Date: Re: Selecting Element from List via Pattern Matching
  • Next by Date: Re: Major problem with 6.0.2.1
  • Previous by thread: Re: Dynamic GUI problems
  • Next by thread: Re: Dynamic GUI problems