Salut a tous

J'ai créé 2 series de 8 radios

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 
/************************************************************/
/* Création du cadre "Com Port" et de son contenu           */
/*  - Une grille pour stocker les differents Widgets        */
/*  - Un Label pour indiquer le choix à faire               */
/*  - 8 Radios pour la selection du Port COM                */
/************************************************************/
// Création du cadre "COM Port"
    pComFrame=gtk_frame_new("COM Port");
    gtk_frame_set_shadow_type(GTK_FRAME(pComFrame),GTK_SHADOW_IN);
 
// creation de la grille COM
    pComGrid=gtk_table_new(5,2,FALSE);
// Ajout dans le Widget "Cadre COM"
    gtk_container_add(GTK_CONTAINER(pComFrame),GTK_WIDGET(pComGrid));
 
// Création du Label au format UTF8 du cadre "port COM"
    sUTF8ComLabel=g_locale_to_utf8("<span face=\"Arial\" size=\"large\" foreground=\"#0369CF\" background=\"#FC9630\">Sélectionnez le n° du port <b>COM</b></span>",-1,NULL,NULL,NULL);  // conversion (+allocation mémoire)
    pComLabel=gtk_label_new(sUTF8ComLabel);     // Création du label
    g_free(sUTF8ComLabel);                      // liberation mémoire allouée
    gtk_label_set_use_markup (GTK_LABEL(pComLabel),TRUE);   // On signale qu'on utilise les balises Pango
 
// Création des 8 Radios "COM x" (1<= x <= 8)
    pComRadio[0]=gtk_radio_button_new_with_label(NULL,"COM 1");
    for(i=1;i<8;i++)
    {
        sRadioLabel=g_strdup_printf("COM%ld",(i+1));
        pComRadio[i]=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(pComRadio[(i-1)]),sRadioLabel);
    }
    g_free(sRadioLabel);    // Label plus utile, libération mémoire
 
// Ajout des Widgets dans la grille
    gtk_table_attach(GTK_TABLE(pComGrid),pComLabel,0,2,0,1,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0);
    gtk_table_attach(GTK_TABLE(pComGrid),pComRadio[0],0,1,1,2,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pComGrid),pComRadio[4],1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pComGrid),pComRadio[1],0,1,2,3,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pComGrid),pComRadio[5],1,2,2,3,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pComGrid),pComRadio[2],0,1,3,4,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pComGrid),pComRadio[6],1,2,3,4,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pComGrid),pComRadio[3],0,1,4,5,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pComGrid),pComRadio[7],1,2,4,5,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
 
// Rendre bouton inactif
//    gtk_widget_set_sensitive(GTK_TOGGLE_BUTTON(pComRadio[6]),FALSE);
 
    for(i=0;i<8;i++)
    {
        g_signal_connect(G_OBJECT(pComRadio[i]),"clicked",G_CALLBACK(OnCOMRadio),pConfigCOM);
    }
 
/************************************************************/
/* Création du cadre "Baud Rate" et de son contenu          */
/*  - Une grille pour stocker les differents Widgets        */
/*  - Un Label pour indiquer le choix à faire               */
/*  - 8 Radios pour la selection du débit                   */
/************************************************************/
// Création du cade "Baud Rate"
    pBaudFrame=gtk_frame_new("Baud Rate");
    gtk_frame_set_shadow_type(GTK_FRAME(pBaudFrame),GTK_SHADOW_IN);
 
// creation de la grille Baud
    pBaudGrid=gtk_table_new(5,2,FALSE);
// Ajout dans le Widget "Cadre COM"
    gtk_container_add(GTK_CONTAINER(pBaudFrame),GTK_WIDGET(pBaudGrid));
 
// Création du Label au format UTF8 du cadre "Baud Rate"
    sUTF8BaudLabel=g_locale_to_utf8("<span face=\"Arial\" size=\"large\" foreground=\"#0369CF\" background=\"#FC9630\">Sélectionnez le débit (en bps)</span>",-1,NULL,NULL,NULL);  // conversion (+allocation mémoire)
    pBaudLabel=gtk_label_new(sUTF8BaudLabel);     // Création du label
    g_free(sUTF8BaudLabel);                      // liberation mémoire allouée
    gtk_label_set_use_markup (GTK_LABEL(pBaudLabel),TRUE);   // On signale qu'on utilise les balises Pango
 
