newbie needs snippet : how to obtain a string from the user in a dialog
- From: ronald <raalst caiway nl>
- To: gtk-app-devel-list gnome org
- Subject: newbie needs snippet : how to obtain a string from the user in a dialog
- Date: Thu, 24 Feb 2005 23:34:52 +0100
Hi all,
Forgive me but I am an cut& paste type cobbler.
I am trying to make a GTK frontend for an FM tuner (included in my TV
card)
I have a working ncurses/C program and I want to exercise the brain
by fitting it with a GTK front instead (also in C)
So far I used glade and populated the callbacks. they work nicely.
but I want to be able to "mark" frequencies with names so you can build
a list of stations. This requires a popup dialog.
I use a dialog with a gtk_entry in it. my main wonder is how to
get the text from that entry when the user presses the OK button.
since the OK button is connected with a destroy-dialog action,
I am confused how to get at the results of the users' effort.
all examples I can find are the "user presses button" type,
not the "user does input".
I have to insert my actions into that destroy chain of
events somehow, but I dunno how.
does anybody have a C snippet handy, perhaps ?
Thanks in advance
My code so far (please, I am only a newbie, even in C. I know it's ugly)
constructive remarks are *very* welcome
void
on_mark_clicked (GtkButton *button,
gpointer user_data)
{
/* if freq-show = number */
GtkWidget *entry = lookup_widget(GTK_WIDGET(button), "freq_show");
gchar dialdata[LINEWIDTH] = "" ;
strcpy (dialdata,gtk_entry_get_text(GTK_ENTRY(entry)));
printf("%s",dialdata); /* DEBUG */
gchar stnname[LINEWIDTH] = "abc" ;
gdouble Mhznr = 0 ;
GtkWidget *dialog = gtk_dialog_new() ;
char *lbltxt=" Name That Station ! ";
GtkWidget *dg_label = gtk_label_new(lbltxt);
GtkWidget *dg_entry = gtk_entry_new() ;
char *bttntxt="OK";
GtkWidget *dg_OK = gtk_button_new_with_label(bttntxt) ;
Mhznr = getnrval ( dialdata ) ;
if (validfreq(Mhznr))
{ /* get station name from user with popup */
int text_width = LINEWIDTH; /* Width of field in characters
*/
gtk_entry_set_width_chars(GTK_ENTRY(dg_entry), text_width);
gtk_signal_connect_object(GTK_OBJECT (dg_OK), "clicked",
GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT(dialog));
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->action_area),
dg_OK);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
dg_label);
gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
dg_entry);
gtk_widget_show_all (dialog);
gtk_widget_grab_focus(dialog);
gtk_dialog_run (GTK_DIALOG (dialog));
strcpy(stnname,gtk_entry_get_text(GTK_ENTRY(dg_entry))) ;
/* makestruct (freq, name) */
/* sort-insert struct on freq */
/* put name on freq-show (FIXME) */
gtk_entry_set_text(GTK_ENTRY(entry),stnname);
gtk_widget_destroy (dialog);
}
else
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]