4.3. Add Functionality with Callbacks

#!/usr/cogent/bin/phgamma

/*
 * This example adds a pane and a text-entry box to the last example.
 * The pane displays the color that corrresponds to the hexidecimal
 * numerical value entered in the text-entry box.
 *
 * This file is best viewed with a tab width of 4.
 */
 
require_lisp("PhotonWidgets");
PtInit(nil);

window = new(PtWindow);
window.SetDim (300,250);
window.fill_color = PgRGB (240,220,220);

/*
 * Make a new pane, and set its area using the SetArea function, which
 * combines SetPos and SetDim.
 */
pane = new(PtPane);
pane.SetArea (50,50,200,100);

/*
 * Set the window to be the parent for the next widgets.
 */
PtSetParentWidget(window);

/*
 * Make a new text box, set its area, and attach callbacks. The first
 * callback parses the entry string, and the second one changes the
 * color of the pane.
 */
entrybox = new(PtText);
entrybox.SetArea (115,160,60,25);
PtAttachCallback(entrybox,Pt_CB_TEXT_CHANGED,
                 #entry = parse_string(entrybox.text_string));
PtAttachCallback(entrybox,Pt_CB_ACTIVATE,#pane.fill_color = entry);

but = new(PtButton);
but.SetPos(130,205);
but.text_string = "Exit";
PtAttachCallback(but,Pt_CB_ACTIVATE,#exit_program(-1));

PtRealizeWidget(window);
PtMainLoop();