Spin decrements by itself
- From: alblas <r alblas demon nl>
- To: "gtk-app-devel-list redhat com" <gtk-app-devel-list redhat com>
- Subject: Spin decrements by itself
- Date: Sat, 27 Oct 2001 19:15:41 +0200
In the callback of a spin button some calculations are done in a loop
which can take some time (1 sec or less).
To prevent that the gui is dead during this time I have added a
g_main_iteration() in the loop.
Now, as soon as I click on the spin button (either up or down arrow) the
spin button starts to decrement 'by itself', until it has reached its
lowest
state.
If I remove the g_main_iteration() everything works normal.
Also, if I remove the long calculation, the spin button works as
expected.
So, the combination of g_main_iteration() and a "long" execution time
of
the callback gives problems.
If replace the spin button by a normal button (and a printf in the
callback to see if it is activated) everything works fine (just 1
callback activation for each button press).
Any idea how to fix this? Or is it a gtk-bug?
See attached example.
Rob.
(Note: This problem was addressed earlier, I didn't get any reaction.
Maybe because it was in a wrong 'thread'?)
#include "gtk/gtk.h"
/* NOTE: Next is just a simple example which shows the spin problem.
In reality the sleep is a loop in which a calculation
on several data items is done;
the g_main_iteration() is also in this loop.
The sleep is here 1 sec, but the problems also pop up with much less
delay (100ms or even lesser).
*/
void func(GtkWidget *widget, gpointer data)
{
char *name=(char *)data;
if (!strcmp(name,"Spintest")) puts("Spin");
/* If one of the 2 next lines is removed the spin works fine. */
sleep(1); /* simulate long execution time */
while (g_main_iteration(FALSE)); /* serve gui */
}
int main(int argc, char **argv)
{
GtkWidget *wnd,*spin;
GtkObject *adjustment;
gtk_init(&argc, &argv);
wnd = gtk_window_new(GTK_WINDOW_TOPLEVEL);
adjustment = gtk_adjustment_new(10,0,100,1,1, 0.0);
spin = gtk_spin_button_new(GTK_ADJUSTMENT(adjustment),1.0,1);
gtk_signal_connect(GTK_OBJECT(adjustment),"value-changed",
GTK_SIGNAL_FUNC(func), "Spintest");
gtk_container_add(GTK_CONTAINER(wnd),spin);
gtk_widget_show_all(wnd);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]