Strange gtk signal connect



Hello everyone
In my application I use a button to navigate through displays ...
So I have to disconnect and reconnect signal but this is not working as
shown in the following exemple:
At the first button click, both f1 and f2 have been called ! 
Even with while loop gtk_events_pending 
I dont understand why ? Thanks for any help.
Olivier, FRANCE

int action;

gboolean f2 (GtkWidget *wid) {
  puts ("f2");
  return TRUE;
}

gboolean f1 (GtkWidget *wid) {
  puts ("f1");
  gtk_signal_disconnect(GTK_OBJECT(wid), action);
  while (gtk_events_pending()) gtk_main_iteration();
  action = gtk_signal_connect (GTK_OBJECT(wid), "clicked",
GTK_SIGNAL_FUNC(f2), NULL);
  return TRUE;
}

int main (int argc, char *argv[]) {

  GtkWidget *Window, *Button;

  gtk_init(&argc, &argv);
  Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  Button = gtk_button_new_with_label (" OK ");
  action = gtk_signal_connect(GTK_OBJECT(Button), "clicked",
GTK_SIGNAL_FUNC(f1), NULL);
  gtk_container_add (GTK_CONTAINER(Window), Button);
  gtk_widget_show_all (Window);
  gtk_main();  
  return 0;
}





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