10.4. GTK or Photon (in lib/gtk.g, lib/photon.g)

Section 10.4.1, “Displaying Text - anygui_show_text”
Section 10.4.2, “Process Termination - anygui_sigchild”
Section 10.4.3, “Process Termination - anygui_destroyer”
Section 10.4.4, “Buttons - .switched_on”
Section 10.4.5, “Moving the Window - anygui_move_window”
Section 10.4.6, “Change PID settings in the Monitor - anyos_change_settings”
Section 10.4.7, “Creating a Message/Dialog Window - anygui_makemsg”

10.4.1. Displaying Text - anygui_show_text

The GTK version of this function selects a type font, deletes the existing message from the GtkText widget, and inserts the new text string, using GTK method calls. The Photon version simply uses a method call to insert the new text string.

10.4.1.1. For GTK (lib/gtk.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_show_text
    * Returns:     t or nil
    * Description: Displays a message string in a text widget.  The fnt
    *              argument is only used in the GTK version of this
    *              function, and is ignored by the Photon version.
    *------------------------------------------------------------------*/
   function anygui_show_text(wgt, str, fnt)
   {
     local font;
     switch (fnt)
       {
       case 1: font = gdk_font_load (FONT1);
       case 2: font = gdk_font_load (FONT2);
       case 3: font = gdk_font_load (FONT3);
       }
     wgt.delete_text(0, -1);
     wgt.insert(font, nil, nil, str, -1);
   }
   

10.4.1.2. For Photon (lib/photon.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_show_text
    * Returns:     t or nil
    * Description: Displays a message string in a text widget.  The fnt
    *              argument is only used in the GTK version of this
    *              function, and is ignored by the Photon version.
    *------------------------------------------------------------------*/
   function anygui_show_text(wgt, str, fnt)
   {
     wgt.text_string = str;
   }
   

10.4.2. Process Termination - anygui_sigchild

The difference between these two functions is simply the two different ways to release a toggled button programmatically in GTK and Photon. They both call the child_died function.

10.4.2.1. For GTK (lib/gtk.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_sigchild
    * Returns:     t or nil
    * Description: Pops out a button when the corresponding child dies.
    *------------------------------------------------------------------*/
   function anygui_sigchild ()
   {
     child_died(#button.set_active(FALSE));
   }
   

10.4.2.2. For Photon (lib/photon.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_sigchild
    * Returns:     t or nil
    * Description: Pops out a button when the corresponding child dies.
    *------------------------------------------------------------------*/
   function anygui_sigchild ()
   {
     child_died(#button.flags = cons(Pt_SET, nil));
   }
   

10.4.3. Process Termination - anygui_destroyer

10.4.3.1. For GTK (lib/gtk.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_destroyer
    * Returns:     t or nil
    * Description: Tells a program to exit when a widget (generally its
    *              main window) gets destroyed.
    *------------------------------------------------------------------*/
   function anygui_destroyer(wgt)
   {
     wgt.signal ("destroy", #exit_program(0));
   }
   

10.4.3.2. For Photon (lib/photon.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_destroyer
    * Returns:     nil
    * Description: A space-holder for a function only used in GTK.
    *------------------------------------------------------------------*/
   function anygui_destroyer(wgt)
   {
     nil;
   }
   

10.4.4. Buttons - .switched_on

Several demo functions need to check if a toggle button has been pressed or not. Most of these can be generalized simply by abstracting the check-for-button-pressed part of the code, which is what these methods do.

10.4.4.1. For GTK (lib/gtk.g)

   /*--------------------------------------------------------------------
    * Function:    GtkButton.switched_on
    * Returns:     t or nil
    * Description: Creates common method to check Gtk and Photon buttons's 
    *              toggled status.
    *------------------------------------------------------------------*/
   method GtkButton.switched_on()
   {
     if (.get_active() == TRUE)
       t;
     else
       nil;
   }
   

10.4.4.2. For Photon (lib/photon.g)

   /*--------------------------------------------------------------------
    * Method:      PtLabel.switched_on
    * Returns:     t or nil
    * Description: Creates common method to check Gtk and Photon buttons's 
    *              toggled status.  The on/off flag for a PtButton is
    *              inherited from the parent class, PtLabel.
    *------------------------------------------------------------------*/
   method PtLabel.switched_on()
   {
     if ((.flags & Pt_SET) != 0)
           t;
     else
           nil;
   }
   

10.4.5. Moving the Window - anygui_move_window

10.4.5.1. For GTK (lib/gtk.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_move_window
    * Returns:     t or nil
    * Description: Moves the History or Log window to the left when the 
    *              Plot button is pressed to allow space to show the plot.
    *------------------------------------------------------------------*/
   function anygui_move_window(button, window, old_x, old_y, new_x, new_y)
   {
     if(instance_p(window))
       {
         if (button.switched_on())
           window.reposition(new_x, new_y);
         else
           window.reposition(old_x, old_y);
       }
   }
   
   

10.4.5.2. For Photon (lib/photon.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_move_window
    * Returns:     nil
    * Description: A space-holder for a function only used in Linux/GTK.
    *------------------------------------------------------------------*/
   function anygui_move_window(button, window, old_x, old_y, new_x, new_y)
   {
     nil;
   }
   
   

10.4.6. Change PID settings in the Monitor - anyos_change_settings

This function has been abstracted because of a characteristic in GTK widgets that isn't shared by Photon widgets. When you change a widget in GTK programmatically, such as click a button or move a slider, it automatically invokes any associated callback. The same programmatic change in Photon doesn't invoke a callback.

In addition, the main part of the Photon version of this function has to be abstracted further to handle a discrepancy between Photon 1.14 (QNX 4) and Photon 2 (QNX 6), by making a call to the anyver_change_settings function .

10.4.6.1. For GTK (lib/gtk.g)

   /*--------------------------------------------------------------------
    * Function:    anyos_change_settings
    * Application: Monitor
    * Returns:     t or nil
    * Description: Changes PID settings in the Monitor, and optionally
    *              unclicks the Auto button if it is on.
    *------------------------------------------------------------------*/
   function anyos_change_settings(button, auto, sp1, v1, sp2, v2, sp3, v3, sp4,
                                  v4, sp5, v5, sp6, v6, msgno, autobutton?)
   {
     if (button.get_active() == TRUE)
       {
         if (auto == nil)
           {
             if (AUTO_001 != 0)
               autobutton.clicked();
           }
         else
           sp1.set_value(v1);
         sp2.set_value(v2);
         sp3.set_value(v3);
         sp4.set_value(v4);
         sp5.set_value(v5);
         sp6.set_value(v6);
       }
   }
   

10.4.6.2. For Photon (lib/photon.g)

   /*--------------------------------------------------------------------
    * Function:    anyos_change_settings
    * Application: Monitor
    * Returns:     function
    * Description: Used by the Monitor to change PID settings, and optionally
    *              unclick the Auto button if it is on.  The PtNumeric widgets
    *              don't execute callbacks after they have been moved
    *              programmatically, so we have to write the point to the
    *              DataHub using write_point() each time a setting changes.
    *------------------------------------------------------------------*/
   function anyos_change_settings(auto, sp1, v1, sp2, v2, sp3, v3, sp4, v4,
                                  sp5, v5, sp6, v6, msgno, autobutton?)
   {
     if (auto == nil)
       {
         if (AUTO_001 != 0)
           {
             autobutton.onoff_state = 0;
             write_point(#AUTO_001, 0);
           }
       }
     else
       {
         autobutton.onoff_state = 1;
         write_point(#AUTO_001, 1);
         sp1.numeric_value = v1;
         write_point(#FREQ_001, v1);
       }
     anyver_change_settings(sp2, v2, sp3, v3, sp4, v4,
                            sp5, v5, sp6, v6);
     
     write_point(#PID1_Kp, v2);
     write_point(#PID1_Ki, v3);
     write_point(#PID1_Kd, v4);
     write_point(#PROP_001, v5);
     write_point(#INT_001, v6);
   }
   

10.4.7. Creating a Message/Dialog Window - anygui_makemsg

This function has been abstracted because message/dialog windows are created differently in GTK than in Photon. GTK uses a GtkDialog widget, which requires a fair amount of setup. Photon's PtMessage widget has more default settings, and thus requires less coding in our case, which is a fairly basic.

10.4.7.1. For GTK (lib/gtk.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_makemsg
    * Returns:     t or nil
    * Description: Creates and displays a message window.
    *------------------------------------------------------------------*/
   function anygui_makemsg(msg)
   {
     if ((undefined_p(win_dialog)) || (win_dialog == nil))
       {
         local vbox, vboxchildren, separator, action_area, button, label;
         
         win_dialog = new (GtkDialog);
         win_dialog.signal ("destroy", #win_dialog = nil);
         win_dialog.set_usize(550, 170);
         win_dialog.set_title("Advisory");
         
         vbox = car(win_dialog.children());
         separator = car(vbox.children());
         action_area = cadr(vbox.children());
         
         button = new(GtkButton);
         button.label = "OK";
         button.width = 70;
         button.can_default = TRUE;
         button.signal("clicked", `(@win_dialog).destroy());
         action_area.pack_start(button, FALSE, FALSE, 0);
         button.grab_default();
         button.show();
         
         lbl = new(GtkLabel);
         lbl.set_text(msg);
         lbl.set_padding(10, 10);
         vbox.pack_start(lbl, TRUE, TRUE, 0);
         lbl.show();
         
         win_dialog.show();
         win_dialog;
       }
     else
         if(instance_p(win_dialog))
           win_dialog.destroy();
   }
   

10.4.7.2. For Photon (lib/photon.g)

   /*--------------------------------------------------------------------
    * Function:    anygui_makemsg
    * Returns:     t or nil
    * Description: Creates and displays a message window.
    *------------------------------------------------------------------*/
   function anygui_makemsg(msg)
   {
     if ((undefined_p(msgwin)) || (destroyed_p(msgwin)))
       {
         msgwin = new(PtMessage);
         msgwin.msg_text = msg;
         msgwin.msg_button1 = " OK ";
         PtRealizeWidget(msgwin);
       }
     else
       if (instance_p(msgwin))
         PtDestroyWidget(msgwin);
   }