Re: Problem to open a new window using libglade



Am Freitag, den 02.03.2007, 11:33 -0500 schrieb
gtk-app-devel-list-request gnome org:
void
on_button1_clicked(GtkButton *button, gpointer data)
{
      /* the button was clicked */
      //Print out to console
      g_print("Beginn break\n");

      //Create the new "progress" window
      GladeXML        *gxml_progress = NULL;
      gxml_progress = glade_xml_new (GLADE_FILE, "window2", NULL);

      //show the window
      GtkWidget *window2 = glade_xml_get_widget(gxml_progress,
"window2");
      gtk_widget_show_all(window2);

      while (gtk_events_pending())
              gtk_main_iteration();

      //Make 5 sec. break
      g_usleep(5000000);
      g_print("End break\n");
} 

Hi there,

if I'm not completely mistaken here, this has nothing to do with glade.
The thing just is, that you need to return to the main loop from the
callback for the widgets to be drawn properly. 
That is prolly why you put in your gtk_main_iteration though I doubt
there is a guaranteed way to make this work.

So the complicated version would probably involve having hooking up a
callback to the configure event for the second window that starts smth.
and then automatically deregisters itself after the first run.

The other thing I've found to work is use a GTK_DIALOG rather than a
generic window and then do smth. along the lines of:

    result = gtk_dialog_run (GTK_DIALOG (dialog));

    if (result == GTK_RESPONSE_OK) {
        got_file_name =
            gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));

        xml = NULL;
        xml = glade_get_widget_tree (GTK_WIDGET (xvc_pref_main_window));
        g_assert (xml);

        w = NULL;
        w = glade_xml_get_widget (xml, "xvc_pref_sf_filename_entry");
        g_assert (w);

        gtk_entry_set_text (GTK_ENTRY (w), strdup (got_file_name));
    }

    gtk_widget_destroy (dialog);

Of course, if you're not really interested in the user's input you can
just ignore the result.

HTH,

Karl.





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