IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

GTK+ avec C & C++ Discussion :

GTK en vala avec Gtkbuilder


Sujet :

GTK+ avec C & C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    14
    Détails du profil
    Informations personnelles :
    Âge : 63
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 14
    Par défaut GTK en vala avec Gtkbuilder
    Bonsoir,

    Je m'amuse sur un programme mono-fenêtre initialement codé avec gambas en environ 160 lignes et que je transpose en GTK/vala avec interface créée sous glade 3.6 et gérée par gtkbuilder.

    J'ai 4 boutons et pour chacun après un clic il doit y avoir lecture "dans la fenêtre principale et unique" de plusieurs valeurs de spinbuttons et modification de plusieurs labels.

    Peut-on rendre visible chacun des composants à modifier à l'intérieur de chaque fonction callback associée à chaque bouton sans passer par des variables globales définissant les widgets sur lesquels on souhaite intervenir ? Est-il gênant en théorie d'utiliser des variables globales sur ces widgets ? Comment s'utilise également la méthode get_objects () plutôt que get_object () traditionnelle sur le widget parent et qu'on voit dans tous les tutos. Remplace t-elle les x appels à get_object () pour les x widgets sur lesquels intervenir ?

    Merci d'avance.

    CJ

  2. #2
    Expert confirmé
    Avatar de gerald3d
    Homme Profil pro
    Conducteur de train
    Inscrit en
    Février 2008
    Messages
    2 308
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 55
    Localisation : France, Côte d'Or (Bourgogne)

    Informations professionnelles :
    Activité : Conducteur de train
    Secteur : Transports

    Informations forums :
    Inscription : Février 2008
    Messages : 2 308
    Billets dans le blog
    5
    Par défaut
    Utiliser des variables globales n'est pas interdit et ne posera aucun problème pour tes différents widgets. On a tendance à dire "beurk" lorsqu'il y a des déclarations en global parce que lorsque les sources sont composées de différents fichiers d'entête avec des milliers de ligne de code il devient trés difficile d'y retrouver ses petits.

    Pour ce qui est de rendre visible des widgets dans des Callback sans passer par des variables globales, et bien ca ne pose aucun problème. Le pointeur générique "gpointer user_data" associé à tous les prototypes des Callback est là pour ca.

  3. #3
    Modérateur

    Homme Profil pro
    Développeur informatique
    Inscrit en
    Juin 2009
    Messages
    1 395
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2009
    Messages : 1 395
    Par défaut
    Citation Envoyé par gerald3d Voir le message
    On a tendance à dire "beurk" lorsqu'il y a des déclarations en global parce que lorsque les sources sont composées de différents fichiers d'entête avec des milliers de ligne de code il devient trés difficile d'y retrouver ses petits.
    Ce n'est pas la raison principale. La principale raison c'est qu'il devient difficile de savoir qui modifie la variable en question, et quand. De plus, impossible de réutiliser le même widget. Deux instances différentes partageront la même variable globale, ce qui peut poser problème quand le comportement donné est spécifique à une instance.

    Prenons l'exemple d'un widget qui affiche un fond coloré. On affiche deux instance de ce widget. Si la couleur à afficher est contrôlée par une variable globale, il est impossible de faire afficher une couleur différente pour chaque widget.

    Cela limite aussi grandement la réutilisation de code.

    Donc effectivement, les variables globales, c'est beurk.

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    14
    Détails du profil
    Informations personnelles :
    Âge : 63
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 14
    Par défaut
    Merci pour vos réponses.

    Ce qui me gêne, c'est 1) bien sûr que je ne maîtrise pas du tout assez Vala et 2) que pour 1 click sur un bouton j'ai x widgets sur lesquels intervenir. Peut-on passer en paramètre la liste de ces x widgets ?

    En C, pour agir sur un gtkentry suite au click d'un bouton je ferais
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    g_signal_connect (
                gtk_builder_get_object (p_builder, "button1"),
                "clicked", G_CALLBACK (cb_ok),
                (gpointer) gtk_entry_get_text (
                   GTK_ENTRY (gtk_builder_get_object (p_builder, "entry1"))
    pour récupérer le pointeur sur le widget entry1 dans ma fonction callback cb_ok

    En python c'est simple avec quelque chose comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    class WidgetsWrapper:
            def __init__(self):
                    self.widgets = gtk.glade.XML("/home/chris/Documents/Prog_python/essai.glade")
                    self.widgets.signal_autoconnect(GladeHandlers.__dict__)
     
            def __getitem__(self, key):
                    """Ceci nous donne la possibilité de faire : widgets['widget_name'].action()"""
                    return self.widgets.get_widget(key)
    ce qui fait que par exemple widgets['entry1'].set.value(30,00) peut se faire directement depuis la fonction cb_ok et qu'il en va de même pour n'importe quel widget déclaré dans le fichier glade.

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    14
    Détails du profil
    Informations personnelles :
    Âge : 63
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 14
    Par défaut
    Si je mets le tout le code principal à l'intérieur d'une classe, est-ce que c'est ok ?

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    14
    Détails du profil
    Informations personnelles :
    Âge : 63
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 14
    Par défaut
    Je viens de faire le portage en Free Pascal / Lazarus alors que ce matin je n'avais jamais écrit une ligne de code en Pascal (192 lignes contre 160 en Gambas). Dans les deux cas, il ne s'agit pas à proprement parler de programmation par objets. Dans les deux cas également c'est Gtk mais derrière une surcouche.

    En Pascal
    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
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
     
    unit Unit1; 
     
    {$mode objfpc}{$H+}
     
    interface
     
    uses
      Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
      StdCtrls, ExtCtrls, Spin, math;
     
    type
     
      { TForm1 }
     
      TForm1 = class(TForm)
        Button1: TButton;
        Button2: TButton;
        Button3: TButton;
        Button4: TButton;
        FloatSpinEdit1: TFloatSpinEdit;
        FloatSpinEdit2: TFloatSpinEdit;
        FloatSpinEdit3: TFloatSpinEdit;
        FloatSpinEdit4: TFloatSpinEdit;
        FloatSpinEdit5: TFloatSpinEdit;
        FloatSpinEdit6: TFloatSpinEdit;
        FloatSpinEdit7: TFloatSpinEdit;
        Label1: TLabel;
        Label10: TLabel;
        Label11: TLabel;
        Label12: TLabel;
        Label13: TLabel;
        Label14: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        Label4: TLabel;
        Label5: TLabel;
        Label6: TLabel;
        Label7: TLabel;
        Label8: TLabel;
        Label9: TLabel;
        RadioButton1: TRadioButton;
        RadioButton2: TRadioButton;
        RadioButton3: TRadioButton;
        RadioButton4: TRadioButton;
        RadioButton5: TRadioButton;
        RadioButton6: TRadioButton;
        RadioButton7: TRadioButton;
        RadioButton8: TRadioButton;
        RadioGroup1: TRadioGroup;
        RadioGroup2: TRadioGroup;
        RadioGroup3: TRadioGroup;
        SpinEdit1: TSpinEdit;
        SpinEdit2: TSpinEdit;
        SpinEdit3: TSpinEdit;
        procedure Button1Click(Sender: TObject);
        procedure Button2Click(Sender: TObject);
        procedure Button3Click(Sender: TObject);
        procedure Button4Click(Sender: TObject);
        procedure RadioButton1Change(Sender: TObject);
        procedure RadioButton2Change(Sender: TObject);
      private
        { private declarations }
      public
        { public declarations }
      end; 
     
    var
      Form1: TForm1; 
     
    implementation
     
    { TForm1 }
     
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      close;
    end;
     
    procedure TForm1.Button2Click(Sender: TObject);
    begin
      ShowMessage ( 'Calcul de puissance à vélo - C. journoud avec Lazarus/Free Pascal - Août 2010' );
    end;
     
    procedure TForm1.Button3Click(Sender: TObject);
    begin
      FloatSpinEdit1.value := 0.0;
      FloatSpinEdit2.value := 0.0;
      FloatSpinEdit3.value := 0.0;
      FloatSpinEdit4.value := 0.0;
      FloatSpinEdit5.value := 0.0;
      FloatSpinEdit7.value := 0.0;
      SpinEdit1.Value := 0;
      SpinEdit2.Value := 0;
      SpinEdit3.Value := 0;
      Label8.caption := ' NC ';
      Label9.caption := ' NC ';
      Label10.caption := ' NC ';
      Label11.caption := ' NC ';
      Label14.caption := ' NC ';
     
    end;
     
    procedure TForm1.Button4Click(Sender: TObject);
    var masse1, masse2, massetot, deniv : double;
    var altmoy, temps, distance, pente : double;
    var vitesse, coef_pente, cp1, cp2, cp3, air : double;
    var densite, frot, puissance, rendement : double;
    var heure, min, sec : integer;
    var str_temp : string;
     
    begin
      masse1 := FloatSpinEdit1.value;
      if masse1 > 90 then ShowMessage ('Attention : supprimer la bière !');
      if masse1 = 0 then ShowMessage ('La masse corporelle ne peut être nulle');
      masse2 := FloatSpinEdit2.Value;
      if masse2 > 12 then ShowMessage ('Change ton vélo Papy !');
      if masse2 = 0 then ShowMessage ('La masse du vélo ne peut être nulle');
      massetot := masse1 + masse2;
     
      distance := FloatSpinEdit5.Value;
      if distance = 0 then ShowMessage ('La distance ne peut être nulle');
      altmoy := FloatSpinEdit7.Value;
      if altmoy = 0 then ShowMessage ('L''altitude moyenne ne peut être nulle');
     
      if RadioButton1.Checked = True then
      begin
        deniv := FloatSpinEdit3.Value;
        if deniv > (distance * 1000) then ShowMessage ('Le dénivelé ne doit pas être spérieur à la distance');
        if deniv <> 0 then pente := deniv * 100 / (deniv / Tan(ArcSin(deniv / (distance * 1000))))
        else pente := 0.0;
        Str(pente:1:2, str_temp);
        Label14.caption := str_temp;
        FloatSpinEdit4.Value := pente;
        FloatSpinEdit4.Visible := True;
      end
      else begin
        pente := FloatSpinEdit4.Value;
        deniv := Sin(ArcTan(pente / 100)) * distance * 1000;
        FloatSpinEdit3.Value := deniv;
        FloatSpinEdit3.Visible := True;
      end;
     
      heure := SpinEdit1.Value;
      min := SpinEdit2.Value;
      sec := SpinEdit3.Value;
      temps := heure + min / 60 + sec / 3600;
      if temps = 0 then ShowMessage ('Il faut saisir une durée')
      else begin
        vitesse := distance / temps;
        coef_pente := pente / 100;
        Str(vitesse:1:2, str_temp);
        Label9.caption := str_temp;
        cp1 := 9.81 * massetot * coef_pente * (vitesse / 3.6);
        Str(cp1:1:2, str_temp);
        Label10.caption := str_temp;
        if RadioButton3.Checked = True then air := 0.35;
        if RadioButton4.Checked = True then air := 0.30;
        if RadioButton5.Checked = True then air := 0.22;
        densite := altmoy / 8 / 100;
        cp2 := (densite / 2) * air * Power((vitesse / 3.6), 3);
        Str(cp2:1:2, str_temp);
        Label8.caption := str_temp;
        if RadioButton6.Checked = True then frot := 0.004;
        if RadioButton7.Checked = True then frot := 0.006;
        if RadioButton8.Checked = True then frot := 0.009;
        cp3 := 9.81 * massetot * frot * vitesse / 3.6;
        Str(cp3:1:2, str_temp);
        Label11.caption := str_temp;
        rendement := FloatSpinEdit6.Value;
        if rendement = 0 then ShowMessage ('Il faut une valeur non nulle pour rendement');
        puissance := (cp1 + cp2 + cp3) * 100 / rendement;
        Str(puissance:1:2, str_temp);
        Label14.caption := str_temp;
      end
    end;
     
    procedure TForm1.RadioButton1Change(Sender: TObject);
    begin
      FloatSpinEdit4.Visible := False;
      FloatSpinEdit3.Visible := True;
    end;
     
    procedure TForm1.RadioButton2Change(Sender: TObject);
    begin
      FloatSpinEdit3.Visible := False;
      FloatSpinEdit4.Visible := True;
    end;
     
    initialization
      {$I unit1.lrs}
     
    end.
    En Gambas
    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
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
     
    ' Gambas class file
     
    PUBLIC SUB _new()
     
    pente_Click 'MAP de l'affichage selon choix de base
    p2_Click 'config d'origine pour les données aérodynamiques
    p3_Click 'config d'origine pour les frottements
    ValueBox4.Value = "00:00:00"
    ValueBox8.Value = 97.5
     
    END
     
    PUBLIC SUB quitter_Click()
     
      ME.Close 
     
    END
     
    PUBLIC SUB effacer_Click()
      pente_Click
      p2_Click
      p3_Click
      ValueBox1.Value = 0
      ValueBox2.Value = 0  
      ValueBox3.Value = 0
      ValueBox4.Value = "00:00:00"
      ValueBox5.Value = 0
      ValueBox6.Value = 0  
      ValueBox7.Value = 0  
      ValueBox8.Value = 97.5  
      Label8.Text = "NC"
      Label9.Text = "NC"
      Label14.Text = "NC"
    END
     
    PUBLIC SUB calculer_Click()
     
      DIM masse1, masse2, massetot AS Float
      DIM distance AS Float
      DIM deniv, altmoy AS Float
      DIM pente AS Float
      DIM temps AS Float
      DIM vitesse, coef_pente, cp1, cp2, cp3 AS Float
      DIM air, densite, frot, puissance, rendement AS Float
     
      'Calcul de la masse totale et vérification des valeurs saisies
      masse1 = ValueBox1.Value
      IF masse1 > 95 THEN 
        Message("Attention à la surcharge !")
      ELSE IF masse1 = 0 THEN 
        Message("La masse ne peut être nulle ...")
      ENDIF 
      masse2 = ValueBox6.Value
      IF masse2 > 12 THEN 
        Message("Change ton vélo Papy !")
      ELSE IF masse2 = 0 THEN 
        Message("La masse ne peut être nulle ...")
      ENDIF 
      massetot = masse1 + masse2
      distance = ValueBox3.Value
      altmoy = ValueBox7.Value
      IF altmoy = 0 THEN 
        Message("L'altitude moyenne ne peut être nulle ...")
      ENDIF 
      IF denivele.Value = TRUE THEN 
        deniv = ValueBox5.Value
        'PRINT deniv
        IF deniv <> 0 THEN 
          IF deniv > (distance * 1000) THEN 
            Message("Le dénivelé ne doit pas être supérieur à la distance")
            deniv = distance * 1000
            ValueBox2.Value = deniv
          ENDIF 
          pente = deniv * 100 / (deniv / Tan(ASin(deniv / (distance * 1000))))
          'PRINT pente
        ELSE 
          pente = 0.0
        ENDIF 
        'PRINT pente
        ValueBox2.Value = pente
        ValueBox2.Visible = TRUE
      ELSE 
        pente = ValueBox2.Value
        deniv = Sin(ATan(pente / 100)) * distance * 1000
        ValueBox5.Value = deniv
        ValueBox5.Visible = TRUE
     
      ENDIF 
      temps = ValueBox4.Value
      temps *= 24
      IF temps = 0 THEN 
        Message("Il faut saisir une durée ")
      ELSE
        vitesse = distance / temps
        coef_pente = pente / 100
        Label8.Text = Str(vitesse) & " km/h"
        cp1 = 9.81 * massetot * coef_pente * (vitesse / 3.6)
        Label9.Text = Str(cp1)
        ' air = valeurs de Scx en fonction de la position
        IF haut.Value = TRUE THEN
          air = 0.35
        ELSE IF bas.Value = TRUE THEN
          air = 0.30
        ELSE 
          air = 0.22
        ENDIF 
        densite = altmoy / 8 / 100
        cp2 = (densite / 2) * air * (vitesse / 3.6) ^ 3
        Label10.Text = Str(cp2)
        IF route700.Value = TRUE THEN
          frot = 0.004
        ELSE IF route26.Value = TRUE THEN
          frot = 0.006
        ELSE
          frot = 0.009
        ENDIF 
        cp3 = 9.81 * massetot * frot * vitesse / 3.6
        frottements.Text = Str(cp3)
        rendement = ValueBox8.Value
        IF rendement = 0 THEN
          Message("Il faut saisir une valeur non nulle pour le rendement ")
        ENDIF 
        puissance = (cp1 + cp2 + cp3) * 100 / rendement
        Label14.Text = Str(puissance)
      ENDIF
    END
     
    PUBLIC SUB pente_Click()
     
      IF denivele.Value = TRUE THEN 
        ValueBox5.Visible = TRUE
        ValueBox2.Visible = FALSE
      ELSE IF pente.Value = TRUE THEN 
        ValueBox5.Visible = FALSE
        ValueBox2.Visible = TRUE
      ENDIF 
    END
     
    PUBLIC SUB p2_Click()
      IF haut.Value = TRUE THEN 
        Label10.Text = "Mains en haut"
      ENDIF 
      IF bas.Value = TRUE THEN 
        Label10.Text = "Mains en bas"
      ENDIF 
      IF clm.Value = TRUE THEN  
        Label10.Text = "Guidon CLM"
      ENDIF 
     
    END
     
    PUBLIC SUB p3_Click()
      IF route700.Value = TRUE THEN 
        frottements.Text = "Vélo de route"
      ENDIF 
      IF route26.Value = TRUE THEN 
        frottements.Text = "VTT avec pneus de route"
      ENDIF 
      IF xc26.Value = TRUE THEN  
        frottements.Text = "VTT avec pneus tout terrain"
      ENDIF 
     
    END
     
    PUBLIC SUB apropos_Click()
     
      Message("Programmé avec Gambas 2 par C. Journoud, selon méthode Vayer / Portoleau - Août 2010")
     
    END
    La doc sur le net ce n'est pas rien. Avec Vala, la doc est pour le moment faite pour ceux qui ont un certain niveau en C# et/ou un gros niveau en C pour pouvoir aller fouiller le code généré. Pour tout ce qui concerne GTK+, je trouve le C plus simple, et encore une fois beaucoup plus documenté. Je me demande si ce n'est pas aussi la programmation par objet qui me déroute.

  7. #7
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    14
    Détails du profil
    Informations personnelles :
    Âge : 63
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 14
    Par défaut Suite ...
    Voici le "magnifique" code en Vala à l'arrache (mais qui compile et produit ce qui est attendu ):

    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
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
     
    /* 
     * compilation: 
     * valac --pkg gtk+-2.0 --pkg gmodule-2.0 puissance.vala 
     */ 
     
    using Gtk;
    using Math;
     
    Window window;
    SpinButton spinbutton1;
    SpinButton spinbutton2;
    SpinButton spinbutton3;
    SpinButton spinbutton4;
    SpinButton spinbutton5;
    SpinButton spinbutton6;
    SpinButton spinbutton7;
    SpinButton spinbutton8;
    SpinButton spinbutton9;
    SpinButton spinbutton10;
    Label label7;
    Label label9;
    Label label11;
    Label label13;
    Label label16;
    RadioButton radiobutton1;
    RadioButton radiobutton2;
    RadioButton radiobutton3;
    RadioButton radiobutton4;
    RadioButton radiobutton5;
    RadioButton radiobutton6;
    RadioButton radiobutton7;
    RadioButton radiobutton8;
     
    public void on_button1_clicked () {
        double pente;
        double deniv;
        double vitesse;
        double coef_pente;
        double cp1, cp2, cp3;
        double air = 0.35;
        double densite;
        double frot = 0.004;
        double rendement;
        double puissance;
        double masse1 = spinbutton1.get_value();
     
        if (masse1 == 0) {
          var mes = new Gtk.MessageDialog (window, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "La masse corporelle ne peut être nulle");
          mes.run();
          mes.destroy();
        }
     
        double masse2 = spinbutton2.get_value();
        if (masse2 == 0) {
          var mes = new Gtk.MessageDialog (window, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "La masse du vélo ne peut être nulle");
          mes.run();
          mes.destroy();
        }
     
        double massetot = masse1 + masse2;
        double distance = spinbutton6.get_value();
        double altmoy = spinbutton5.get_value();
     
        if (altmoy == 0) {
          var mes = new Gtk.MessageDialog (window, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "L'altitude moyenne ne peut être nulle");
          mes.run();
          mes.destroy();
        }
     
        if (radiobutton1.get_active() == true) {
          deniv = spinbutton3.get_value();
          if (deniv != 0) {
            if (deniv > distance * 1000) {
              var mes = new Gtk.MessageDialog (window, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Le dénivelé ne doit pas être supérieur à la distance");
              mes.run();
              mes.destroy();  
            }
            pente = deniv * 100 / (deniv / tan(asin(deniv / (distance * 1000))));
          }
          else { pente = 0.0;
          }
        spinbutton4.value = pente;
        spinbutton4.set_visible(true);
        }
        else {
          pente = spinbutton4.get_value();
          deniv = sin(atan(pente / 100)) * distance * 1000;
          spinbutton3.value = deniv;
          spinbutton3.set_visible(true);
        }
        double heure = spinbutton7.value;
        double min = spinbutton8.value;
        double sec = spinbutton9.value;
        double temps = heure + min / 60 + sec / 3600;
        if (temps == 0) {
          var mes = new Gtk.MessageDialog (window, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Il faut saisir une durée");
          mes.run();
          mes.destroy();
        }
        else {
          vitesse = distance / temps;
          coef_pente = pente / 100;
          cp1 = 9.81 * massetot * coef_pente * (vitesse / 3.6);
          if (radiobutton3.get_active() == true) { air = 0.35; }
          if (radiobutton4.get_active() == true) { air = 0.30; }
          if (radiobutton5.get_active() == true) { air = 0.22; }
          densite = altmoy / 8 / 100;
          cp2 = (densite / 2) * air * pow((vitesse / 3.6), 3);
          if (radiobutton6.get_active() == true) { frot = 0.004; }
          if (radiobutton7.get_active() == true) { frot = 0.006; }
          if (radiobutton8.get_active() == true) { frot = 0.009; }
          cp3 = 9.81 * massetot * frot * vitesse / 3.6;
          rendement = spinbutton10.value;
          if (rendement == 0) {
          var mes = new Gtk.MessageDialog (window, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Il faut une valeur non nule pour rendement");
          mes.run();
          mes.destroy();
        }
        puissance = (cp1 + cp2 + cp3) * 100 / rendement;
        label7.set_text("%3.2f".printf(vitesse));
        label9.set_text("%3.2f".printf(cp1));
        label11.set_text("%3.2f".printf(cp2));
        label13.set_text("%3.2f".printf(cp3));    
        label16.set_text("%3.2f".printf(puissance));
        }
    }
     
    public void on_button2_clicked () {
        spinbutton1.value = 0.0;
        spinbutton2.value = 0.0;
        spinbutton3.value = 0.0;
        spinbutton4.value = 0.0;
        spinbutton5.value = 0.0;
        spinbutton6.value = 0.0;
        spinbutton7.value = 0;
        spinbutton8.value = 0;
        spinbutton9.value = 0;
        spinbutton10.value = 97.50;
        label7.set_text("NC");
        label9.set_text("NC");
        label11.set_text("NC");
        label13.set_text("NC");
        label16.set_text("NC");
        radiobutton1.set_active(true);
        spinbutton4.set_visible(false);
        radiobutton3.set_active(true);
        radiobutton6.set_active(true);
    }
     
    public void on_button3_clicked () {
        var mes = new Gtk.MessageDialog (window, Gtk.DialogFlags.MODAL, Gtk.MessageType.INFO, Gtk.ButtonsType.OK, "Calcul de puissance à vélo - C. Journoud avec Vala - Août 2010");
        mes.run();
        mes.destroy();
    }
     
    public void on_radiobutton1_toggled () {
        spinbutton3.set_visible(true);
        spinbutton4.set_visible(false);
    }
     
    public void on_radiobutton2_toggled () {
        spinbutton3.set_visible(false);
        spinbutton4.set_visible(true);
    }
     
    int main (string[] args) {     
        Gtk.init (ref args);
     
        try {
            var builder = new Builder ();
            builder.add_from_file ("puissance.glade");
            builder.connect_signals (null);
            window = builder.get_object ("window1") as Window;
            spinbutton1 = builder.get_object ("spinbutton1") as SpinButton;
            spinbutton2 = builder.get_object ("spinbutton2") as SpinButton;
            spinbutton3 = builder.get_object ("spinbutton3") as SpinButton;
            spinbutton4 = builder.get_object ("spinbutton4") as SpinButton;
            spinbutton5 = builder.get_object ("spinbutton5") as SpinButton;
            spinbutton6 = builder.get_object ("spinbutton6") as SpinButton;
            spinbutton7 = builder.get_object ("spinbutton7") as SpinButton;
            spinbutton8 = builder.get_object ("spinbutton8") as SpinButton;
            spinbutton9 = builder.get_object ("spinbutton9") as SpinButton;
            spinbutton10 = builder.get_object ("spinbutton10") as SpinButton;
            label7 = builder.get_object ("label7") as Label;
            label9 = builder.get_object ("label9") as Label;
            label11 = builder.get_object ("label11") as Label;
            label13 = builder.get_object ("label13") as Label;
            label16 = builder.get_object ("label16") as Label;
            radiobutton1 = builder.get_object ("radiobutton1") as RadioButton;
            radiobutton2 = builder.get_object ("radiobutton2") as RadioButton;
            radiobutton3 = builder.get_object ("radiobutton3") as RadioButton;
            radiobutton4 = builder.get_object ("radiobutton4") as RadioButton;
            radiobutton5 = builder.get_object ("radiobutton5") as RadioButton;
            radiobutton6 = builder.get_object ("radiobutton6") as RadioButton;
            radiobutton7 = builder.get_object ("radiobutton7") as RadioButton;
            radiobutton8 = builder.get_object ("radiobutton8") as RadioButton;
     
            window.destroy.connect(Gtk.main_quit);
            window.show_all ();
            spinbutton4.set_visible(false);
            Gtk.main ();
        } catch (Error e) {
            stderr.printf ("Could not load UI: %s\n", e.message);
            return 1;
        } 
     
        return 0;
    }
    Voici le fichier .glade

    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
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
     
    <?xml version="1.0"?>
    <glade-interface>
      <!-- interface-requires gtk+ 2.16 -->
      <!-- interface-naming-policy project-wide -->
      <widget class="GtkWindow" id="window1">
        <property name="title" translatable="yes">Calcul de puissance &#xE0; v&#xE9;lo</property>
        <property name="resizable">False</property>
        <property name="window_position">center</property>
        <child>
          <widget class="GtkAlignment" id="alignment1">
            <property name="visible">True</property>
            <child>
              <widget class="GtkVBox" id="vbox1">
                <property name="visible">True</property>
                <property name="homogeneous">True</property>
                <child>
                  <widget class="GtkHBox" id="hbox1">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label1">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Masse corporelle en kg :</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton1">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="xalign">1</property>
                        <property name="overwrite_mode">True</property>
                        <property name="adjustment">0 0 110 0.10000000000000001 10 0</property>
                        <property name="digits">2</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">0</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox3">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label2">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Masse v&#xE9;lo + &#xE9;quipement en kg :</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton2">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="xalign">1</property>
                        <property name="adjustment">0 0 20 0.01 10 0</property>
                        <property name="digits">2</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">1</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox4">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton1">
                        <property name="label" translatable="yes">D&#xE9;nivel&#xE9; en m :</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">radiobutton2</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton3">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="xalign">1</property>
                        <property name="adjustment">0 0 3000 1 10 0</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">2</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox5">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton2">
                        <property name="label" translatable="yes">Pente en % :</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="active">True</property>
                        <property name="draw_indicator">True</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton4">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="xalign">1</property>
                        <property name="adjustment">0 0 30 0.10000000000000001 10 0</property>
                        <property name="digits">2</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">3</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox6">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label3">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Altitude moyenne en m :</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton5">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="xalign">1</property>
                        <property name="adjustment">0 0 3000 1 10 0</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">4</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox7">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label4">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Distance en km :</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton6">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="adjustment">0 0 300 0.01 10 0</property>
                        <property name="digits">2</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">5</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox9">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label5">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Temps en hh:mm:ss :</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton7">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="adjustment">0 0 59 1 10 0</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton8">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="adjustment">0 0 59 1 10 0</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">2</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton9">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="adjustment">0 0 60 1 10 0</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">3</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">6</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox8">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label6">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Vitesse en km/h : </property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkLabel" id="label7">
                        <property name="visible">True</property>
                        <property name="label" translatable="yes">NC</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">7</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox10">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label8">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Puissance li&#xE9;e &#xE0; la gravit&#xE9; : </property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkLabel" id="label9">
                        <property name="visible">True</property>
                        <property name="label" translatable="yes">NC</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">8</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox11">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label10">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Puissance li&#xE9;e &#xE0; la p&#xE9;n&#xE9;tration dans l'air : </property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkLabel" id="label11">
                        <property name="visible">True</property>
                        <property name="label" translatable="yes">label</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">9</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox12">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton3">
                        <property name="label" translatable="yes">Haut</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="active">True</property>
                        <property name="draw_indicator">True</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton4">
                        <property name="label" translatable="yes">Bas</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">radiobutton3</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton5">
                        <property name="label" translatable="yes">CLM</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">radiobutton3</property>
                      </widget>
                      <packing>
                        <property name="position">2</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">10</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox14">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label12">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Puissance li&#xE9;e aux frottements : </property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkLabel" id="label13">
                        <property name="visible">True</property>
                        <property name="label" translatable="yes">NC</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">11</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox15">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton6">
                        <property name="label" translatable="yes">700 x 23</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="active">True</property>
                        <property name="draw_indicator">True</property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton7">
                        <property name="label" translatable="yes">26" route</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">radiobutton6</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkRadioButton" id="radiobutton8">
                        <property name="label" translatable="yes">26" cross</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">False</property>
                        <property name="draw_indicator">True</property>
                        <property name="group">radiobutton6</property>
                      </widget>
                      <packing>
                        <property name="position">2</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">12</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox16">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label14">
                        <property name="visible">True</property>
                        <property name="tooltip" translatable="yes">Prendre 97,5 % pour les v&#xE9;los modernes des ann&#xE9;es 2000, et &#xE0; estimer  pour les p&#xE9;riodes pr&#xE9;c&#xE9;dentes</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> Rendement du v&#xE9;lo en % : </property>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkSpinButton" id="spinbutton10">
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="invisible_char">&#x25CF;</property>
                        <property name="xalign">1</property>
                        <property name="adjustment">97.5 75 100 0.5 10 0</property>
                        <property name="digits">2</property>
                        <property name="snap_to_ticks">True</property>
                        <property name="numeric">True</property>
                        <property name="wrap">True</property>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">13</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox17">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkLabel" id="label15">
                        <property name="visible">True</property>
                        <property name="xalign">0</property>
                        <property name="label" translatable="yes"> PUISSANCE TOTALE EN W : </property>
                        <attributes>
                          <attribute name="language"/>
                        </attributes>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkLabel" id="label16">
                        <property name="visible">True</property>
                        <property name="label" translatable="yes"> NC </property>
                        <attributes>
                          <attribute name="language"/>
                        </attributes>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">14</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHSeparator" id="hseparator1">
                    <property name="visible">True</property>
                  </widget>
                  <packing>
                    <property name="expand">False</property>
                    <property name="position">15</property>
                  </packing>
                </child>
                <child>
                  <widget class="GtkHBox" id="hbox2">
                    <property name="visible">True</property>
                    <child>
                      <widget class="GtkButton" id="button1">
                        <property name="label" translatable="yes">Calculer</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                        <signal name="clicked" handler="on_button1_clicked"/>
                      </widget>
                      <packing>
                        <property name="position">0</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkButton" id="button2">
                        <property name="label" translatable="yes">Effacer</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                        <signal name="clicked" handler="on_button2_clicked"/>
                      </widget>
                      <packing>
                        <property name="position">1</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkButton" id="button3">
                        <property name="label">gtk-about</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                        <property name="use_stock">True</property>
                        <signal name="clicked" handler="on_button3_clicked"/>
                      </widget>
                      <packing>
                        <property name="position">2</property>
                      </packing>
                    </child>
                    <child>
                      <widget class="GtkButton" id="button4">
                        <property name="label">gtk-quit</property>
                        <property name="visible">True</property>
                        <property name="can_focus">True</property>
                        <property name="receives_default">True</property>
                        <property name="use_stock">True</property>
                        <signal name="clicked" handler="gtk_main_quit"/>
                      </widget>
                      <packing>
                        <property name="position">3</property>
                      </packing>
                    </child>
                  </widget>
                  <packing>
                    <property name="position">16</property>
                  </packing>
                </child>
              </widget>
            </child>
          </widget>
        </child>
      </widget>
    </glade-interface>
    Mes widgets sont globaux. Je ne trouve pas cela très élégant.
    C'est un premier jet avec beaucoup à reprendre.
    Ce qui est sûr c'est que je ne suis pas à l'aise dans le passage de Glade au code car je ne "vois" pas ce qui est fait.

  8. #8
    Membre averti
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    14
    Détails du profil
    Informations personnelles :
    Âge : 63
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 14
    Par défaut
    En fait c'est un fil sur Gtk mais plus orienté C que Vala ; Je me demande donc si je ne devrais pas poster ailleurs sur le site !

Discussions similaires

  1. Utilisation de signaux avec GtkBuilder
    Par rabbi_jaccob dans le forum GTK+ avec C & C++
    Réponses: 3
    Dernier message: 12/06/2008, 18h06
  2. [GTK+] Capture vidéo avec OpenCV et intégration dans une GUI GTK+
    Par kurapix dans le forum GTK+ avec C & C++
    Réponses: 6
    Dernier message: 21/04/2008, 10h12
  3. GTK+ un prolbème avec draw_rectangle
    Par Bébar dans le forum GTK+
    Réponses: 5
    Dernier message: 08/07/2007, 14h32
  4. GTK et OPENGL avec gtkglarea
    Par Vincent|Dev dans le forum OpenGL
    Réponses: 1
    Dernier message: 09/02/2005, 13h33
  5. [GTK]instal devPack avec dev c++
    Par FreshVic dans le forum Autres éditeurs
    Réponses: 8
    Dernier message: 15/04/2003, 16h48

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo