Re: get datas from entries...



On Thu, 25 Jul 2002, sefo wrote:

hi,

1/
i'd like to know how i could get the data from an entry widget and put it into a text widget
i managed to get the value of the entry when i validate (enter key) and i managed to print it in the console
(g_print) but i can't display it in the text widget (gtk_insert_text())

look @ the code here (http://sefo.netfirms.com/prog1.txt)

  just one thing : the prototype of a callback of an entry, associated to 
the "activate" signal, is

  void CallBack(GtkEntry *entry, gpointer data)

  then you could try this connection :

  gtk_signal_connect(GTK_OBJECT(entry), "activate", 
GTK_SIGNAL_FUNC(entry_callback), &MainText);

  and the callback :

void entry_callback(GtlWidget *Entry, GtkWidget **widget) {
  GtkWidget *Text;

  Text = widget[0];
  char *str=gtk_entry_get_text(GTK_ENTRY(Entry));
  gtk_insert_text(GTK_TEXT(Text), str);         
  g_print("%s\n", str);
}

Perhaps it is not the simpliest way to do that, but it should work


2/
i got 4 entries and a button, i'd like the button to get the value of the 4 entries
and put each of these values in a variable.

look @ the code here (http://sefo.netfirms.com/prog2.txt)


 In the function where yours entries and your button are defined : 

  GtkWidget **Entries; /* In fact, the replacement of your 4 entries */
  GtkWidget *Button;

  Entries = g_malloc(4*sizeof(GtkWidget *));
  /*
  ... You set your entries with Entries[0] = etc..
                                Entries[1] = ...
                                Entries[2] = ...
                                Entries[3] = ...
  and Button = ... 
  */

  /* And you connect the following signal to your button */
  gtk_signal_connect(GTK_OBJECT(Button), "clicked", 
(GtkSignalFunc)calculate), Entries);
  ...

The callback should be :
  void calculate(GtkWidget *w, GtkWidget **Entries)
    {
      gchar *text;
   
      /* to get the text of the first entry : */
      text = gtk_entry_get_text(GTK_ENTRY(Entries[0]));
      /* and so on ... */
    }
  
Hope this will help 

Vincent TORRI

thx
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


-- 
TORRI Vincent
Mathematiques Appliquees Bordeaux                                                
Institut de Mathematiques                                                       
Universite Bordeaux 1                                                           
351 cours de la liberation                                                      
33 405 Talence cedex - France                                                   
                                                                                
Tel : 33 (0)5 57 96 21 42                                                       
Fax : 33 (0)5 56 84 26 26                                                       
--




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