Multiple calls to a signal handler




    I have a GtkEntry and a GtkHScale that work together.  The value of the
HScale is displayed in the Entry and the Entry is there so that a user can
type in a value rather than using the slider.  I have signal handlers for
the "value_changed" signal for the HScale and the "changed" signal for the
Entry.  In each signal handler, I compare the values of the two widgets and
if they don't match, I set the value in the widget that was not changed.  I
do this with gtk_range_set_value() and gtk_entry_set_text().

    The complication seems to be that when I manually set the value for the
Entry with gtk_entry_set_text(),  this causes the signal handler to be
called twice:  once for the deletion of the old text and a second time for
the insertion of the new text.  The first time that is called (for the
deleted old text) the values don't match.  So, my test to see if the values
match is false and it set the value of the slider which causes that signal
handler to be called again.  The second time (for the addition of the new
text) everything is set to the correct value.This seems to work, but the
signal handlers get called a total of 4 times in response to one change and
I am trying to add a call to a function that is called only after all of the
widgets have been updated and the signal handlers get called as soon as a
value is changed.  

    Is there a way to turn off the signal handler for the Entry while I am
manually settings its value from the signal handler for the HScale?  I see
g_signal_handler_block(), but I do not know the handler_id because
g_signal_connect() is called from within the glade generated code.  And, I
must have an older version of GTK+ installed, because
g_signal_handler_block_by_func() is not there.

Thanks,

Nathan




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