3
$\begingroup$

I am setting up a UI with sliders that are enabled or disabled according to the item in a PopupMenu. I have been trying to figure out how to reset the sliders to the default value of zero when I select another item from the PopupMenu. After reading the documentation I think that Refresh should do the trick but I am missing something. It seems that after refresh the sliders need to be updated but I cannot figure out how. Can you help? Please see the mwe below. I am using v 12.1.1.0. Thank you!

BU

(* Initialization section *)
dMin = -500; dMax = 500; dStep = 0.1;
aMin = 0; aMax = 500; aStep = 0.1;

PopupMenu[Dynamic[tType], {
  {0, 0, 1, 0, 0, 0} -> "t1",
  {1, 0, 1, 1, 0, 0} -> "t2",
  {1, 0, 1, 1, 1, 1} -> "t3",
  {1, 1, 1, 1, 1, 1} -> "t4",
  {2, 1, 1, 1, 0, 0} -> "t5",
  {3, 1, 1, 1, 0, 0} -> "t6",
  {0, 1, 1, 1, 0, 0} -> "t7",
  {0, 1, 1, 1, 1, 1} -> "t8"}]

Manipulate[Grid[{
   {"a", Slider[
     Dynamic[aa], {If[tType[[1]] == 3 , 1.5 bb, dMin], 
      If[tType[[1]] == 2, 1.5 bb, If[1.5 bb <= dMax, dMax, 1.5*dMax]],
       dStep}, Enabled -> tType[[1]] > 0, 
     Appearance -> {Small, "UpArrow", "Labeled"}, 
     Background -> LightBlue, ImageMargins -> 0]},
   {"b", Slider[Dynamic[bb], {dMin, dMax, dStep}, 
     Enabled -> tType[[2]] > 0, 
     Exclusions -> {If[tType[[2]] > 0, 0, None]}, 
     Appearance -> {Small, "UpArrow", "Labeled"}, 
     Background -> LightBlue, ImageMargins -> 0]},(* 
   excludes zero from types 4 t0 8 *)
   {"c", Slider[Dynamic[cc], {dMin, dMax, dStep}, 
     Enabled -> tType[[3]] > 0, 
     Appearance -> {Small, "UpArrow", "Labeled"}, 
     Background -> LightBlue, ImageMargins -> 0]},
   {"d", Slider[Dynamic[dd], {aMin, aMax, aStep}, 
     Enabled -> tType[[4]] > 0, 
     Appearance -> {Small, "UpArrow", "Labeled"}, 
     Background -> LightBlue, ImageMargins -> 0]},
   {"e", Slider[Dynamic[ee], {dMin, dMax, dStep}, 
     Enabled -> tType[[5]] > 0, 
     Appearance -> {Small, "UpArrow", "Labeled"}, 
     Background -> LightMagenta, ImageMargins -> 0]},
   {"f", Slider[Dynamic[ff], {aMin, aMax, aStep}, 
     Enabled -> tType[[6]] > 0, 
     Appearance -> {Small, "UpArrow", "Labeled"}, 
     Background -> LightMagenta, ImageMargins -> 0]}},
  Frame -> Outer, ItemSize -> {{1, 21}}], 
 Dynamic[tType, 
  Refresh[{aa = 0, bb = 0, cc = 0, dd = 0, ee = 0, ff = 0}, 
   TrackedSymbols :> {tType}]], AppearanceElements -> None]
$\endgroup$
0

1 Answer 1

1
$\begingroup$

Replace Dynamic[tType] in the first argument of PopupMenu with

Dynamic[tType, (tType = #; aa = bb = cc = dd = ee = ff = 0;) &] 

to get

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.