PtAttachCallback

PtAttachCallback — associates an action with a Photon event.

Syntax

PtAttachCallback (widget, callback_number, callback_function,
eventmask?|key_cap?, key_mods?, key_flags?)

		

Arguments

widget
The widget to attach the callback function on.
callback_number
The callback to trigger on.
callback_function
The function to call when the event occurs.
eventmask
An optional filter, for the callback only.
callbacks
Those that match this eventmask trigger the function.
keycap
Optional keyboard capture ID.
key_mods
Optional keyboard modifiers to the keycap (e.g. SHIFT, CTRL, ALT).
key_flags
Optional key flags (e.g. key up, key down, key repeat).

Returns

t when successful.

Description

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.

Example

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.

See Also

PtCallbackInfo, PtRemoveCallback