Next | Prev | Up | Top | Contents | Index

Adding Actions and Translations

Actions may be added to a widget in a way similar to the C version of Motif. You define an action for the widget in a translation table. In this binding, the Tcl code is placed as the arguments to the action in the translation table. Registering the translation using the action call links a generic action handler, which in turn handles the Tcl code.

This code adds a translation to turn an arrow left or right when the l or r key is typed:

#! /usr/sgitcl/bin/moat 
xtAppInitialize
xmArrowButton .arrow managed
.arrow setValues -translations \
   {<Key>r: action(arrow_direction %w arrow_right)
    <Key>l: action(arrow_direction %w arrow_left)  }
proc arrow_direction {arrow direction}  {
   puts stdout "Changing direction to $direction"
   $arrow setValues -arrowDirection $direction
}
. realizeWidget
. mainLoop
As with callbacks, substitutions are possible. The only one currently supported is %w, to substitute the current widget path. Other substitutions return an error message.


Next | Prev | Up | Top | Contents | Index