GUIKit`
GUIKit`

BindEvent

The functionality provided by GUIKit has been superseded by the interface construction and controls functions native to the built-in Wolfram Language.

BindEvent[name|{target,name}|{target,name,filter},object|script|call,]

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

Details and Options

  • To use BindEvent, you first need to load GUIKit using Needs["GUIKit`"].
  • BindEvent causes script code or other method calls to be executed when an event is triggered from the targeted widget.
  • BindEvent returns the object instance listener that is created as a result of requesting the binding.
  • BindEvent 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 "propertyChange" and "vetoableChange", 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 "#", "#1", "#2", 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 "x" and "y", 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 "ScriptEvaluator", 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.

Examples

Basic Examples  (1)

Bind a script to the button "Action" event:

Bind a script to the "MouseMoved" event that prints the "x" and "y" property values of the mouse event:

Wolfram Research (2007), BindEvent, Wolfram Language function, https://reference.wolfram.com/language/GUIKit/ref/BindEvent.html.

Text

Wolfram Research (2007), BindEvent, Wolfram Language function, https://reference.wolfram.com/language/GUIKit/ref/BindEvent.html.

CMS

Wolfram Language. 2007. "BindEvent." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/GUIKit/ref/BindEvent.html.

APA

Wolfram Language. (2007). BindEvent. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/GUIKit/ref/BindEvent.html

BibTeX

@misc{reference.wolfram_2024_bindevent, author="Wolfram Research", title="{BindEvent}", year="2007", howpublished="\url{https://reference.wolfram.com/language/GUIKit/ref/BindEvent.html}", note=[Accessed: 22-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_bindevent, organization={Wolfram Research}, title={BindEvent}, year={2007}, url={https://reference.wolfram.com/language/GUIKit/ref/BindEvent.html}, note=[Accessed: 22-December-2024 ]}