Re: [gtk-list] Re: [patch] mainloop



johannes@nada.kth.se (Johannes Keukelaar) writes:

> //This patch makes some fairly major changes to the GTK mainloop.  The
> //main effective difference is that the mainloop can be called
> //recursively from within a timeout or idle function. This probably
> //isn't too useful for GTK programs in general, but it is meant to allow
> //to allow the gtk mainloop to be used for hybrid GTK/ILU programs.
> 
> Does that mean that it was already possible to call the main loop recursively 
> from a signal callback? If that is so, is that the way to go about building 
> functions like, for example, my_ask_yes_or_no( "Really want to quit?" ), which 
> would pop up a modal dialog box and return after the user clicks on the yes or 
> no button?

 The way to implement modality is to use gtk_grab_add and
gtk_grab_remove see the below example.

static void destroy_error_window(GtkWidget *widget, GtkWidget *passed)
{
 gtk_grab_remove(passed);
 gtk_widget_destroy(passed);
}

static void error_window_print(const char *msg)
{
 GtkWidget *window = gtk_window_new(GTK_WINDOW_DIALOG);
 GtkWidget *label = gtk_label_new(msg);
 GtkWidget *vbox = gtk_vbox_new(FALSE, 0);
 GtkWidget *button = gtk_button_new_with_label("Ok");
 GtkWidget *separator = gtk_hseparator_new();
 
 gtk_window_set_title(GTK_WINDOW(window), "error message");
 gtk_container_border_width(GTK_CONTAINER (window), 10);
 
 gtk_container_add(GTK_CONTAINER(window), vbox);

 gtk_signal_connect(GTK_OBJECT(button), "clicked",
                    GTK_SIGNAL_FUNC(destroy_error_window),
                    GTK_OBJECT(window));

 gtk_box_pack_start_defaults(GTK_BOX(vbox), label);
 gtk_box_pack_start_defaults(GTK_BOX(vbox), separator);
 gtk_box_pack_start_defaults(GTK_BOX(vbox), button);
 
 gtk_widget_show(button);
 gtk_widget_show(separator);
 gtk_widget_show(label);
 
 gtk_widget_show(vbox);
 gtk_widget_show(window);

 gtk_grab_add(window);
}

-- 
James Antill -- newsmaster@demon.net



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