Multiple independent modal dialogs

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

 



Hi,

I have a short program (below) that displays two windows, each with a button. Clicking the button pops up a modal dialog (in this case a file chooser, but the type of the dialog does not really matter).

I would like the two windows to be completely independent, i.e. clicking the button in one window should not disable the other window and vice-versa.

I realize this can probably be done by avoiding gtk_dialog_run and handling the window interactions from the main loop, but that would make the development very tedious.

Obviously, if I wanted to nest main loops for two independent windows, I would have to run each window in its own thread. However, it seems that gtk_main can't be run from several threads at once.

So is there a way to accomplish the above without sacrificing the simplicity of gtk_dialog_run?

Thank you in advance.
----
#include <gtk/gtk.h>

static void on_click(GtkWidget *widget, gpointer sptr)
{
    GtkWidget * parent = (GtkWidget *)sptr;
    GtkWidget * dialog = gtk_file_chooser_dialog_new(
        "Open File", 0, GTK_FILE_CHOOSER_ACTION_OPEN,
        GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
        GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
    gtk_window_set_transient_for(GTK_WINDOW(dialog),
        GTK_WINDOW(parent));
    gtk_dialog_run (GTK_DIALOG (dialog));
    gtk_widget_destroy(dialog);
}

GtkWidget * create_window(void)
{
    GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    gtk_widget_set_usize(window, 200, 200);
    g_signal_connect(G_OBJECT (window), "delete_event",
        G_CALLBACK(gtk_main_quit), NULL);

    GtkWidget * button = gtk_button_new ();
    gtk_button_set_label(GTK_BUTTON(button), "show dialog");
    g_signal_connect(G_OBJECT (button), "clicked",
        G_CALLBACK(on_click), (gpointer) window);
    gtk_widget_show(button);

    gtk_container_add(GTK_CONTAINER (window), button);
    gtk_widget_show(window);
}

int main(int argc, char *argv[])
{
    gtk_init (&argc, &argv);
    GtkWidget * wnd1 = create_window();
    GtkWidget * wnd2 = create_window();
    gtk_main();
}
--
Martin
_______________________________________________
gtk-list mailing list
gtk-list@xxxxxxxxx
http://mail.gnome.org/mailman/listinfo/gtk-list

[Index of Archives]     [Touch Screen Library]     [GIMP Users]     [Gnome]     [KDE]     [Yosemite News]     [Steve's Art]

  Powered by Linux