Re: [gtk-list] Disabling callbacks



On Wed, 02 Jun 1999 08:08:42 -1000, gtk-list@redhat.com (K. M. Hawarden-Ogata) wrote:
> I have a widget that calls a callback, which in turn changes a variable.
> Fine.
> 
> Going the other way, I change that variable and I want to undate (redraw)
> the widget to reflect the new state of the variable, without triggering the
> callback.
> 
> I read the documentation about signals and blocking them, but it's very
> sketchy. Does anyone have an idea about what I need to do?

I assume that you're trying to use a GtkAdjustment for a range widget.
I don't know if there is a simpler way to solve it, but I did it by using
a lock:


  static unsigned int lock = 0;
  static int variable;

  void callback_function(GtkWidget *widget, gpointer data)
  {
    if(lock == 0)
      {
         /* change the variable according to the widgets state */
         variable = *(int *)data;
      }
    else
      {
         /* the widget is already changed, so just lower the value of lock */
         lock --;
      }
  }

  void set_variable(int value)
  {
    variable = value;
    lock ++;
    gtk_whatever_the_widget_needs_to_set_its_value(widget, variable);
  }


Of course instead of using global variables you should pass a structure
through the data argument of the callback function, but I hope the basic
idea is clear.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]