GTK: Building Control Buttons - control_button

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

# 12.3. GTK: Building Control Buttons - `control_button`

This function takes for its arguments a text string (`lbl`), a color, program and process names, several arguments, and a container (such as a box), as well as a widget and a message number (`msg`). The function makes a colored button with the text string as its label, and packs it into the container. When the button is clicked it calls the `start_stop` function, passing along itself, the program and process names, along with the arguments.

       /*--------------------------------------------------------------------
        * Function:    control_button
        * Returns:     A GtkToggleButton
        * Description: Builds control buttons.
        *------------------------------------------------------------------*/
       function control_button(lbl, color, prog, process_name, arg1,
                               arg2, arg3, container, wgt, msg)
       {
         local button;
         button = new(GtkToggleButton);
         button.label = lbl;
         button.set_color(1, GTK_STATE_NORMAL, color);
         button.set_color(1, GTK_STATE_PRELIGHT, (color + 0x111111));
         button.set_color(1, GTK_STATE_ACTIVE, (color - 0x111111));

The above lines assign a color, and make the button "light up" when the pointer is over it, and "darken" when it is toggled. The effect will work best if the button colors are of medium intensity, such as between `0xaaaaaa` and `0xdddddd`.

         container.pack_start(button, TRUE, TRUE, 0);
         button.signal("toggled", `start_stop(@button, @prog, @process_name,
                                              @arg1, @arg2, @arg3));
         button.signal("enter", `anygui_show_text(@wgt, read_msg(@msg), 1));
         button.signal("leave", `anygui_show_text(@wgt, read_msg("1"), 1));
         button.show();
         button;
       }

When the pointer enters (is over) a button, the message for that button is displayed in the Controller's text widget, and when the pointer leaves the button the Controller message is again displayed.

| Notice the use of the quote operators ``` and `@` in the `button.signal` method calls. The ``` operator prevents the `start_stop` function from being evaluated when the code is being read to create the button, and the `@` operators allow the `button`, `process_name`, `prog`, `arg`, `wgt`, and `msg` parameters to be evaluated at that time, so that their actual values get assigned to the `start_stop` function when it is called.

For more information on using GTK widgets in Gamma, please refer to the Gamma/GTK manual.

Prev | Home | Next
GTK: the Controller window - `create_control_win` | Up | Photon: the Controller window - `create_control_win`

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