1
$\begingroup$

Is it possible to emulate the behaviour of ControlActive[] for an ordinary Control[] when implemented by an EventHandler[]?

For example, the following will display False unless the slider is being manipulated.

In[1]:= Slider[Dynamic[u]]
In[2]:= Dynamic[u; ControlActive[]]

ControlActive[], via $ControlActiveSetting asks the front-end for the value of FrontEnd`$ControlActive. Out[3] updates whenever any control is active.

In[3]:= Dynamic[FrontEnd`$ControlActive]

I'd like to be able to do something like the following. However, it has no effect (on either Out[4] or Out[3]):

In[4]:= EventHandler[
 Graphics@Dynamic[ u; ControlActive[Circle[], Disk[]] ],
 {
  "MouseDown" :> (u += 0.1; MathLink`CallFrontEndHeld@FrontEnd`SetValue@FEPrivate`Set[FrontEnd`$ControlActive, True]),
  "MouseUp" :> (u -= 0.1; MathLink`CallFrontEndHeld@FrontEnd`SetValue@FEPrivate`Set[FrontEnd`$ControlActive, False])
  }
 ]

By a quirk of implementation, $ControlActiveSetting uses CallFrontEnd[] rather than the Held form, so it is possible to do the following, which shows the desired effect, but has the side-effect of breaking normal uses of ControlActive[] -- clicking the graphic will cause Out[6] and Out[2] to update, and manipulating the slider of Out[1] will have no effect on Out[2] until the non-front-end FrontEnd`$ControlActive is cleared.

In[5]:= FrontEnd`$ControlActive = False;
In[6]:= EventHandler[
 Graphics[ Dynamic@ControlActive[Circle[], Disk[]] ],
 {
  "MouseDown" :> (FrontEnd`$ControlActive = True),
  "MouseUp" :> (FrontEnd`$ControlActive = False)
  }
 ]

The obvious work-around is to use a different variable and a wrapper around ControlActive[] that checks both. I'd like to avoid that if possible.

Assuming a solution, can one further restrict/scope the setting of FrontEnd`$ControlActive to affect only a particular dynamic variable? Ie, assuming some Dynamic[v], the event handler would only trigger updates of Dynamic[v; ControlActive[]] and not, for instance, Out[2] above.

Edit: Added missing dynamic trigger to In[4].

$\endgroup$

1 Answer 1

1
$\begingroup$

FrontEnd`$ControlActive is read-only.

$\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.