#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 *pVBoxFrame; GtkWidget *pVBoxFrame2; GtkWidget *pSeparator; GtkWidget *pEntry; GtkWidget *pEntry0; GtkWidget *pLabel; GtkWidget *pLabel0; GtkWidget *pLabel2; GtkWidget *pLabel3; GtkWidget *pLabel4; GtkWidget *pLabel5; GtkWidget *pLabel6; GtkWidget *pLabel7; GtkWidget *pButton_valeur; float number2; const gchar *sText; 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 pLabel0= gtk_label_new("Valeur"); pButton_valeur= gtk_button_new_with_label("Valider"); pEntry0 = gtk_entry_new(); /* Recuperation du texte contenu dans le GtkEntry */ sText = gtk_entry_get_text(GTK_ENTRY(pEntry0)); /* Conversion chaine -> valeur numérique */ number2 = g_strtod (sText, NULL); printf ("number :%f", number2); /* 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), 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); 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); /// 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 */ pVBoxFrame = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(pFrame1), pVBoxFrame); /* Creation et insertion des elements contenus dans le premier GtkFrame */ pLabel = gtk_label_new("X1 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame), 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(pVBoxFrame), pLabel2, TRUE, FALSE, 0); /* Creation d un GtkHSeparator */ pSeparator = gtk_hseparator_new(); pLabel = gtk_label_new("Y1 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame), 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(pVBoxFrame), 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 */ pVBoxFrame = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(pFrame2), pVBoxFrame); pLabel = gtk_label_new("X2 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame), 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(pVBoxFrame), pLabel4, TRUE, FALSE, 0); pLabel = gtk_label_new("Y2 :"); gtk_box_pack_start(GTK_BOX(pVBoxFrame), pLabel, TRUE, FALSE, 0); pEntry = gtk_entry_new(); gtk_box_pack_start(GTK_BOX(pVBoxFrame), 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(pVBoxFrame), 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 */ pVBoxFrame2 = gtk_vbox_new(TRUE, 0); gtk_container_add(GTK_CONTAINER(pFrame3), pVBoxFrame2); pLabel = gtk_label_new("X3 :"); 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), pLabel6, TRUE, FALSE, 0); pLabel = gtk_label_new("Y3 :"); 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), pLabel7, TRUE, FALSE, 0); /* 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*) pVBoxFrame2); 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 *pTempLabel; GList *pList; const gchar *sText; gchar *modified_text; gdouble number; float number2; /* Recuperation de la liste des elements que contient la GtkVBox */ pList = gtk_container_get_children(GTK_CONTAINER((GtkWidget*)data)); /* Passage a l element suivant : le Label */ pList = g_list_next(pList); /* Le premier element est le GtkEntry */ pTempEntry0 = GTK_WIDGET(pList->data); /* Cet element est le GtkLabel */ pTempLabel = GTK_WIDGET(pList->data); /* Recuperation du texte contenu dans le GtkEntry */ sText = gtk_entry_get_text(GTK_ENTRY(pTempEntry0)); /* Conversion chaine -> valeur numérique */ number = g_strtod (sText, NULL); /* Modification du nombre */ number = number*2; /* Conversion valeur numérique -> chaine */ modified_text = g_strdup_printf ("%0.2f", number); /* Modification du texte contenu dans le GtkLabel */ gtk_label_set_text(GTK_LABEL(pTempLabel), modified_text); /* Liberation de la memoire utilisee par la liste */ g_list_free(pList); /* Libération de la chaine temporaire */ g_free (modified_text); printf ("number :%lf", number2); }