4.5. Read a Widget File and Create its Widgets

#!/usr/cogent/bin/phgamma

/* This example is the second of three ways to incorporate a
 * PhAB-created GUI into a Gamma program.  It produces the same output
 * as the previous example, but instead of using the PhabLoad()
 * function, it calls PhabReadWidgetFile() and PhabCreateWidgets().
 * This allows for naming the widgets locally, and independently of
 * their original names, unlike PhabLoad(), which assigns global
 * variables that correspond to widget names.  */
 
require_lisp("PhotonWidgets.lsp");
require_lisp("PhabTemplate.lsp");
PtInit(nil);

/*
 * Read the widget file.
 */
wfile = PhabReadWidgetFile (string(_os_, "-WidgetFiles/wgt/colortest.wgtw"));

/*
 * Create widgets from the widget file that was read.
 */
window = PhabCreateWidgets(wfile, nil, nil);

/*
 * Find the widgets to be used, and assign them new names.
 */
ct = PhabLookupWidget(window,#colortest,nil);
eb = PhabLookupWidget(window,#entrybox,nil);
pn = PhabLookupWidget(window,#colorpane,nil);
bt = PhabLookupWidget(window,#exitbutcolortest,nil);

PtAttachCallback(eb,Pt_CB_TEXT_CHANGED,
                 #entry = parse_string(eb.text_string));
PtAttachCallback(eb,Pt_CB_ACTIVATE,#pn.fill_color = entry);
PtAttachCallback(bt,Pt_CB_ACTIVATE,#exit_program(-1));

PtRealizeWidget(ct);
PtMainLoop();