Photon: the Controller window - create_control_win

Cogent Tools Demo and Tutorials: Version 4.0
Prev | Chapter 12. Controller Functions | Next

# 12.4. Photon: the Controller window - `create_control_win`

The Controller window in Photon 1.14 was created using PhAB in QNX 4, and was then imported into the Builder for Photon 2, and modified slightly for use in QNX 6.

       /*--------------------------------------------------------------------
        * Function:    create_control_win
        * Returns:     doesn't return
        * Description: Creates the Controller window.
        *------------------------------------------------------------------*/
       function create_control_win()
       {
         local wfile, window, control_win, pbut, mbut, dbut, lbut;
         local hbut, xbut, text, textatt, control_widgetfile, gamstring;

         wfile = PhabReadWidgetFile(anyos_assign("control_widgetfile"));
         gamstring = anyos_assign("gamstring");

As with the Monitor in Tutorial One, we use the Gamma/Photon `PhabReadWidgetFile` function to read the widget from the Phab file. However, instead of using an `if` statement to choose the correct widget file based on the OS, we use the abstracted function `anyos_assign` to reassign a generic string. The version of `anyos_assign` that gets called, and the string it assigns, are determined by which library is loaded: `lib/qnx4.g` or `lib/qnx6.g`. We also use that function to create a single string (`"gamstring"`) to represent either `"phgamma"` or `"gamma"` for starting programs in QNX 4 or QNX 6, respectively.

         window = PhabCreateWidgets(wfile, nil, nil);
         control_win = PhabLookupWidget(window, #Ptcontrol, nil);
         tframe =  PhabLookupWidget(window, #PtTitle, nil);
         pbut = PhabLookupWidget(window, #Ptpbut, nil);
         mbut = PhabLookupWidget(window, #Ptmbut, nil);
         dbut = PhabLookupWidget(window, #Ptdbut, nil);
         lbut = PhabLookupWidget(window, #Ptlbut, nil);
         hbut = PhabLookupWidget(window, #Pthbut, nil);
         helpbut = PhabLookupWidget(window, #Pthelpbut, nil);
         xbut = PhabLookupWidget(window, #Ptxbut, nil);
         rbut = PhabLookupWidget(window, #Ptrbut, nil);
         text = PhabLookupWidget(window, #Pttext, nil);
         anygui_show_text(text, read_msg("1"), nil);
         text2 = PhabLookupWidget(window, #Pttext2, nil);
         show_names(text2);

Once we have loaded the widget file, we can look up each widget and assign it a name for local use. After that, we assign callbacks to each of the buttons using the `attach_msg` function and Gamma/Photon's `PtAttachCallback` function. Finally, we start the main loop using Gamma/Photon's `PtMainLoop` function.

         attach_msg(pbut, "2", "1");
         attach_msg(mbut, "3", "1");
         attach_msg(dbut, "4", "1");
         attach_msg(lbut, "5", "1");
         attach_msg(hbut, "6", "1");

         PtAttachCallback(pbut, Pt_CB_ACTIVATE,
                          `start_stop(@pbut, gamstring, "emul", "emul.g"));
         PtAttachCallback(mbut, Pt_CB_ACTIVATE,
                          `start_stop(@mbut, gamstring, "monitor", "phmonitor.g"));
         PtAttachCallback(dbut, Pt_CB_ACTIVATE,
                          `start_stop(@dbut, "phdhview", "pidviewer", "-d", "toolsdemo"));
         PtAttachCallback(lbut, Pt_CB_ACTIVATE,
                          `start_stop(@lbut, gamstring, "log", "phlog.g"));
         PtAttachCallback(hbut, Pt_CB_ACTIVATE,
                          `start_stop(@hbut, gamstring, "history", "phhistory.g"));
         PtAttachCallback(rbut, Pt_CB_ACTIVATE, `toggle_raw(@rbut, @text2));

         PtAttachCallback(helpbut, Pt_CB_ACTIVATE, #anyos_help());
         PtAttachCallback(xbut, Pt_CB_ACTIVATE, #stop_processes());
         PtAttachCallback(xbut, Pt_CB_ACTIVATE, #exit_program(-1));

         control_win.SetPos(0, 0);

         PtRealizeWidget(control_win);

         PtMainLoop();
       }

Prev | Home | Next
GTK: Building Control Buttons - `control_button` | Up | Common: The Text Message Display - `read_msg` and `messages.txt`

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