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 :

[Débutant]_Récupérer tous les widgets d'une fenêtre_


Sujet :

GTK+ avec C & C++

  1. #1
    Membre émérite Avatar de orfix
    Homme Profil pro
    Inscrit en
    Avril 2007
    Messages
    707
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2007
    Messages : 707
    Par défaut [Débutant]_Récupérer tous les widgets d'une fenêtre_
    Salut,
    J'essaie de manipuler plusieurs widgets présent sur une fenêtre par le biais d'une fonction callback mais, en vain

    D'après ce TUTO si j'ai bien compris j'aurai besoin d'une GList mais, après plusieurs essaies je ne vois pas dans quel ordre je récupère mais différent widget !

    Pour illustrer mon problème j'ai écrit ce petit programme dans le but est de permuter les chaînes contenues dans deux GtkEntry suit à l'appui sur un bouton ...
    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
     
    #include <gtk/gtk.h>
     
    void cb_swap( GtkWidget *p_widget, gpointer data );
     
    int main( int argc, char *argv[] )
    {
    	gtk_init( &argc, &argv );
     
    	GtkWidget *mainWindow	= gtk_window_new( GTK_WINDOW_TOPLEVEL );
    	GtkWidget *lbl_title_A	= gtk_label_new("Titre A :");
    	GtkWidget *lbl_title_B	= gtk_label_new("Titre B :");
    	GtkWidget *txt_entry_A	= gtk_entry_new();
    	GtkWidget *txt_entry_B	= gtk_entry_new();
    	GtkWidget *cmd_swap	= gtk_button_new_with_label("SWAP");
    	GtkWidget *mainBox	= gtk_vbox_new(FALSE,10);
     
    	/* Mise en place des Widgets sur la fenetre ... */
    	gtk_container_add(GTK_CONTAINER(mainWindow),mainBox);
    	gtk_box_pack_start(GTK_BOX(mainBox),lbl_title_A,FALSE,FALSE,5);
    	gtk_box_pack_start(GTK_BOX(mainBox),txt_entry_A,FALSE,FALSE,5);
    	gtk_box_pack_start(GTK_BOX(mainBox),lbl_title_B,FALSE,FALSE,5);
    	gtk_box_pack_start(GTK_BOX(mainBox),txt_entry_B,FALSE,FALSE,5);
    	gtk_box_pack_start(GTK_BOX(mainBox),cmd_swap,FALSE,FALSE,5);
     
    	g_signal_connect(G_OBJECT(cmd_swap),"clicked",G_CALLBACK(cb_swap),mainBox);	
    	g_signal_connect(G_OBJECT(mainWindow),"delete-event",G_CALLBACK(gtk_main_quit),NULL);	
     
    	gtk_widget_show_all( mainWindow );
    	gtk_main();
     
    	return 0;
    }
     
    void cb_swap( GtkWidget *p_widget, gpointer data )
    {
    	GList *p_list=gtk_container_get_children(GTK_CONTAINER((GtkWidget*)data));
    	GtkWidget *txt_entry_A,*txt_entry_B;	
    	gchar *buff_A,*buff_B;
     
    	/* Sauter le 'lbl_title_A' */
    	p_list=g_list_next( p_list );
    	/* Recuperer le 'txt_entry_A' */
    	txt_entry_A=GTK_WIDGET( p_list->data );
     
    	/* Sauter le 'lbl_title_B' */
    	p_list=g_list_next( p_list );
    	/* Recuperer le 'txt_entry_B' */
    	txt_entry_B=GTK_WIDGET( p_list->data );
     
    	/* Permutation ...*/
    	buff_A=gtk_entry_get_text(GTK_ENTRY( txt_entry_A ));
    	buff_B=gtk_entry_get_text(GTK_ENTRY( txt_entry_B ));
     
    	gtk_entry_set_text(GTK_ENTRY( txt_entry_A ),buff_B);
    	gtk_entry_set_text(GTK_ENTRY( txt_entry_B ),buff_A);
     
    	(void)p_widget;
    }
    Si quelqu'un pouvait m'expliquer brièvement le principe ou alors seulement corriger mon bout de code cela serait sympa
    Merci
    @++

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2006
    Messages
    172
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2006
    Messages : 172
    Par défaut
    essaye comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    txt_entry_A = g_list_nth_data(p_list,2);
    txt_entry_B = g_list_nth_data(p_list,4);

  3. #3
    Membre émérite Avatar de orfix
    Homme Profil pro
    Inscrit en
    Avril 2007
    Messages
    707
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

    Informations professionnelles :
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Avril 2007
    Messages : 707
    Par défaut
    Citation Envoyé par Kicker Voir le message
    essaye comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    txt_entry_A = g_list_nth_data(p_list,2);
    txt_entry_B = g_list_nth_data(p_list,4);
    Merci Beaucoup !!!
    Fallait aussi que j'alloue un buffer pour y stocker temporairement une des deux chaînes
    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
     
    #include <string.h>
    <...>
    void cb_swap( GtkWidget *p_widget, gpointer data )
    {
    	GList *p_list=gtk_container_get_children(GTK_CONTAINER((GtkWidget*)data));
    	GtkWidget *txt_entry_A,*txt_entry_B;	
    	const gchar *buff_A,*buff_B;
    	gchar temp[512];
     
    	txt_entry_A = GTK_WIDGET( g_list_nth_data(p_list,1) );
    	txt_entry_B = GTK_WIDGET( g_list_nth_data(p_list,3) );
     
    	/* Permutation ...*/
    	buff_A=gtk_entry_get_text(GTK_ENTRY( txt_entry_A ));
    	buff_B=gtk_entry_get_text(GTK_ENTRY( txt_entry_B ));
    	strcpy( temp,buff_A);
    	gtk_entry_set_text(GTK_ENTRY( txt_entry_A ), buff_B );
    	gtk_entry_set_text(GTK_ENTRY( txt_entry_B ), temp );
     
    	(void)p_widget;
    }
    Encore merci

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 23/01/2013, 12h16
  2. [Débutant] Initialiser les propriétés de tous les objets d'une ArrayList
    Par Tententai dans le forum API standards et tierces
    Réponses: 5
    Dernier message: 23/05/2006, 20h24
  3. afficher tous les champs d'une table
    Par julio84 dans le forum ASP
    Réponses: 8
    Dernier message: 19/01/2005, 10h31
  4. Afficher tous les champs d'une table avec dbexpress et MySQL
    Par LHT dans le forum Bases de données
    Réponses: 2
    Dernier message: 25/06/2004, 17h11
  5. Envoie d'un message a TOUS les composant d'une form
    Par chddv dans le forum Composants VCL
    Réponses: 7
    Dernier message: 15/09/2003, 09h47

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