Read a Widget File and Assign its Widgets to a Class

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

# 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, "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();

Prev | Home | Next
Read a Widget File and Create its Widgets | Up | Set, Test, and Clear Widget Flags

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