Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #12494 > unrolled thread

Help with dynamic functionality

Started bysamid.hoda@gmail.com
First post2012-11-28 08:16 +0000
Last post2012-12-03 08:19 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Help with dynamic functionality samid.hoda@gmail.com - 2012-11-28 08:16 +0000
    Re: Help with dynamic functionality "Nasser M. Abbasi" <nma@12000.org> - 2012-12-03 08:17 +0000
    Re: Help with dynamic functionality awnl <awnl@gmx-topmail.de> - 2012-12-03 08:19 +0000

#12494 — Help with dynamic functionality

Fromsamid.hoda@gmail.com
Date2012-11-28 08:16 +0000
SubjectHelp with dynamic functionality
Message-ID<k94h9k$bh5$1@smc.vnet.net>
My actual problem is quite involved but I am including a simple example for
 illustrative purposes. I am trying to reproduce "Enabled"-like functionality as follows:

Clear[y, SliderModule];
SetAttributes[SliderModule, HoldAll];
SliderModule[enabled_] :=
 DynamicModule[{x = 0}, {Slider[
    Dynamic[x, (x = If[enabled, #, 0]) &]], Dynamic[x]}]
{Checkbox[Dynamic[y]], Dynamic[y], SliderModule[y]}

Ideally when the checkbox is checked then the user is able to move the slider; but when it is unchecked the slider resets to zero. The problem is when I uncheck the checkbox the slider doesn't reset to zero until I click on the slider itself. Is there a way to get the slider to immediately reset when I uncheck the checkbox? Please remember that this is a simplification of my actual problem so try to keep the SliderModule structure the same.

Cheers,
Sam

[toc] | [next] | [standalone]


#12501

From"Nasser M. Abbasi" <nma@12000.org>
Date2012-12-03 08:17 +0000
Message-ID<k9hn7e$io$1@smc.vnet.net>
In reply to#12494
On 11/28/2012 2:16 AM, samid.hoda@gmail.com wrote:
> My actual problem is quite involved but I am including a simple example for
>   illustrative purposes. I am trying to reproduce "Enabled"-like functionality as follows:
>
> Clear[y, SliderModule];
> SetAttributes[SliderModule, HoldAll];
> SliderModule[enabled_] :=
>   DynamicModule[{x = 0}, {Slider[
>      Dynamic[x, (x = If[enabled, #, 0]) &]], Dynamic[x]}]
> {Checkbox[Dynamic[y]], Dynamic[y], SliderModule[y]}
>
> Ideally when the checkbox is checked then the user is able to move the slider;
>but when it is unchecked the slider resets to zero. The problem is when
>I uncheck the checkbox the slider doesn't reset to zero until I click on the
>slider itself. Is there a way to get the slider to immediately reset when
>I uncheck the checkbox? Please remember that this is a simplification of
>my actual problem so try to keep the SliderModule structure the same.
>
> Cheers,
> Sam
>


Column[{
   Slider[Dynamic[slider], Enabled -> Dynamic[checkbox]],
   Checkbox[Dynamic[checkbox, {checkbox = #; If[Not[checkbox],slider = 0]} &]]}
  ]


--Nasser

[toc] | [prev] | [next] | [standalone]


#12516

Fromawnl <awnl@gmx-topmail.de>
Date2012-12-03 08:19 +0000
Message-ID<k9hn9s$jr$1@smc.vnet.net>
In reply to#12494
Hi,

> My actual problem is quite involved but I am including a simple
> example for illustrative purposes. I am trying to reproduce
> "Enabled"-like functionality as follows:
>
> Clear[y, SliderModule]; SetAttributes[SliderModule, HoldAll];
> SliderModule[enabled_] := DynamicModule[{x = 0}, {Slider[ Dynamic[x,
> (x = If[enabled, #, 0]) &]], Dynamic[x]}] {Checkbox[Dynamic[y]],
> Dynamic[y], SliderModule[y]}
>
> Ideally when the checkbox is checked then the user is able to move
> the slider; but when it is unchecked the slider resets to zero. The
> problem is when I uncheck the checkbox the slider doesn't reset to
> zero until I click on the slider itself. Is there a way to get the
> slider to immediately reset when I uncheck the checkbox? Please
> remember that this is a simplification of my actual problem so try to
> keep the SliderModule structure the same.

I think this would work as you want:

Clear[isEnabled, sliderModule];
sliderModule[Dynamic[enabled_]] := DynamicModule[{x = 0},
    Row[{
      Slider[
       Dynamic[x],
       Enabled -> Dynamic[
	  If[TrueQ[enabled],(*Print[x];*)True, x = 0; False]
	]
       ],
      Dynamic[x]
      }]
    ];

{Checkbox[Dynamic[isEnabled]], Dynamic[isEnabled],
  sliderModule[Dynamic[isEnabled]]}

it has the drawback though that the Enabled option will be reevaluated 
for every change in x, which might or might not be a problem and can be 
checked by uncommenting the Print. Adding the TrackedSymbols  option for 
that dynamic seems to not work as expected. So here is another version 
which recreates the slider when the enable-state is changed but doesn't 
do any unnecessary evaluations when the slider is moved:

Clear[isEnabled, sliderModule];
sliderModule[Dynamic[enabled_]] := DynamicModule[{x = 0},
    Row[{
      Dynamic[
       (*Print[x];*)
       If[Not@enabled, x = 0];
       Slider[Dynamic[x], Enabled -> TrueQ[enabled]],
       TrackedSymbols :> {enabled}
       ],
      Dynamic[x]
      }]
    ];



hth,

albert

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web