3
$\begingroup$

Bug introduced in 11.3 or earlier, and persisting through 12.0

CASE:4372001 confirmed

I am running into an issue trying to improve the performance of my user interface by moving as much of the state handling into the front-end as possible. It appears as though nesting EventHandler forces the kernel to be called, no matter what the action to be performed is.

The following examples illustrate what I am trying to achieve, and how it fails:

Single EventHandler, front-end-only state

This one works as intended: Clicking on the number toggles between 1 and 2, and no front-end <-> kernel communication occurs (verified with LinkSnooper)

DynamicModule[
 {open},
 EventHandler[
  PaneSelector[{True -> 1, False -> 2}, Dynamic@open],
  {
   "MouseClicked" :> FEPrivate`Set[open, FEPrivate`Not@open]
   }
  ]
 ]

Nested EventHandler, front-end-only state

This is the problematic case: Despite the PassEventsDown -> True, this doesn't work.

EventHandler[
 DynamicModule[
  {open},
  EventHandler[
   PaneSelector[{True -> 1, False -> 2}, Dynamic@open],
   {"MouseClicked" :> FEPrivate`Set[open, FEPrivate`Not@open]}
   ]
  ],
 {"MouseClicked" :> True},
 PassEventsDown -> True
 ]

Nested EventHandler, kernel-side state

This one works as expected, but needs to call the kernel:

EventHandler[
 DynamicModule[
  {open},
  EventHandler[
   PaneSelector[{True -> 1, False -> 2}, Dynamic@open],
   {"MouseClicked" :> (open = ! open)}
   ]
  ],
 {"MouseClicked" :> True},
 PassEventsDown -> True
 ]

Nested EventHandler, front-end-only state, using FE`Evaluate

This one is thanks to @Kuba, who noticed that the event action is sent to the kernel even though it shouldn't be. This means that adding FE`Evaluate can be used to make it work. The problem is of course that this still calls the kernel.

EventHandler[
 DynamicModule[
  {open},
  EventHandler[
   PaneSelector[{True -> 1, False -> 2}, Dynamic@open],
   {"MouseClicked" :> FE`Evaluate@FEPrivate`Set[open, FEPrivate`Not@open]}
   ]
  ],
 {"MouseClicked" :> True},
 PassEventsDown -> True
 ]

Question

Since WRI support already confirmed that this is a bug, I am only looking for a possible work-around. Is there any way to get nested, clickable boxes that work entirely in the front-end?

$\endgroup$
  • $\begingroup$ Put simply, no. $\endgroup$ – ihojnicki Jan 22 at 19:43
  • $\begingroup$ @ihojnicki That's unfortunate, I was afraid that would be the answer... But thank you for confirming it explicitly! $\endgroup$ – Lukas Lang Jan 22 at 19:57
1
$\begingroup$

As confirmed by both WRI support and @ihojnicki, this is currently not possible. The front-end does not appear to be able to handle nested EventHandler expressions on its own.

Quoting WRI support: ([CASE:4372001])

It does appear that Nested EventHandler is not behaving properly when all computations are moved to front-end. I have forwarded an issue report to our developers with the information you provided. I also added your contact information to the issue report, so that you can be notified if the issue is resolved in a future version of Mathematica.

I have looked into alternative approaches but unfortunately have not been able to make them work for your specific issue.

For now, I have solved my problem by restructuring the GUI to not require nesting of EventHandlers. This way, one can preserve the responsiveness that comes with front-end only user-interfaces.

| improve this answer | |
$\endgroup$

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.