14.2. GTK: Interpolator Options Widgets - qry_radio_but, qry_entry

The qry_radio_but function creates the Interpolator options buttons, sets up their callbacks, and puts them into a table.

   /*--------------------------------------------------------------------
    * Function:    qry_radio_but
    * Returns:     A GtkRadioButton
    * Description: Creates the "Choose an Interpolator" radio buttons and
    *              puts them into a table.  The last 6 parameters simply
    *              get passed along to the allow_entry_values() function
    *              and the .change_int() method.
    *------------------------------------------------------------------*/
   function qry_radio_but(tbl, txt, butlist, int_set, msg,
                          top, bottom, w1, w2, w3, e1, e2, e3)
   {
     local button;
     button = gtk_radio_button_new_with_label(butlist, txt);
     if (txt == "NoInterpolator")
       {
         button.set_active(TRUE);
         allow_entry_values(w1, w2, w3, e1, e2, e3);      
       }

When the program starts, we want the NoInterpolator button pressed, and when we set the button active, we also have to code in the allow_entry_values function for that button. The callback for each button uses the change_int method to set up the query.

     button.signal("clicked", `((@int_set).change_int(@button, @txt, @w1, @w2,
                                                       @w3, @e1, @e2, @e3)));
     button_messages (button, msg, "6");
     tbl.attach_defaults(button, 0, 1, top, bottom);
     button;
   }
   

Since much of the setup and functionality is similar for our GtkEntry and GtkCombo widgets, we create them in a single function.

   /*--------------------------------------------------------------------
    * Function:    qry_entry
    * Returns:     A GtkEntry or GtkCombo widget, as specified
    * Description: Creates a GtkEntry or GtkCombo widget, sets defaut values,
    *              and puts it into a table.
    *------------------------------------------------------------------*/
   function qry_entry(tbl, txt, value, top, bottom)
   {
     local box, label, entry, cbitems, cmb, ent_but = nil;
   
     box = new(GtkHBox);
     label = new(GtkLabel);
     label.set_text(txt);
     label.width = 80;
     box.pack_start(label, TRUE, TRUE, 0);
   
     if ((strstr(txt, "history")) == -1)
       {
         entry = new(GtkEntry);
         entry.width = 75;
         if (value == nil)
           entry.set_text("");
         else
           entry.set_text(string(value));
         box.pack_start(entry, TRUE, TRUE, 0);
       }
     else
       {
         cbitems = list("MV_001", "PV_001");
         cmb = new(GtkCombo);
         cmb.width = 75;
         cmb.use_arrows = 0;
         cmb.set_popdown_strings(cbitems);
         entry = car(cmb.children());
         ent_but = cadr(cmb.children());
         entry.set_editable(FALSE);
         if (value == nil)
           entry.set_text("");
         else
           entry.set_text(string(value));
         box.pack_start(cmb, TRUE, TRUE, 0);
       }
     tbl.attach_defaults(box, 1, 2, top, bottom);
     entry;
   }