Block a signal seems not to work
- From: "Peter T. Mayer" <peter_t_mayer yahoo de>
- To: gtk-list gnome org
- Subject: Block a signal seems not to work
- Date: Mon, 17 May 2004 18:13:31 +0200
Hello,
After I have irked myself for 3 days with blocking a signal and couldn't
find a solution I ask here for help:
I connect a signal handler as follows:
g_signal_connect ((gpointer) hscale1, "value_changed",
G_CALLBACK (on_hscale1_value_changed),
NULL);
and this is the corresonding callback function:
void
on_hscale1_value_changed (GtkRange *range,
gpointer user_data)
{
double oldtime= gtk_range_get_value (range);
g_signal_handlers_block_by_func ((gpointer) range, G_CALLBACK
(on_hscale1_value_changed), NULL);
double newtime= go_to_position (GTK_WIDGET (range), oldtime);
gtk_range_set_value (range, newtime );
g_signal_handlers_unblock_by_func ((gpointer) range, G_CALLBACK
(on_hscale1_value_changed), NULL);
}
The function go_to_position calculates newtime by finding the nearest
possible value around oldtime, this means oldtime will always differ
slightly from newtime. Now I want to display the correct value and not
the one which was set by the user. So I call "gtk_range_set_value
(range, newtime );". But then the callback is called again (because the
value has changed to newtime). The problem is that in most cases
"newtime= go_to_position (GTK_WIDGET (range), oldtime);" will give you a
different newtime value, even if in the function call before oldtime was
already calculated by go_to_position. So you get an never ending loop.
This happens also, if you block (as shown above) or even disconnect the
handler. If for testing purposes I only block and do not unblock the
signal (comment out the last line of on_hscale1_value_changed), this
works as expected. So the signal must be stored until I unblock the handler.
If you want to test the described case write the following
go_to_position function:
double go_to_position( GtkWidget *dialog, double seconds ) {
printf( "Time: %.1f\n", seconds );
return seconds+0.1;
}
How could I stop this behavior?
Thanks,
Peter!
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]