PhabCreateWidgets

PhabCreateWidgets — creates widgets from existing definitions.

Syntax

PhabCreateWidgets (widget_defs, parent, name_prefix)

		

Arguments

widget_defs

A list of widget definitions most likely generated using the library functions PhabLoad or PhabReadWidgetFile and its related functions.

parent

The parent for the new widgets. Pass nil for no parent.

name_prefix

A string prefix to use when creating names for newly created widgets. Pass nil to use existing widget names.

Returns

A list of widgets, or nil.

Description

This function is used when creating new windows from a window definition. Typically, but not necessarily, the window template is created using PhAB. New names are optionally given to each window widget.

Example

This example, ex_PhabCreateWidgets.g, is included in the product distribution.

#!/usr/cogent/bin/phgamma 

/*
This example reads a widget file that contains 8 buttons with .gif
images on them.  It creates the widgets and puts them into two
windows.  The first window contains all of the widgets, while the
second window contains a widget of your choice, which you can enter as
the third argument on the command line. To run this example, you must
be in a directory that can access the .wgt file.

The example takes an argument, <button name>, which can be one of:
Go, Stop, Pause, Done, Increase, Decrease, Left or Right.
*/

arg = string(cadr(argv));

if(string_p(arg))
{
  if((strcmp(arg, "Go") == 0) ||
	 (strcmp(arg, "Stop") == 0) ||
	 (strcmp(arg, "Pause") == 0) ||
	 (strcmp(arg, "Done") == 0) ||
	 (strcmp(arg, "Increase") == 0) ||
	 (strcmp(arg, "Decrease") == 0) ||
	 (strcmp(arg, "Left") == 0) ||
	 (strcmp(arg, "Right") == 0))
  {

	PtInit(nil);
	
	/*
	 * Rename some car/cdr functions to facilitate understanding.
	 */
	PhabGetTop = car;
	PhabGetRoot = car;
	PhabGetChildren = cdr;
	PhabGetLevel = car;
	PhabGetType = cadr;
	PhabGetName = caddr;
	
	require_lisp("PhotonWidgets.lsp");
	require_lisp("PhabTemplate.lsp");
	
	/*
	 * Read the widget definitions, and access them.
	 */
	file = string(_os_, "-WidgetFiles/wgt/buttons.wgtw");
	defs = PhabReadWidgetFile(file);
	tree = PhabGetTop(defs);
	children = PhabGetChildren(tree);
	
	/*
	 * Make a function to index the buttons by number.
	 */
	function index_buttons(buttons)
	  {
		local index = 1;
		indexlist = list();
		
		with button in buttons do
		{
		  local name = PhabGetName(car(button));
		  local name = PhabGetName(car(button));
		  indexlist = cons(list(name, index), indexlist);
		  index ++;
		}
		indexlist;
	  }
	
	/*
	 * Make a function to look up a requested button.
	 */
	function lookup (name, list)
	  {
		car(assoc(name, list));
	  }
	
	/*
	 * Make a new window, create all the buttons, and display them
	 * in the window.
	 */
	win = new(PtWindow);
	win.SetArea(100,50,120,500);
	win.title = "All";
	for (i=0;i<8;i++)
	{
	  eachbut = car(car(PhabCreateWidgets(list(car(nth_cdr(children,i)))
										  ,nil,nil)));
	  eachbut.SetPos(25, (i * 60));
	  PtRealizeWidget(eachbut);
	  PtExtentWidget(win);
	}
	
	/*
	 * Find the requested button.
	 */
	buttonlist = index_buttons(children);
	argument = cadr(argv);
	found = lookup(symbol(argument), buttonlist);
	index = cadr(found) - 1;
	
	/*
	 * Make a new window, create the requested button, and display it.
	 */
	win2 = new(PtWindow);
	win2.SetArea(250,50,100,140);
	win2.title = "Request";
	anybut = car(car(PhabCreateWidgets(list(car(nth_cdr(children,index)))
									   ,nil,nil)));
	anybut.SetPos(20, 20);
	
	exitbut = new(PtButton);
	exitbut.SetArea(30, 100, 40, 25);
	exitbut.text_string = "Exit";
	PtAttachCallback(exitbut,Pt_CB_ACTIVATE,#exit_program(1));
	
	
	PtRealizeWidget(win);
	PtMainLoop();
  }
  else
	princ ("Please enter an argument, one of: Go Stop Pause Done Increase Decrease Left Right \n");
}		
else
princ ("Please enter an argument, one of: Go Stop Pause Done Increase Decrease Left Right \n");

See Also

PhabReadWidgetFile