Extract Certain Widgets

Gamma/Photon: Using Gamma™ with the Photon microGUIŽ, Version 4.0
Prev | Chapter 4. Building Applications - a Tutorial | Next

# 4.9. Extract Certain Widgets

    #!/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. Type the 2 arguments
    buttons and [button name] at the shell prompt, where [button name]
    can be one of: Go, Stop, Pause, Done, Increase, Decrease, Left or Right.
    */

    PtInit(nil);

    /*
     * Create some convenience functions.
     */
    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("WidgetFiles/wgt/", cadr(argv),".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));
    		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);
    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 = caddr(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,120,120);
    anybut = car(car(PhabCreateWidgets(list(car(nth_cdr(children,index)))
    	,nil,nil)));
    anybut.SetPos(20,40);

    PtRealizeWidget(win);
    PtMainLoop();

Prev | Home | Next
Read and Print a Widget File | Up | Encapsulate Loading and Creating Widgets

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