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]