[GTK] Comment on recupere plusieurs data en une fois ?

Comment on recupere plusieurs data en une fois ? [GTK] - C++ - Programmation

Marsh Posté le 24-10-2004 à 15:28:31    

voic mon code et j'aimerais savoir comment je fais pour recupere la valeur de tous les GTK_Entry, GTK_RadioButton et des GTK_CheckButton lorsque je clique sur le Boutton CALCUL ?
 
Et aussi comment faire pour lorsque je ferme la 2eme fenetre la 1ere ne se ferme aussi ?
 

Code :
  1. #include <stdlib.h>
  2. #include <gtk/gtk.h>
  3. static GtkWidget *win = NULL;
  4. void Calcul(GtkWidget *winBtn,gpointer data);
  5. int main (int argc, char *argv[])
  6. {
  7. //  GtkWidget *win = NULL;
  8.  
  9.   /* Initialize GTK+ */
  10.   gtk_init (&argc, &argv);
  11.   /* Create the main window */
  12.   win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  13.   gtk_container_set_border_width (GTK_CONTAINER (win), 1);
  14.   gtk_window_set_default_size(GTK_WINDOW (win),320,200);
  15.   gtk_window_set_title (GTK_WINDOW (win), "INTERCLUB" );
  16.   gtk_window_set_position (GTK_WINDOW (win), GTK_WIN_POS_CENTER);
  17.   //gtk_widget_realize (win); // A QUOI CA SERT ???
  18.   g_signal_connect (win, "destroy", gtk_main_quit, NULL);
  19.  
  20.   GtkWidget *winVBox = gtk_vbox_new(TRUE, 0);
  21.   gtk_container_add(GTK_CONTAINER(win), winVBox);
  22.  
  23.   GtkWidget *winTable_1;
  24.   winTable_1 = gtk_table_new(14,15,FALSE);
  25.   gtk_box_pack_start(GTK_BOX(winVBox), winTable_1, TRUE, FALSE, 0);
  26.  
  27.  
  28.   /* equipe */
  29.   GtkWidget *winLabel_NageursDoublants;
  30.   winLabel_NageursDoublants = gtk_label_new("Nageurs\ndoublants" );
  31.   gtk_table_attach(GTK_TABLE(winTable_1), winLabel_NageursDoublants, 0, 1 , 0 , 1,GTK_EXPAND, GTK_EXPAND,0,0);
  32.  
  33.   GtkWidget *winCheck_NageursDoublants[10];
  34.   for(gint i=0 ; i < 10 ; ++i) {
  35.   winCheck_NageursDoublants[i] = gtk_check_button_new();
  36.   gtk_table_attach(GTK_TABLE(winTable_1), winCheck_NageursDoublants[i], 0, 1 , i+1 , i+2,GTK_EXPAND, GTK_EXPAND,0,0);
  37.   } 
  38.  
  39.  
  40.   GtkWidget *winLabel_Nageurs;
  41.   winLabel_Nageurs = gtk_label_new("Nageurs" );
  42.   gtk_table_attach(GTK_TABLE(winTable_1), winLabel_Nageurs, 1, 2 , 0 , 1,GTK_EXPAND, GTK_EXPAND,0,0);
  43.  
  44.   GtkWidget *winLabel_Nages[13];
  45.   winLabel_Nages[0]  = gtk_label_new("50 NL" );
  46.   winLabel_Nages[1]  = gtk_label_new("100 NL" );
  47.   winLabel_Nages[2]  = gtk_label_new("200 NL" );
  48.   winLabel_Nages[3]  = gtk_label_new("400 NL" );
  49.   winLabel_Nages[4]  = gtk_label_new("1500 NL" );
  50.   winLabel_Nages[5]  = gtk_label_new("100 DOS" );
  51.   winLabel_Nages[6]  = gtk_label_new("200 DOS" );
  52.   winLabel_Nages[7]  = gtk_label_new("100 BR" );
  53.   winLabel_Nages[8]  = gtk_label_new("200 BR" );
  54.   winLabel_Nages[9]  = gtk_label_new("100 PAP" );
  55.   winLabel_Nages[10] = gtk_label_new("200 PAP" );
  56.   winLabel_Nages[11] = gtk_label_new("200 4N" );
  57.   winLabel_Nages[12] = gtk_label_new("400 4N" );
  58.   for(gint i=0 ; i < 13 ; ++i) {
  59.       gtk_table_attach(GTK_TABLE(winTable_1), winLabel_Nages[i], i+2, i+3 , 0 , 1, GTK_EXPAND, GTK_EXPAND,1,2);
  60.   }   
  61.  
  62.   GtkWidget *winEntry_Equipe[11][14];
  63.   for(gint i=0 ; i < 10 ; ++i) {
  64.      winEntry_Equipe[i][0] = gtk_entry_new();
  65.      gtk_entry_set_width_chars (GTK_ENTRY(winEntry_Equipe[i][0]), 20);
  66.      gtk_table_attach(GTK_TABLE(winTable_1), winEntry_Equipe[i][0], 1 , 2, i+1, i+2 ,GTK_EXPAND, GTK_EXPAND,1,2 ); 
  67.   }   
  68.   for(gint i=0 ; i < 10 ; ++i) {
  69.    for(gint j=1 ; j < 14 ; ++j) {
  70.      winEntry_Equipe[i][j] = gtk_entry_new_with_max_length(7);
  71.      gtk_entry_set_width_chars (GTK_ENTRY(winEntry_Equipe[i][j]), 7);
  72.      gtk_table_attach(GTK_TABLE(winTable_1), winEntry_Equipe[i][j],j+1 , j+2, i+1, i+2 ,GTK_EXPAND, GTK_EXPAND,1,2);
  73.    } 
  74.   }
  75.  
  76.   GtkWidget *winLabel_Relais[3];
  77.   winLabel_Relais[0]  = gtk_label_new("RELAIS" );
  78.   winLabel_Relais[1]  = gtk_label_new("10x100 NL" );
  79.   winLabel_Relais[2]  = gtk_label_new("4x100 4N" );
  80.   gtk_table_attach_defaults(GTK_TABLE(winTable_1), winLabel_Relais[0],1 ,2 ,12 ,14 );
  81.   gtk_table_attach_defaults(GTK_TABLE(winTable_1), winLabel_Relais[1],2 ,3 ,12 ,13 ); 
  82.   gtk_table_attach_defaults(GTK_TABLE(winTable_1), winLabel_Relais[2],2 ,3 ,13 ,14 );     
  83.   GtkWidget *winEntry_Relais[2];
  84.   winEntry_Relais[0] = gtk_entry_new_with_max_length(7);
  85.   winEntry_Relais[1] = gtk_entry_new_with_max_length(7);
  86.   gtk_entry_set_width_chars (GTK_ENTRY(winEntry_Relais[0]), 7);
  87.   gtk_entry_set_width_chars (GTK_ENTRY(winEntry_Relais[1]), 7);
  88.   gtk_table_attach(GTK_TABLE(winTable_1), winEntry_Relais[0],3 , 4, 12, 13 ,GTK_EXPAND, GTK_EXPAND,1,1);
  89.   gtk_table_attach(GTK_TABLE(winTable_1), winEntry_Relais[1],3 , 4, 13, 14 ,GTK_EXPAND, GTK_EXPAND,1,1);
  90.  
  91.   GtkWidget *winLabel_Sexe;
  92.   winLabel_Sexe = gtk_label_new("Sexe de l'equipe" );
  93.   gtk_table_attach_defaults(GTK_TABLE(winTable_1), winLabel_Sexe,5 ,7 ,12 ,14 );
  94.  
  95.   GtkWidget *winRadio_Sexe1;
  96.   GtkWidget *winRadio_Sexe2;
  97.  
  98.   winRadio_Sexe1 = gtk_radio_button_new_with_label(NULL, "Homme" );
  99.   gtk_table_attach_defaults(GTK_TABLE(winTable_1), winRadio_Sexe1 ,7 ,8 ,12 ,13 );
  100.  
  101.   winRadio_Sexe2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (winRadio_Sexe1), "Femme" );
  102.   gtk_table_attach_defaults(GTK_TABLE(winTable_1), winRadio_Sexe2 ,7 ,8 ,13 ,14 );
  103.  
  104.   GtkWidget *winButtonCalcul;
  105.   winButtonCalcul = gtk_button_new_with_label("CALCUL" );
  106.   gtk_table_attach_defaults(GTK_TABLE(winTable_1), winButtonCalcul ,13 ,15 ,12 ,14 );
  107.   g_signal_connect(G_OBJECT(winButtonCalcul), "clicked", G_CALLBACK(Calcul), (GtkWidget*) winVBox);
  108.  
  109.   /* Enter the main loop */
  110.   gtk_widget_show_all (win);
  111.   gtk_main ();
  112.   return 0;
  113. }
  114. void Calcul(GtkWidget *winBtn,gpointer data)
  115. {
  116.   GtkWidget *winRes = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  117.   gtk_window_set_position (GTK_WINDOW (winRes), GTK_WIN_POS_CENTER);
  118.   gtk_window_set_default_size(GTK_WINDOW (winRes),320,200);
  119.   gtk_window_set_title (GTK_WINDOW (winRes), "RESULTATS" );
  120.   g_signal_connect (winRes, "destroy", gtk_main_quit, NULL);
  121.  
  122.   GtkWidget *winTable_2 = gtk_table_new(14,15,FALSE);
  123.   gtk_container_add(GTK_CONTAINER(winRes), winTable_2);
  124.  
  125.   gtk_widget_show_all(winRes);
  126. }


Message édité par tching pao le 24-10-2004 à 15:36:33
Reply

Marsh Posté le 24-10-2004 à 15:28:31   

Reply

Marsh Posté le 24-10-2004 à 20:48:53    

up

Reply

Marsh Posté le 25-10-2004 à 09:08:45    

Quel est le problème ?
 
texte = gtk_entry_get_text (ton_entry);
etat = gtk_toggle_button_get_active (tes_boutons);
 
Tout ça dans Calcul(). Il faut t'organiser différemment pour que tes variables y soient accessibles.

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed