PtAttachCallback (widget, callback_number, callback_function, eventmask?|key_cap?, key_mods?, key_flags?)
The PtAttachCallback function is one of the most useful functions to use with Photon in Gamma. This functions allows an action to be associated with a Photon event.
The callback_number is usually expressed as a constant. For example, Pt_CB_ACTIVATE, Pt_CB_RAW, Pt_CB_SELECTION. A list of the available callbacks is given with each widget definition in the widget reference.
The callback_function is protected using quote operators (#, `, and @) and is evaluated only when the callback occurs.
The eventmask is used to look for specific events. For example, the callback number Pt_CB_BUT_PRESS can be masked with the event mask constant Pt_EV_BUT_RELEASE so that the callback function is only called when the mouse button is released.
This example, ex_PtAttachCallback.g, is included in the product distribution.
#!/usr/cogent/bin/phgamma
require_lisp("PhotonWidgets.lsp");
PtInit(nil);
win = new(PtWindow);
win.SetDim(200,50);
function pressed (held)
{
if (!held)
widget.text_string = string("Pressed: cb called ",counter++," times");
else
widget.text_string = string("Held: cb called ",counter++," times");
}
counter = 1;
button = new(PtButton);
button.SetPos(10, 10);
button.text_string = "------ Press Me ------";
PtAttachCallback(button,Pt_CB_ACTIVATE,#pressed(nil));
PtAttachCallback(button,Pt_CB_REPEAT,#pressed(t));
PtRealizeWidget(win);
PtMainLoop();
See the Callback Functions section of the Photon Functions chapter (Tutorial One), or the Photon: the Controller window of the Controller Functions chapter (Tutorial Two) in the Cogent Tools Demo and Tutorials book for an example of this function used in context.
Copyright © 1995-2006 by Cogent Real-Time Systems, Inc. All rights reserved.