Update Functions - reset_value, write_data

Cogent Tools Demo and Tutorials: Version 4.0
Prev | Chapter 7. GTK Functions (in `gtksimple.g`) | Next

# 7.4. Update Functions - `reset_value`, `write_data`

These functions help connect a scale or spin button to a point in the Cascade DataHub. The first function (`reset_value`) adjusts the value of a widget to reflect a change in the datahub, while the second function (`write_data`) updates the datahub point from a change entered in the widget. In this manner, a two-way connection is maintained.

       /*--------------------------------------------------------------------
        * Function:    reset_value
        * Returns:     t or nil
        * Description: Resets the value of a widget's adjustment.
        *------------------------------------------------------------------*/
       function reset_value(widget, newval, adj_id)
       {
         local newadj;
         newadj = widget.get_adjustment();
         if (adj_id)
           {
             gtk_signal_handler_block (newadj, adj_id);
             newadj.set_value(100 - newval);
             gtk_signal_handler_unblock (newadj, adj_id);
           }
         else
           newadj.set_value(newval);
       }

Whenever the widget's adjustment gets reset, it sends a `"changed_value"` signal. This has to be blocked when the adjustment is due to a change in the Cascade DataHub, otherwise the widget will send an echo back to the datahub. The echo isn't visible in this application, but it would show up in a text log. For this reason, we use the Gamma/GTK functions `gtk_signal_handler_block` and `gtk_signal_handler_unblock` (documented in the Gamma/GTK List of Functions (Non Widget Specific) appendix) to block all signals from the adjustment while we reset the value.

       /*--------------------------------------------------------------------
        * Function:    write_data
        * Returns:     t or nil
        * Description: Reads a widget that contains an adjustment value,
        *              and writes its value to the datahub.
        *------------------------------------------------------------------*/
       function write_data(widget, !ptname)
       {
         local ptval;
         ptval = widget.get_adjustment();
         write_point(string(ptname), ptval.value);
       }

The Gamma function `write_point` is used to write the values to the datahub.

Prev | Home | Next
Making Scales and Spin Buttons - `make_scale`, `make_prog_bar`, `make_spinner` | Up | Button Functions - `toggle_sym`, `change_settings`

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