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 :

Créer une boite de dialogue personalisée.


Sujet :

GTK+ avec C & C++

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    56
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2012
    Messages : 56
    Par défaut Créer une boite de dialogue personalisée.
    Bonjour,

    J'ai besoin d'une boite de dialogue personnalisée, mais je ne sais faire que des fenêtres. Je n'ai pas trouvé de tutorial pour une boite de dialogue personnalisée.

    Le problème, c'est que après avoir créé la fenêtre, le callback continue de s'exécuter, il n'attend pas la réponse.

  2. #2
    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
    Bonjour,

    personne ne pourra pas t'aider sans plus d'informations... Tu dois indiquer ce que tu as essayé, ce qui ne marche pas, et fournir un code exemple montrant le problème.

  3. #3
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    56
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2012
    Messages : 56
    Par défaut
    J'ai enfin trouvé un tutorial peu détaillé: à la section 10.3: http://www.cc.gatech.edu/data_files/...tk_tut-10.html

    Mais il y a un problème, la boite de dialogue ne se lance qu'une ou deux fois. Lorsque je clique sur le bouton qui lance la boite, le programme dit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    (test.exe:7832): Gtk-CRITICAL **: gtk_box_pack: assertion `GTK_IS_WIDGET (child)' failed
     
    (test.exe:7832): GLib-GObject-WARNING **: invalid (NULL) pointer instance
     
    (test.exe:7832): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion`G_TYPE_CHECK_INSTANCE (instance)' failed
     
    (test.exe:7832): GLib-GObject-WARNING **: invalid (NULL) pointer instance
     
    (test.exe:7832): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion`G_TYPE_CHECK_INSTANCE (instance)' failed

    Après un ou deux affichages de la boite, le programme plante en disant:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    (test.exe:7832): Gtk-CRITICAL **: gtk_box_pack: assertion `GTK_IS_WIDGET (child)' failed
     
    (test.exe:7832): GLib-GObject-CRITICAL **: g_object_ref: assertion `G_IS_OBJECT (object)' failed
    Mais les messages d'erreur dépendent des fois, défois il y en a moins et défois plus.

  4. #4
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    56
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2012
    Messages : 56
    Par défaut
    Voilà le code du callback qui déclenche la boite de dialogue, le dialogue est créé à la ligne 58 et déclenché à la ligne 66:
    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
    void on_button_b_transcode_clicked(GtkButton *button, gpointer user_data)
    {
     
      if(annulertranscode == 0) {
        annulertranscode = 1;
        stoptranscode = 0;
        gtk_widget_set_sensitive(button_b_transcode,FALSE);
        gtk_widget_set_sensitive(button_EA_compile,FALSE);
        gtk_widget_set_sensitive(button_backtest,FALSE);
     
        gchar * filename = (gchar*)gtk_entry_get_text(GTK_ENTRY(entry_backtest_file));
        int len = strlen(filename);
        if(len < 5) {
          GtkWidget *dialog;
          dialog = gtk_message_dialog_new(GTK_WINDOW(window1),
                GTK_DIALOG_DESTROY_WITH_PARENT,
                GTK_MESSAGE_WARNING,
                GTK_BUTTONS_OK,
                "Incorrect file name.");
          gtk_window_set_title(GTK_WINDOW(dialog), "Warning");
          gtk_dialog_run(GTK_DIALOG(dialog));
          gtk_widget_destroy(dialog);
          gtk_widget_set_sensitive(button_b_transcode,TRUE);
            gtk_widget_set_sensitive(button_backtest,TRUE);
            gtk_widget_set_sensitive(button_EA_compile,TRUE);
            gtk_button_set_label(GTK_BUTTON(button_b_transcode),"Transcode");
            annulertranscode = 0;
            input_format = -1;
            return;
        }
        input_format = -1;
        if(filename[len-1] == 'v' && filename[len-2] == 's' && filename[len-3] == 'c' && filename[len-4] == '.') input_format = 0;
        else if(filename[len-1] == '1' && filename[len-2] == 'f' && filename[len-3] == 'b' && filename[len-4] == '.') input_format = 1;
        else if(filename[len-1] == '2' && filename[len-2] == 'f' && filename[len-3] == 'b' && filename[len-4] == '.') input_format = 2;
        else if(filename[len-1] == '3' && filename[len-2] == 'f' && filename[len-3] == 'b' && filename[len-4] == '.') input_format = 3;
        else if(filename[len-1] == '4' && filename[len-2] == 'f' && filename[len-3] == 'b' && filename[len-4] == '.') input_format = 4;
     
        if(input_format == 4) {
            GtkWidget *dialog;
            dialog = gtk_message_dialog_new(GTK_WINDOW(window1),
                GTK_DIALOG_DESTROY_WITH_PARENT,
                GTK_MESSAGE_WARNING,
                GTK_BUTTONS_OK,
                "Format .bf4 is not Transcodable.");
            gtk_window_set_title(GTK_WINDOW(dialog), "Warning");
            gtk_dialog_run(GTK_DIALOG(dialog));
            gtk_widget_destroy(dialog);
            gtk_widget_set_sensitive(button_b_transcode,TRUE);
            gtk_widget_set_sensitive(button_backtest,TRUE);
            gtk_widget_set_sensitive(button_EA_compile,TRUE);
            gtk_button_set_label(GTK_BUTTON(button_b_transcode),"Transcode");
            annulertranscode = 0;
            input_format = -1;
            return;
     
        } else if(input_format >= 0 && input_format <= 3) {
          transcode = 0;
          create_window2();
     
     
          if(input_format == 0) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radiobutton_dialog_transcode_bf1),TRUE);
          if(input_format == 1) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radiobutton_dialog_transcode_bf2),TRUE);
          if(input_format == 2) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radiobutton_dialog_transcode_bf3),TRUE);
          if(input_format == 3) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radiobutton_dialog_transcode_bf4),TRUE);
     
          transcode = gtk_dialog_run(GTK_DIALOG(window2));
     
          if(transcode == 0) {
            gtk_widget_set_sensitive(button_b_transcode,TRUE);
            gtk_widget_set_sensitive(button_backtest,TRUE);
            gtk_widget_set_sensitive(button_EA_compile,TRUE);
            annulertranscode = 0;
            gtk_widget_destroy(window2);
            return;
     
          }
          gtk_widget_set_sensitive(button_b_transcode,TRUE);
          gtk_button_set_label(GTK_BUTTON(button_b_transcode),"Stop Transcode");
     
          if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton_dialog_transcode_bf1))) g_thread_create(csv_to_bf1_thread,progressbar_backtest,TRUE,NULL);
          if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton_dialog_transcode_bf2))) {
            if(input_format == 0) g_thread_create(csv_to_bf2_thread,progressbar_backtest,TRUE,NULL);
            else if(input_format == 1) g_thread_create(bf1_to_bf2_thread,progressbar_backtest,TRUE,NULL);
          }
     
          if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton_dialog_transcode_bf3))) {
            if(input_format == 0) g_thread_create(csv_to_bf3_thread,progressbar_backtest,TRUE,NULL);
            else if(input_format == 1) g_thread_create(bf1_to_bf3_thread,progressbar_backtest,TRUE,NULL);
            else if(input_format == 2) g_thread_create(bf2_to_bf3_thread,progressbar_backtest,TRUE,NULL);
     
          }
     
          if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(radiobutton_dialog_transcode_bf4))) {
            if(input_format == 0) g_thread_create(csv_to_bf4_thread,progressbar_backtest,TRUE,NULL);
            else if(input_format == 1) g_thread_create(bf1_to_bf4_thread,progressbar_backtest,TRUE,NULL);
            else if(input_format == 2) g_thread_create(bf2_to_bf4_thread,progressbar_backtest,TRUE,NULL);
            else if(input_format == 3) g_thread_create(bf3_to_bf4_thread,progressbar_backtest,TRUE,NULL);
          }
     
          gtk_widget_destroy(window2);
          input_format = -1;
     
     
     
        } else if(input_format == -1) {
            GtkWidget *dialog;
            dialog = gtk_message_dialog_new(GTK_WINDOW(window1),
                GTK_DIALOG_DESTROY_WITH_PARENT,
                GTK_MESSAGE_WARNING,
                GTK_BUTTONS_OK,
                "Unknown file format.");
            gtk_window_set_title(GTK_WINDOW(dialog), "Warning");
            gtk_dialog_run(GTK_DIALOG(dialog));
            gtk_widget_destroy(dialog);
            gtk_widget_set_sensitive(button_b_transcode,TRUE);
            gtk_widget_set_sensitive(button_backtest,TRUE);
            gtk_widget_set_sensitive(button_EA_compile,TRUE);
            gtk_button_set_label(GTK_BUTTON(button_b_transcode),"Transcode");
            annulertranscode = 0;
            input_format = -1;
            return;
        }
     
      } else {
        stoptranscode = 1;
     
      }
     
    }
    Et le code de création de la boite de dialogue, les widget sont contenus dans des variables globales:
    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
     
      GtkWidget *window2;
      GtkWidget *label_dialog_transcode;
      GtkWidget *radiobutton_dialog_transcode_bf1;
      GSList *radiobutton_dialog_transcode_bf1_group = NULL;
      GtkWidget *radiobutton_dialog_transcode_bf2;
      GtkWidget *radiobutton_dialog_transcode_bf3;
      GtkWidget *radiobutton_dialog_transcode_bf4;
      GtkWidget *hbuttonbox5;
      GtkWidget *button_dialog_transcode_cancel;
      GtkWidget *button_dialog_transcode_ok;
     
    GtkWidget* create_window2 (void)
    {
     
     
      window2 = gtk_dialog_new ();
      gtk_window_set_title (GTK_WINDOW (window2), "Transcode");
     
      gtk_widget_show (GTK_DIALOG(window2)->vbox);
      gtk_container_set_border_width (GTK_CONTAINER (GTK_DIALOG(window2)->vbox), 5);
     
      label_dialog_transcode = gtk_label_new ("Choix du format:");
      gtk_widget_show (label_dialog_transcode);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window2)->vbox), label_dialog_transcode, FALSE, FALSE, 0);
     
     
     
      radiobutton_dialog_transcode_bf1 = gtk_radio_button_new_with_mnemonic (NULL, "Format .bf1 (contains all data, but the file is read faster)");
      if(input_format == 0) gtk_widget_show (radiobutton_dialog_transcode_bf1);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window2)->vbox), radiobutton_dialog_transcode_bf1, FALSE, FALSE, 0);
      gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_dialog_transcode_bf1), radiobutton_dialog_transcode_bf1_group);
      radiobutton_dialog_transcode_bf1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_dialog_transcode_bf1));
     
     
      radiobutton_dialog_transcode_bf2 = gtk_radio_button_new_with_mnemonic (NULL, "Format .bf2 (do not contains BidVolume and AskVolume)");
      if(input_format <= 1) gtk_widget_show (radiobutton_dialog_transcode_bf2);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window2)->vbox), radiobutton_dialog_transcode_bf2, FALSE, FALSE, 0);
      gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_dialog_transcode_bf2), radiobutton_dialog_transcode_bf1_group);
      radiobutton_dialog_transcode_bf1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_dialog_transcode_bf2));
     
     
     
      radiobutton_dialog_transcode_bf3 = gtk_radio_button_new_with_mnemonic (NULL, "Format .bf3 (do not contains TickTime, only Bid and Ask of each tick)");
      if(input_format <= 2) gtk_widget_show (radiobutton_dialog_transcode_bf3);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window2)->vbox), radiobutton_dialog_transcode_bf3, FALSE, FALSE, 0);
      gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_dialog_transcode_bf3), radiobutton_dialog_transcode_bf1_group);
      radiobutton_dialog_transcode_bf1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_dialog_transcode_bf3));
     
     
      radiobutton_dialog_transcode_bf4 = gtk_radio_button_new_with_mnemonic (NULL, "Format .bf4 (contains only Bid and Ask, but faster to read than .bf3)");
      gtk_widget_show (radiobutton_dialog_transcode_bf4);
      gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window2)->vbox), radiobutton_dialog_transcode_bf4, FALSE, FALSE, 0);
      gtk_radio_button_set_group (GTK_RADIO_BUTTON (radiobutton_dialog_transcode_bf4), radiobutton_dialog_transcode_bf1_group);
      radiobutton_dialog_transcode_bf1_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radiobutton_dialog_transcode_bf4));
     
      gtk_dialog_add_button(GTK_DIALOG(window2),"Cancel",0);
      gtk_dialog_add_button(GTK_DIALOG(window2),"Trancode",1);
      gtk_dialog_set_default_response(GTK_DIALOG(window2),0);
     
      return window2;
    }

  5. #5
    Membre éclairé
    Profil pro
    Retraité
    Inscrit en
    Novembre 2009
    Messages
    331
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2009
    Messages : 331
    Par défaut
    En lançant le programme avec l'option --g-fatal-warnings, il plante au premier warning et en utilisant un debogueur, ceci te permettra de mieux localiser le problème.

  6. #6
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2012
    Messages
    56
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2012
    Messages : 56
    Par défaut
    Le premier warning est celui là, mais je ne sais pas ce que ça signifie:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (test.exe:4108): Gtk-CRITICAL **: gtk_box_pack: assertion `GTK_IS_WIDGET (child)' failed
    EDIT: Apparemment j'ai réussit à supprimer ce warning, il y avait une ligne de code en trop et au mauvais endroit.

    Maintenant il dit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    (test.exe:11528): GLib-GObject-CRITICAL **: g_object_ref: assertion `G_IS_OBJECT (object)' failed

Discussions similaires

  1. Créer une boite de dialogue ou pas?
    Par Freud44 dans le forum C++Builder
    Réponses: 5
    Dernier message: 06/05/2008, 00h30
  2. Réponses: 6
    Dernier message: 29/01/2008, 18h47
  3. Comment créer une boite de dialogue d'options comme Delphi?
    Par Patrick25300 dans le forum Composants VCL
    Réponses: 2
    Dernier message: 04/01/2008, 17h56
  4. Réponses: 2
    Dernier message: 06/10/2006, 14h31
  5. Réponses: 4
    Dernier message: 26/01/2006, 16h13

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