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


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

Re: Help with dynamic functionality

Started byFred Simons <f.h.simons@tue.nl>
First post2012-12-03 08:18 +0000
Last post2012-12-03 08:18 +0000
Articles 1 — 1 participant

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

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Help with dynamic functionality Fred Simons <f.h.simons@tue.nl> - 2012-12-03 08:18 +0000

#12503 — Re: Help with dynamic functionality

FromFred Simons <f.h.simons@tue.nl>
Date2012-12-03 08:18 +0000
SubjectRe: Help with dynamic functionality
Message-ID<k9hn7p$is$1@smc.vnet.net>
A further simplication shows wat is going on and how to achieve what you 
are looking for:

Grid[{{Checkbox[Dynamic[y]], Dynamic[y]},
   {Dynamic[x], Slider[Dynamic[x, (x = If[y, #, 0]) &]]}}]

Check the checkbox and move the slider. Then uncheck the checkbox. That 
changes the value of y, so the updating mechanism starts. For updating 
the the slider, the frontend  asks the kernel to evaluate the first 
argument, that is in this case  x only, which as not changed. If you 
want that unchecking the box has an effect on the slider, the first 
argument of the slider must depend on the variable y as well, e.g.

{Checkbox[Dynamic[y]], Dynamic[y],
  Slider[Dynamic[If[y, x, 0], (x = #) &]], Dynamic[x]}

Observe that the last Dynamic[x] shows that even when the the checkbox 
is unchecked, assignments to x are done when the slider is used. To 
prevent that, instead of (x=#)& you can use If[y, x=#]&.

Fred Simons
Eindhoven University of Technology


Op 28-11-2012 9:17, samid.hoda@gmail.com schreef:
> 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
>
>
>
> -----
> Geen virus gevonden in dit bericht.
> Gecontroleerd door AVG - www.avg.com
> Versie: 2013.0.2793 / Virusdatabase: 2629/5920 - datum van uitgifte: 11/26/12
>
>
>

[toc] | [standalone]


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


csiph-web