spin decrements by itself



In the callback of a spin button  some calculations are done which can take
some time.
To prevent that the gui is dead during this time I have added a
g_main_iteration() in the callback.

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.

Any idea how to fix this? Or is it a gtk-bug?

See attached example.


Rob.


#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.
*/

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]