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 :

ajouter un élément à une vBox par une fonction callback


Sujet :

GTK+ avec C & C++

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Inscrit en
    Mai 2009
    Messages
    23
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2009
    Messages : 23
    Points : 27
    Points
    27
    Par défaut ajouter un élément à une vBox par une fonction callback
    Bonjour,

    voilà mon problème:
    J'ai créé un fenêtre avec une combobox intégrée dans un vbox. Je voudrais que lorsque je change la valeur active de cette combobox et qu'elle arrive sur une valeur (DAMA), une autre combobox vienne s'ajouter en dessous de la première sur la même fenêtre et je voudrais que celle-ci disparaisse quand je sélectionne une autre entrée active (Determinist).

    Voilà mon code:


    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
    #include <stdlib.h>
    #include <stdarg.h>
    #include <stdio.h>
    #include <gtk/gtk.h>
    #include <glib/gprintf.h>
     
     
    void req_menu (GtkWidget * p_wid, gpointer *p_data)
    {
        GtkWidget *p_combo2 = NULL;
        GtkComboBox *p_combo1 = p_wid;
        GtkBox *p_vbox = p_data;
     
        gchar *active_text = gtk_combo_box_get_active_text(p_combo1);
     
        if(strcmp(active_text, "DAMA") == 0) {
     
            p_combo2 = gtk_combo_box_new_text();
            gtk_combo_box_append_text(p_combo2, "Determinist");
            gtk_combo_box_append_text(p_combo2, "Contention");
            gtk_combo_box_append_text(p_combo2, "Contention+Determinist");
            gtk_box_pack_start(p_vbox, p_combo2, FALSE, FALSE, 0);
        }
     
    }
     
     
     
    int main(int argc, char **argv)
    {
        /* Variables */
        GtkWidget * p_win = NULL;
        GtkWidget * p_vbox = NULL;
        GtkWidget * p_button = NULL;
        GtkWidget * p_combo = NULL;
     
        /* Initialisation de GTK+ */
        gtk_init(&argc, &argv);
     
        /* Création de la fenêtre */
        p_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_default_size(GTK_WINDOW(p_win), 300, 300);
     
     
        /* Ajout du conteneur principal et des boutons*/
        p_vbox = gtk_vbox_new(FALSE, 0);
        gtk_container_add(GTK_CONTAINER (p_win), p_vbox);
     
        p_combo = gtk_combo_box_new_text();
     
        gtk_combo_box_append_text(p_combo, "Determinist");
        gtk_combo_box_append_text(p_combo, "Contention");
        gtk_combo_box_append_text(p_combo, "DAMA");
        gtk_combo_box_append_text(p_combo, "DAMA+Contention");
     
        gtk_box_pack_start(p_vbox, p_combo, FALSE, FALSE, 0);
     
     
     
        gtk_widget_show_all(p_win);
     
        g_signal_connect(G_OBJECT(p_combo), "changed", G_CALLBACK (req_menu), p_vbox);
     
        g_signal_connect(G_OBJECT(p_win), "delete-event", G_CALLBACK( gtk_main_quit ), NULL);
     
     
        gtk_widget_show_all(p_win);
     
        /* Affichage et boucle événementielle */
        gtk_main();
     
        /* Fermeture de GTK+ */
        gtk_exit(EXIT_SUCCESS);
        return EXIT_SUCCESS;
    }
    Merci de votre aide.

  2. #2
    Membre habitué

    Inscrit en
    Mai 2005
    Messages
    132
    Détails du profil
    Informations forums :
    Inscription : Mai 2005
    Messages : 132
    Points : 171
    Points
    171
    Par défaut
    Salut,

    apres reparer quelques fautes (il n'etait pas possible le composer sous Linux et gcc 4.1.2) et par excellence apres ajouter gtk_widget_show ... ca marche ...

    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
     
    #include <stdlib.h>
    //#include <stdarg.h>
    //#include <stdio.h>
    #include <gtk/gtk.h>
    //#include <glib/gprintf.h>
     
    #include <string.h>
     
     
    void req_menu (GtkWidget * p_wid, gpointer p_data)
    {
        GtkComboBox *p_combo2 = NULL;
        GtkComboBox *p_combo1 = (GtkComboBox *)p_wid;
        GtkBox *p_vbox = (GtkBox *)p_data;
     
        gchar *active_text = gtk_combo_box_get_active_text(p_combo1);
     
        if(strcmp(active_text, "DAMA") == 0)
        {
     
            p_combo2 = (GtkComboBox*)gtk_combo_box_new_text();
            gtk_combo_box_append_text(p_combo2, "Determinist");
            gtk_combo_box_append_text(p_combo2, "Contention");
            gtk_combo_box_append_text(p_combo2, "Contention+Determinist");
            gtk_box_pack_start(p_vbox, (GtkWidget*)p_combo2, FALSE, FALSE, 0);
     
    //**********************************************************************************
            gtk_widget_show ( (GtkWidget*)p_combo2 );
    //**********************************************************************************
     
        }
     
    }
     
     
     
    int main(int argc, char **argv)
    {
        /* Variables */
        GtkWidget * p_win = NULL;
        GtkWidget * p_vbox = NULL;
    //    GtkWidget * p_button = NULL;
        GtkWidget * p_combo = NULL;
     
        /* Initialisation de GTK+ */
        gtk_init(&argc, &argv);
     
        /* Création de la fenêtre */
        p_win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_default_size(GTK_WINDOW(p_win), 300, 300);
     
     
        /* Ajout du conteneur principal et des boutons*/
        p_vbox = gtk_vbox_new(FALSE, 0);
        gtk_container_add(GTK_CONTAINER (p_win), p_vbox);
     
        p_combo = gtk_combo_box_new_text();
     
        gtk_combo_box_append_text( (GtkComboBox*) p_combo, "Determinist");
        gtk_combo_box_append_text( (GtkComboBox*) p_combo, "Contention");
        gtk_combo_box_append_text( (GtkComboBox*) p_combo, "DAMA");
        gtk_combo_box_append_text( (GtkComboBox*) p_combo, "DAMA+Contention");
     
        gtk_box_pack_start( (GtkBox*)p_vbox, p_combo, FALSE, FALSE, 0);
     
     
     
        gtk_widget_show_all(p_win);
     
        g_signal_connect(G_OBJECT(p_combo), "changed", G_CALLBACK (req_menu), p_vbox);
     
        g_signal_connect(G_OBJECT(p_win), "delete-event", G_CALLBACK( gtk_main_quit ), NULL);
     
     
        gtk_widget_show_all(p_win);
     
        /* Affichage et boucle événementielle */
        gtk_main();
     
        /* Fermeture de GTK+ */
        gtk_exit(EXIT_SUCCESS);
        return EXIT_SUCCESS;
    }
    Fredy "KRUGER"

    (je suis desole pour ma langue francaise)

Discussions similaires

  1. Réponses: 2
    Dernier message: 18/06/2009, 15h09
  2. Réponses: 3
    Dernier message: 07/08/2008, 13h19
  3. Réponses: 4
    Dernier message: 31/10/2007, 20h27
  4. masquer une partie d'une vidéo par une banniere
    Par lezabour dans le forum Général Conception Web
    Réponses: 1
    Dernier message: 16/10/2006, 16h47
  5. Réponses: 11
    Dernier message: 05/10/2006, 13h20

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