BindEvent


binds an event from one object to a listener or to a script.

DetailsDetails

  • To use , you first need to load GUIKit using Needs["GUIKit`"].
  • causes script code or other method calls to be executed when an event is triggered from the targeted widget.
  • returns the object instance listener that is created as a result of requesting the binding.
  • is typically used with a Script block that gets evaluated in the Wolfram Language when an action occurs.
  • If there is no target specified, the wrapping context Widget is the target.
  • With BindEvent[ name|{target,name}|{target,name,filter},Script[]], when the event name occurs, the script is processed.
  • With BindEvent[ name|{target,name}|{target,name,filter},WidgetReference[listener]], the WidgetReference must resolve to an object that implements the appropriate listener interface.
  • If filter is specified, then only events that match that filter cause the script to be processed. In general, the filter is used to name a method in a listener type that has multiple methods (e.g., WindowEvent).
  • For event names and , the filter is the name of the property for which the binding should be done.
  • Each time a BindEvent action is triggered and the Script code is executed, specially registered objects associated with the current event are registered with the names , , , and so on, depending upon the number of arguments associated with the event listener callbacks. Almost all events register at least one object as representing the event object associated with this action. Typically, you might request properties of the event object as in the case of mouse events that provide properties, such as and , the location of the mouse.
  • In some rare cases it will be beneficial to trigger code execution that does not require evaluation in the kernel, specifically when a user interface would like to abort a currently executing evaluation through the user interface, typically with a Cancel button. This can be accomplished by associating an InvokeMethod request on a specially registered evaluator object referenced as , using BindEvent["action",InvokeMethod[{"ScriptEvaluator","abort"}]]. The framework will always make sure such a reference is defined for any live user interfaces to allow the user to programmatically abort current Wolfram Language evaluations.
  • The following option can be given:
  • NameNonethe name with which to register the new listener in the object registry
  • Name -> "myName" registers the new listener in the object registry for future lookup using WidgetReference["myName"]. This naming and lookup could be useful if you want to dynamically add or remove the listener from the bound widget, essentially providing a way to remove the binding listener.

ExamplesExamplesopen allclose all

Basic Examples  (1)Basic Examples  (1)

In[1]:=
Click for copyable input

Bind a script to the button event:

Bind a script to the event that prints the and property values of the mouse event: