gk::event

Generate and respond to local events

Synopsis

gk::event notify event params
gk::event bind event script
gk::event delete binding

Description

The gk::event command provides a way to have one part of the application generate an event that another part of the application can respond to, without either part having to know directly about the other.

Events consist of an event name, and a list of parameters providing more details about the event. Each parameter is itself a two item list, consisting of a key (which must be a single character) and an associated value. An event is generated using the "notify" option.

To respond to an event, a binding must be established. The "bind" option arranges for script to be called whenever an event named event is generated. The "bind" option returns a binding, which can be passed to the "delete" option if your program no longer wishes to be notified of the event. The event name specified in the "bind" option can also include wildcards, following the rules of the "string match" command.

To get the value of event parameters, the script undergoes "percent substitution" before being evaluated. Occurences of the two characters percent ("%") followed by the character representing an event parameter are replaced by the value of that event parameter. This is the same mechanism used to access parameters in Tk's event mechanism.

Note that the gk::event command uses a single instance of a gk::notifier object. You can create other instances of gk::notifier objects for other uses in your application.

Example

set binding [gk::event bind newUserArrived "handleNewUser %U"]
...
gk::event notify newUserArrived [list [list U 25]]
...
gk::event delete $binding

GroupKit Reference Manual. Last updated March 13, 1998 by Mark Roseman.