So I've been playing with FrontEndTokens recently and discovered that there are some of them that don't seem to have a standard-usage way of being called. For example, the "Tab" token isn't called when the tab key is pressed, but is captured by the {"MenuCommand","Tab"} event binding, which makes it ripe for abuse as a custom event. That is, if it really doesn't have a common usage, it should be possible to use it as a place holder for a function that will be performed by whatever event handlers. Tkinter in python has this sort of thing via a virtual event caller.

That led me to wondering if it's possible to construct personalized FrontEndTokens that I could use as EventHandler callbacks.

I'm afraid the answer to this is probably no, given that some of the simple test I've run (e.g. trying NotebookEventActions -> {{"MenuCommand", "CustomEvent"} :> Print[1]} haven't worked) but if this were possible it would extend the UI capabilities of Mathematica dramatically.

  • $\begingroup$ So you want an EventHandler to capture custom tokens. How to you want to trigger them? $\endgroup$ – Kuba Dec 14 '16 at 8:50
  • $\begingroup$ My thought was to use FrontEndTokenExecute and a {"MenuCommand",token}. The idea is to call the event myself and have it be caught by an event handler, for example, have like "MouseClicked" and "MouseExited" call FrontEndTokenExecute["VirtualEvent"]. Basically I want to emulate the tkinter virtual event / event_generate mechanism. $\endgroup$ – b3m2a1 Dec 14 '16 at 16:39
  • $\begingroup$ Ok, but how would event handlers know that they should react or not? Because if every EH should then you can just run event[] and Dynamics can catch that. $\endgroup$ – Kuba Dec 14 '16 at 16:50
  • $\begingroup$ Obviously I could just call a function if I have just one event handler, but say there are two in nested focus. The first could do event1[] on the "CustomEvent" call and the second could do event2[]. This is why tkinter allows you to register virtual events. I get what you're saying, though, wondering which event handlers would catch such a call, but I figure it's the same as how EventHandler or CellEventActions behave with "MenuCommand" tokens. Only event handlers with current focus should catch them. $\endgroup$ – b3m2a1 Dec 14 '16 at 17:23
  • $\begingroup$ The trick would be to have something like Dynamic[customEventSymbol; action;Spacer[0], TrackedSymbols :> {customEventSymbol}] as a "listner" and FrontEndTokenExecute translated to customEventSymbol++ or something. $\endgroup$ – Kuba Dec 14 '16 at 18:34

Your Answer

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

Browse other questions tagged or ask your own question.