// Création des 8 Radios débits
    pBaudRadio[0]=gtk_radio_button_new_with_label(NULL,"1200");
    pBaudRadio[1]=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(pBaudRadio[0]),"2400");
    pBaudRadio[2]=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(pBaudRadio[1]),"4800");
    pBaudRadio[3]=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(pBaudRadio[2]),"9600");
    pBaudRadio[4]=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(pBaudRadio[3]),"19200");
    pBaudRadio[5]=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(pBaudRadio[4]),"38400");
    pBaudRadio[6]=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(pBaudRadio[5]),"57600");
    pBaudRadio[7]=gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(pBaudRadio[6]),"115200");
 
// Ajout des Widgets dans la grille
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudLabel,0,2,0,1,GTK_EXPAND|GTK_FILL,GTK_EXPAND|GTK_FILL,0,0);
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudRadio[0],0,1,1,2,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudRadio[4],1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudRadio[1],0,1,2,3,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudRadio[5],1,2,2,3,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudRadio[2],0,1,3,4,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudRadio[6],1,2,3,4,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudRadio[3],0,1,4,5,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
    gtk_table_attach(GTK_TABLE(pBaudGrid),pBaudRadio[7],1,2,4,5,GTK_EXPAND|GTK_FILL,GTK_EXPAND,0,0);
 
// Connexion des signaux des radios
    for(i=0;i<8;i++)
    {
        g_signal_connect(G_OBJECT(pBaudRadio[i]),"clicked",G_CALLBACK(OnBaudRadio),pConfigCOM);
    }
Leurs Callback:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
 
/********************************************************************************/
/*  Cette fonction prend en 2eme parametre un pointeur sur la structure         */
/* SerialParam, afin de mettre a jour la donnée membre "ComPort"                */
/********************************************************************************/
void OnCOMRadio(GtkWidget *pWidget, gpointer pData)
{
//    const gchar *sLabel;
 
/////////////////////////////////////
///////////// Pour DEBUG /////////////
    DebugWidget();
/////////////////////////////////////
/////////////////////////////////////
 
    SerialParam *SerialConfig;
    SerialConfig=(SerialParam*)pData;       // transtypage du pointeur
 
    if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pWidget))==TRUE)
    {
        strcpy(SerialConfig->ComPort,gtk_button_get_label(GTK_BUTTON(pWidget)));
    }
}
 
/********************************************************************************/
/*  Cette fonction prend en 2eme parametre un pointeur sur la structure         */
/* SerialParam, afin de mettre a jour la donnée membre "BaudRate"               */
/********************************************************************************/
void OnBaudRadio(GtkWidget *pWidget, gpointer pData)
{
    const gchar *sLabel;
 
/////////////////////////////////////
///////////// Pour DEBUG /////////////
    DebugWidget();
/////////////////////////////////////
/////////////////////////////////////
 
    SerialParam *SerialConfig;
    SerialConfig=(SerialParam*)pData;       // transtypage du pointeur
 
    if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pWidget))==TRUE)
    {
        sLabel=gtk_button_get_label(GTK_BUTTON(pWidget));
        SerialConfig->BaudRate=atol(sLabel);    // conversion du label débit en "long"
    }
}
Et la structure SerialParam, ainsi que sa déclaration:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
typedef struct SerialParam SerialParam;
struct SerialParam
{
    char ComPort[5];        // Nom du PORT selectionné
    long BaudRate;          // Débit
};
 
    SerialParam ConfigCOM;              // déclaration d'une structure SerialParam
    SerialParam *pConfigCOM=&ConfigCOM; // pointeur sur la structure ConfigCom
Et enfin pour initialiser les données de la structure, je "simule" un click sur le radio "COM1", et un autre sur le radio "9600".

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
/************************************************************/
/*  Valeurs par defaut des boutons Radio                    */
/*      - Debit 9600 bauds                                  */
/*      - Port COM 1                                        */
/************************************************************/
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pComRadio[0]),TRUE);  // COM 1
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pBaudRadio[3]),TRUE); // 9600 bauds
Maintenant la question:

Comment se fait il que lorsque je lance le debug, seul le callback du radios "BaudRate" est executé? et pas celui du "COM"

De plus le callback est appelé 2 fois de suite, la premiere fois la condition du IF n'est pas remplie, du coup il ne fait rien , la seconde fois, la condition du IF est remplie comment cela se fait il?


D'avance merci

Edit: Je code avec Code::Blocks sous Windows XP