4.6. Read a Widget File and Assign its Widgets to a Class

#!/usr/cogent/bin/phgamma

/* This example is the third of three ways to incorporate a
 * PhAB-created GUI in a Gamma program.  It uses PhabAttachWidgets()
 * to assign the widgets to one global class, with each widget as an
 * instance of the class.  For most programming situations, this is
 * probably the best of the three alternatives.  */
 
require_lisp("PhotonWidgets.lsp");
require_lisp("PhabTemplate.lsp");
PtInit(nil);

/* Create the class.*/
class ColorTest
{
  window;
}

/* Attach the widgets to the class. */
PhabAttachWidgets (ColorTest, string (_os_, "-WidgetFiles/wgt/colortest.wgtw"));

/* Set up the constructor to instantiate the widgets inside the window. */
method ColorTest.constructor ()
{
  .window = PhabRoot(.PhabInstantiate (t));
}

/* Create a new instance of the class and realize it. */
cwin = new (ColorTest);
PtRealizeWidget (cwin.window);

/* Assign callbacks by calling the widgets as instances of
 * the ColorTest class.*/
PtAttachCallback(cwin.entrybox,Pt_CB_TEXT_CHANGED,
                 #entry = parse_string(cwin.entrybox.text_string));
PtAttachCallback(cwin.entrybox,Pt_CB_ACTIVATE,#cwin.colorpane.fill_color = entry);
PtAttachCallback(cwin.exitbutcolortest,Pt_CB_ACTIVATE,#exit_program(-1));

PtMainLoop();