5
$\begingroup$

I'm trying to figure out how to tell when controls have been triggered Manipulate (in Animate, actually, but I take it Manipulate is the heart of the matter). After no luck from Search on -- Manipulate control -- through 407 questions, and scores re CurrentValue, I'm hoping this isn't a redundant question.

Given code such as

Manipulate[x, {x, 0, 1, Animator, 
  AppearanceElements -> {"ProgressSlider", "PlayPauseButton", 
    "FasterSlowerButtons", "StepLeftButton", "StepRightButton"}
  }
 ]

I'd like to know how to tell a) when, for instance, the "PlayPauseButton" has been hit, and, b) what's its current value). Same for "StepLeftButton", "StepRightButton", and both "FasterSlowerButtons".

$\endgroup$
5
$\begingroup$

There is no direct way, but you can monitor values of options which are affected by those elements. Here is a small example:

Panel@DynamicModule[{
   animationRunning = True,
   animationRate = Automatic
   },
  Grid[{
    {Animator[Dynamic[x], {0, 1}, 
      AnimationRunning -> Dynamic@animationRunning, 
      AnimationRate -> Dynamic@animationRate], SpanFromLeft},
    {},
    {"AnimationRunning:", Dynamic@animationRunning},
    {"AnimationRate:", Dynamic@animationRate}
    }
   ]
  ]

enter image description here

Another option is to create many Animators with a single AppearanceElements option in each to compose one Animator where you can wrap each element with EventHandler:

Panel @ DynamicModule[
  {lastAction, x}

, animatorElement[element_String, running_: False] := EventHandler[
    Animator[Dynamic[x], {0, 1}
    , AppearanceElements -> {element}
    , AnimationRunning -> running
    ]
  , { "MouseEntered" :> (lastAction = "entered " <> element)
    , "MouseExited" :> (lastAction = "exited " <> element)
    , "MouseClicked" :> (lastAction = "clicked" <> element)
    }
  , PassEventsDown -> True
  ]

; Column[{
    animatorElement["ProgressSlider", True]
  , Row[animatorElement /@ {"PlayPauseButton", "FasterSlowerButtons",        "StepLeftButton", "StepRightButton"
    }]
  , Dynamic[{x, lastAction}]
  }]
]
$\endgroup$
  • $\begingroup$ Very cool ! Thanks, Kuba."Dynamic@animationRunning" solves my "Is it running?" question perfectly.That teaches me something about how parameter specifications work, too. I'm aware that the specified AnimationRate and the actual one may not be identical if there's heavy lifting being done inside Manipulate. So, I'll be sure to verify the frame rate in my application with a smoothed-average function, or something of that sort. Your second bit is quite elegant. You're teaching us to think outside the box in solving a problem. $\endgroup$ – Wxguy Mar 14 '18 at 20:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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