Re: Dialog-like window?



I just make myself a dialog in Glade and then use gtk_dialog_run... the

result it returns just lets you know what button was clicked... once that is done you can take any information you want from the dialog before returning from the function. Below is a little example. Let's say you have a dialog made in glade called "dialog1" and on that dialog you have the stock "Ok" and "Cancel" buttons. Inside the dialog is an Entry called "entry1" where you want to get a string from the user.

You could then use this "dialog" as a function such as: g_print("You typed: %s", dialog_get_string ()); or gchar *some_string = dialog_get_string ();

gchar *
dialog_get_string ()
{
      GladeXML                *gxml = NULL;
      GtkWidget               *dialog = NULL;
      GtkWidget               *entry = NULL;
GtkResponseType response; gchar *str = NULL; /* build dialog from glade */

gxml = glade_xml_new ("gui.glade", "dialog1", NULL); dialog = glade_xml_get_widget (gxml, "dialog1");
      entry = glade_xml_get_widget (gxml, "entry1");
response = gtk_dialog_run (GTK_DIALOG(dialog)); /*
      function sits here waiting for the user to click a button
      on my home-made dialog. Let's say that in this example I
      have "Ok" and "Cancel". I will just return str as NULL if
      the user clicks cancel, but will return the contents of the
      entry if they click "Ok".
      */

      if (response == GTK_RESPONSE_OK)
      {
              /* get value from the text */
              str = g_strdup (gtk_entry_get_text (GTK_ENTRY (entry)));

              /*
              this is also where you could get values to populate
              some struct you want to return to user
              */
}
      /* clean up */
      gtk_widget_destroy (dialog);
      gtk_object_unref (GTK_OBJECT (gxml));
return str;
}


- Micah Carrick
www.micahcarrick.com     www.gtkforums.com

Fabricio Rocha wrote:
Dudes,

Is there a way of creating a window which, when shown, will cause the caller function to sit and wait until it gives a result? I mean, something like the GtkDialogs and gtk_dialog_run. However, as far as I understood, a normal GtkDialog only "returns" integer values.

I ask this because I would like to have a certain dialog working itself like a function, building a structure according to whatever is shown or input in its widgets, and then returning this structure (or any other type) when the user clicks on OK. Then the program would continue from the point where the "open_dialog function" was called, using the data structure (or any other value type) which has been created with the dialog.

I have seen this behaviour in other programming languages/toolkits, but still haven´t got a clue of how to emulate this in GTK. What do you suggest?

Thank you!

Fabricio Rocha
Brasilia, Brasil
The RADiola Project
http://radiola.sourceforge.net

		
_______________________________________________________ Yahoo! Mail - Sempre a melhor opção para você! Experimente já e veja as novidades. http://br.yahoo.com/mailbeta/tudonovo/
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list






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