#include #include #include #include #include #include #include void on_activate_entry(GtkWidget *pEntry0, gpointer data); void on_copier_button2(GtkWidget *pButton_valeur, gpointer data); /// Fenêtre d'acquisition /// int main (int argc, char **argv) { GtkWidget *pWindow; GtkWidget *pVBox; GtkWidget *pHBox; GtkWidget *pHBox2; GtkWidget *pFrame1; GtkWidget *pFrame2; GtkWidget *pFrame3; GtkWidget *pFrame4; GtkWidget *pVBoxFrame1; GtkWidget *pVBoxFrame2; GtkWidget *pVBoxFrame3; GtkWidget *pVBoxFrame4; GtkWidget *pSeparator; GtkWidget *pEntry; GtkWidget *pEntry0; GtkWidget *pLabel; GtkWidget *pLabelx; GtkWidget *pLabel0; GtkWidget *pLabel2; GtkWidget *pLabel3; GtkWidget *pLabel4; GtkWidget *pLabel5; GtkWidget *pLabel6; GtkWidget *pLabel7; GtkWidget *pLabel8; GtkWidget *pLabel9; GtkWidget *pLabel10; GtkWidget *pLabel11; GtkWidget *pLabel12; GtkWidget *pLabel13; GtkWidget *pLabel14; GtkWidget *pLabel15; GtkWidget *pLabel16; GtkWidget *pLabel17; GtkWidget *pLabel18; GtkWidget *pLabel19; GtkWidget *pLabel20; GtkWidget *pLabel21; GtkWidget *pLabel22; GtkWidget *pLabel23; GtkWidget *pLabel24; GtkWidget *pLabel25; GtkWidget *pLabel26; GtkWidget *pLabel27; GtkWidget *pLabel28; GtkWidget *pLabel29; GtkWidget *pLabel30; GtkWidget *pLabel31; GtkWidget *pLabel32; GtkWidget *pLabel33; GtkWidget *pLabel34; GtkWidget *pLabel35; GtkWidget *pLabel36; GtkWidget *pLabel37; GtkWidget *pLabel38; GtkWidget *pLabel39; GtkWidget *pLabel40; GtkWidget *pLabel41; GtkWidget *pButton_valeur; gtk_init(&argc,&argv); pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(pWindow), "Les GtkBox"); gtk_window_set_default_size(GTK_WINDOW(pWindow), 620, 400); g_signal_connect(G_OBJECT(pWindow), "destroy", G_CALLBACK(gtk_main_quit),NULL); /* Creation de la GtkBox verticale */ pVBox = gtk_vbox_new(TRUE, 0); /* Ajout de la GtkVBox dans la fenetre */ gtk_container_add(GTK_CONTAINER(pWindow), pVBox); /// Les éléments 1er ligne pLabelx= gtk_label_new("Nb echantillons:"); pLabel0= gtk_label_new("Valeur"); pButton_valeur= gtk_button_new_with_label("Valider"); pEntry0 = gtk_entry_new(); /* Creation de la GtkBox horizontale: ligne 0 */ pHBox = gtk_hbox_new(TRUE, 0); gtk_box_pack_start(GTK_BOX(pVBox), pHBox, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(pHBox), pLabelx, TRUE, FALSE, 0); gtk_box_pack_start(GTK_BOX(pHBox), pEntry0, TRUE, FALSE, 0); /* NB éléments */ gtk_box_pack_start(GTK_BOX(pHBox), pButton_valeur, FALSE, TRUE, 80); gtk_box_pack_start(GTK_BOX(pHBox), pLabel0, TRUE, FALSE, 0); /// Les labels de contrôle pLabel2= gtk_label_new(NULL); pLabel3= gtk_label_new(NULL); pLabel4= gtk_label_new(NULL); pLabel5= gtk_label_new(NULL); pLabel6= gtk_label_new(NULL); pLabel7= gtk_label_new(NULL); pLabel8= gtk_label_new(NULL); pLabel9= gtk_label_new(NULL); pLabel10= gtk_label_new(NULL); pLabel11= gtk_label_new(NULL); pLabel12= gtk_label_new(NULL); pLabel13= gtk_label_new(NULL); pLabel14= gtk_label_new(NULL); pLabel15= gtk_label_new(NULL); pLabel16= gtk_label_new(NULL); pLabel17= gtk_label_new(NULL); pLabel18= gtk_label_new(NULL); pLabel19= gtk_label_new(NULL); pLabel20= gtk_label_new(NULL); pLabel21= gtk_label_new(NULL); pLabel22= gtk_label_new(NULL); pLabel23= gtk_label_new(NULL); pLabel24= gtk_label_new(NULL); pLabel25= gtk_label_new(NULL); pLabel26= gtk_label_new(NULL); pLabel27= gtk_label_new(NULL); pLabel28= gtk_label_new(NULL); pLabel29= gtk_label_new(NULL); pLabel30= gtk_label_new(NULL); pLabel31= gtk_label_new(NULL); pLabel32= gtk_label_new(NULL); pLabel33= gtk_label_new(NULL); pLabel34= gtk_label_new(NULL); pLabel35= gtk_label_new(NULL); pLabel36= gtk_label_new(NULL); pLabel37= gtk_label_new(NULL); pLabel38= gtk_label_new(NULL); pLabel39= gtk_label_new(NULL); pLabel40= gtk_label_new(NULL); pLabel41= gtk_label_new(NULL); /// Les Mesures /// /* Ligne 1*/ pHBox2 = gtk_hbox_new(TRUE, 0); gtk_box_pack_start(GTK_BOX(pVBox), pHBox2, TRUE, TRUE, 0); /// Mesures 1 /// /* Creation du premier GtkFrame */ pFrame1 = gtk_frame_new("Mesure 1"); gtk_box_pack_start(GTK_BOX(pHBox2), pFrame1, TRUE, FALSE, 0); /* Creation et insertion d une boite pour le premier GtkFrame */ pVBoxFrame1 = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(pFrame1), pVBoxFrame1); /* Creation et insertion des elements contenus dans le premier GtkFrame */ pLabel = gtk_label_new("X1 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame1), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame1), pEntry, TRUE, FALSE, 0); pEntry = gtk_entry_new(); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); /* Box de contrôle final */ gtk_box_pack_start(GTK_BOX(pVBoxFrame1), pLabel2, TRUE, FALSE, 0); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); pLabel = gtk_label_new("Y1 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame1), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame1), pEntry, TRUE, FALSE, 0); pEntry = gtk_entry_new(); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); /* Box de contrôle final */ gtk_box_pack_start(GTK_BOX(pVBoxFrame1), pLabel3, TRUE, FALSE, 0); /// Mesures 2 /// /* Creation du premier GtkFrame */ pFrame2 = gtk_frame_new("Mesure 2"); gtk_box_pack_start(GTK_BOX(pHBox2), pFrame2, TRUE, FALSE, 0); /* Creation et insertion d une boite pour le premier GtkFrame */ pVBoxFrame2 = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(pFrame2), pVBoxFrame2); pLabel = gtk_label_new("X2 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame2), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame2), pEntry, TRUE, FALSE, 0); pEntry = gtk_entry_new(); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); /* Box de contrôle final */ gtk_box_pack_start(GTK_BOX(pVBoxFrame2), pLabel4, TRUE, FALSE, 0); pLabel = gtk_label_new("Y2 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame2), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame2), pEntry, TRUE, FALSE, 0); pEntry = gtk_entry_new(); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); /* Box de contrôle final */ gtk_box_pack_start(GTK_BOX(pVBoxFrame2), pLabel5, TRUE, FALSE, 0); /// Mesures 3 /// /* Creation du premier GtkFrame */ pFrame3 = gtk_frame_new("Mesure 3"); gtk_box_pack_start(GTK_BOX(pHBox2), pFrame3, TRUE, FALSE, 0); /* Creation et insertion d une boite pour le premier GtkFrame */ pVBoxFrame3 = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(pFrame3), pVBoxFrame3); pLabel = gtk_label_new("X3 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame3), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame3), pEntry, TRUE, FALSE, 0); /* Box de contrôle final */ gtk_box_pack_start(GTK_BOX(pVBoxFrame3), pLabel6, TRUE, FALSE, 0); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); pLabel = gtk_label_new("Y3 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame3), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame3), pEntry, TRUE, FALSE, 0); pEntry = gtk_entry_new(); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); /* Box de contrôle final */ gtk_box_pack_start(GTK_BOX(pVBoxFrame3), pLabel7, TRUE, FALSE, 0); /// Mesures 4 /// /* Creation du premier GtkFrame */ pFrame4 = gtk_frame_new("Mesure 4"); gtk_box_pack_start(GTK_BOX(pHBox2), pFrame4, TRUE, FALSE, 0); /* Creation et insertion d une boite pour le premier GtkFrame */ pVBoxFrame4 = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(pFrame4), pVBoxFrame4); pLabel = gtk_label_new("X4 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame4), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame4), pEntry, TRUE, FALSE, 0); pEntry = gtk_entry_new(); /* Box de contrôle final */ gtk_box_pack_start(GTK_BOX(pVBoxFrame4), pLabel8, TRUE, FALSE, 0); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); pLabel = gtk_label_new("Y4 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame4), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame4), pEntry, TRUE, FALSE, 0); pEntry = gtk_entry_new(); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); /* Box de contrôle final */ gtk_box_pack_start(GTK_BOX(pVBoxFrame4), pLabel9, TRUE, FALSE, 0); /// Conexion des signaux: Bouton --> Appel de la fonction /* Connexion du signal "activate" du GtkEntry */ g_signal_connect(G_OBJECT(pEntry), "activate", G_CALLBACK(on_activate_entry), (GtkWidget*) pLabel2); /* Connexion du signal "clicked" du GtkButton */ /* Copie des X - Y */ g_signal_connect(G_OBJECT(pButton_valeur), "clicked", G_CALLBACK(on_copier_button2), (GtkWidget*) pVBoxFrame1); /* Connexion du signal "clicked" du GtkButton */ /* Copie des X - Y */ g_signal_connect(G_OBJECT(pButton_valeur), "clicked", G_CALLBACK(on_copier_button2), (GtkWidget*) pVBoxFrame2); /* Connexion du signal "clicked" du GtkButton */ /* Copie des X - Y */ g_signal_connect(G_OBJECT(pButton_valeur), "clicked", G_CALLBACK(on_copier_button2), (GtkWidget*) pVBoxFrame3); /* Connexion du signal "clicked" du GtkButton */ /* Copie des X - Y */ g_signal_connect(G_OBJECT(pButton_valeur), "clicked", G_CALLBACK(on_copier_button2), (GtkWidget*) pVBoxFrame4); gtk_widget_show_all(pWindow); gtk_main(); return EXIT_SUCCESS; } /* Fonction callback execute lors du signal "activate" */ void on_activate_entry(GtkWidget *pEntry00, gpointer data) { } /* Fonction callback executee lors du signal "clicked" */ /* Option qui recopie la variable sur le label en desous */ void on_copier_button2(GtkWidget *pButton_valeur, gpointer data) { GtkWidget *pTempEntry0; GtkWidget *pTempEntry02; GtkWidget *pTempLabel; GtkWidget *pTempLabel2; GtkWidget *pTempLabel0; GList *pList; const gchar *sText; const gchar *sText2; gchar *modified_text; gchar *modified_text2; gdouble number; gdouble number2; float X,Y; /* Recuperation de la liste des elements que contient la GtkVBox */ pList = gtk_container_get_children(GTK_CONTAINER((GtkWidget*)data)); /// X (On passe la partie X Traité dans le module: "on_copier_boutton") /* Le premier element est le GtkLabel */ pTempLabel0 = GTK_WIDGET(pList->data); /* On passe au pointeur suivant */ pList = g_list_next(pList); /* Cet element est le GtkEntry */ pTempEntry0 = GTK_WIDGET(pList->data); /* On passe au pointeur suivant */ pList = g_list_next(pList); /* Le premier element est le GtkLabel */ pTempLabel = GTK_WIDGET(pList->data); /// Y /* On passe au pointeur suivant */ pList = g_list_next(pList); /* On passe au pointeur suivant */ pList = g_list_next(pList); /* Cet element est le GtkEntry */ pTempEntry02 = GTK_WIDGET(pList->data); /* On passe au pointeur suivant */ pList = g_list_next(pList); /* Le premier element est le GtkLabel */ pTempLabel2 = GTK_WIDGET(pList->data); /* Recuperation du texte contenu dans le GtkEntry */ sText = gtk_entry_get_text(GTK_ENTRY(pTempEntry0)); /* Recuperation du texte contenu dans le GtkEntry */ sText2 = gtk_entry_get_text(GTK_ENTRY(pTempEntry02)); /* Conversion chaine -> valeur numérique */ number = g_strtod (sText, NULL); /* Conversion chaine -> valeur numérique */ number2 = g_strtod (sText2, NULL); /* Copie de number sur number2 */ X=number; Y=number2; /* Conversion valeur numérique -> chaine */ modified_text = g_strdup_printf ("%0.2f", number); /* Conversion valeur numérique -> chaine */ modified_text2 = g_strdup_printf ("%0.2f", number2); /* Modification du texte contenu dans le GtkLabel */ gtk_label_set_text(GTK_LABEL(pTempLabel), modified_text); /* Modification du texte contenu dans le GtkLabel */ gtk_label_set_text(GTK_LABEL(pTempLabel2), modified_text2); /* Liberation de la memoire utilisee par la liste */ g_list_free(pList); /* Libération de la chaine temporaire */ g_free (modified_text); g_free (modified_text2); g_print ("x :%lf\n", X); g_print ("y :%lf\n", Y); }