4.11. Select and Recreate Any Widget

#!/usr/cogent/bin/phgamma

/*
 * This example is similar to the previous one, in that it pulls
 * specified widgets out of an existing widget, named readtestfile.wgtw.
 * Enter the name for the widget of your choice on the command
 * line.  The possible names are: MyTestFile (brings the whole
 * widget), MainWindowButton, PaneOne, PaneOneButtonA,
 * PaneOneButtonB, PaneTwo, and PaneTwoButtonC.
 */   
   
PtInit(nil);
require_lisp("PhotonWidgets");
require_lisp("PhabTemplate");

/*
 * Read the widget definitions, and access them.
 */
file = string("WidgetFiles/wgt/readtestfile.wgtw");
defs = PhabReadWidgetFile(file);
treewin = car(defs);
 
/*
 * Make a function that walks a widget tree and finds the widget
 * you want. (The same as in the previous example.)
 */
function PhabLookupTree(tree,name)
  {
    local return = nil;
    local trees;
    if (caddr(car(tree)) == name)
      return = tree;
    else
      {
	for (trees = cdr(tree); trees && !return; trees = cdr(trees)){
	   return = PhabLookupTree(car(trees),name);
	 }
      }
    return;
  }

/*
 * Make a new window to hold the widget.
 */
win = new(PtWindow);
win.SetDim(500,450);

/*
 * Call the PhabLookupTree function on a widget from the command line.
 */
read_name = symbol(cadr(argv));
wgtdef = PhabLookupTree(treewin,read_name);

/*
 * Transform the widget tree into a widget definition.
 */
wgtdef = cons(wgtdef,nil);

/*
 * Create the widget.
 */
wgt = PhabCreateWidgets(wgtdef,nil,nil);	  

/*
 * Realize the widget by realizing the window.
 */
PtRealizeWidget(win);
PtMainLoop();			
 
		

Copyright 1995-2002 by Cogent Real-Time Systems, Inc.