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+ Discussion :

Revenir en arrière avec GTK


Sujet :

GTK+

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Novembre 2009
    Messages
    8
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2009
    Messages : 8
    Par défaut Revenir en arrière avec GTK
    Bonjour,

    Je suis en train de faire un projet informatique et j'essaye de simuler un distributeur d'argent. L'idée est que quand on arrive à la fin ou on veut finir on doit revenir à l'écran d'accueil ou le début.

    J'ai pensé à appeler la première fonction pour qu'elle fasse l'écran d'accueil. Le problème c'est que quand je l'appelle à ce niveau là, j'arrive à voir l'écran voulu mais cette fonction n'écoute plus le clavier ou la souris.

    Peut être la bonne solution n'est pas de faire comme ça.

    Merci par avance. (désolé pour tous ls erreurs de codage, je suis novice)

    (en rouge le cheminement)

    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
    int main(int argc, char **argv)
    {
        MainWindow * pApp;
    
        pApp = g_malloc(sizeof(MainWindow));
    
        /** Initialize GTK+ */
        gtk_init(&argc,&argv);
    
        begin(pApp);
    
        /** Enter the main loop */
        gtk_main();
    
        g_signal_connect(G_OBJECT(pApp->pWindow), "destroy", G_CALLBACK(gtk_main_quit),NULL);
    
        return EXIT_SUCCESS;
    }
    
    void begin(gpointer data)
    {
        MainWindow *pApp;
        pApp = (MainWindow*) data;
    
        /** Create the main window */
        pApp->pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title(GTK_WINDOW(pApp->pWindow), "The free ATM");
        gtk_window_set_default_size(GTK_WINDOW(pApp->pWindow),600,600);
        gtk_window_set_position(GTK_WINDOW(pApp->pWindow), GTK_WIN_POS_CENTER);
    
        pApp->pTable = gtk_table_new(4,4,FALSE);
        gtk_container_add(GTK_CONTAINER(pApp->pWindow), GTK_WIDGET(pApp->pTable));
    
        pApp->pLabel = gtk_label_new("Please insert your card");
        pApp->pImage = gtk_image_new_from_file("logodef.png");
    
        gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pLabel,1, 2, 2, 3,GTK_EXPAND | GTK_FILL, GTK_EXPAND,0, 0);
        gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pImage,1, 2, 1, 2,GTK_EXPAND | GTK_FILL, GTK_EXPAND,0, 0);
    
        g_signal_connect(pApp->pWindow, "key-press-event",G_CALLBACK(accounts), (gpointer) pApp);
    
        gtk_widget_show_all(pApp->pWindow);
    }
    
    void accounts(GtkWidget *pWidget,GdkEventKey* pKey,gpointer data)
    {
        MainWindow *pApp;
        pApp = (MainWindow*) data;
    
        /**
         *    F1->F12
         * 65470->65481
         */
    
        unsigned short i=65470;
        unsigned short key = pKey->keyval;
        char chain[50];
    
        FILE * file;
        file = fopen(in,"r");
    
        for(i;i<65482 && pApp->pEntry == NULL ;i++)
        {
            fscanf(file,"%[^\n]",chain);
            fgetc(file);
    
            if(i == key)
            {
                fillsheet(pApp,chain);
    
                gtk_label_set_text(GTK_LABEL(pApp->pLabel),"Please enter the password");
    
                pApp->pEntry = gtk_entry_new();
                /* Limitation du nombre de caracteres */
                gtk_entry_set_max_length(GTK_ENTRY(pApp->pEntry), 4);
                /* Mode mot de passe */
                gtk_entry_set_visibility(GTK_ENTRY(pApp->pEntry), FALSE);
                /* Modification du caractere affiche */
                gtk_entry_set_invisible_char(GTK_ENTRY(pApp->pEntry), '*');
    
                gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pEntry,1, 2, 3, 4,GTK_EXPAND , GTK_EXPAND,100,0);
    
                g_signal_connect(G_OBJECT(pApp->pEntry), "activate", G_CALLBACK(checkpass), (gpointer) pApp);
    
                gtk_widget_show_all(pApp->pWindow);
    
            }
        }
    
        fclose(file);
    
        if(i==65482)
        {
            gtk_label_set_text(GTK_LABEL(pApp->pLabel),"Sorry, but your card is not valid \n Please remove your card");
            gtk_widget_show_all(pApp->pWindow);
            g_timeout_add(2000,retry,(gpointer) pApp);
        }
    
    }
    
    gboolean retry(gpointer data)
    {
        MainWindow *pApp;
        pApp = (MainWindow*) data;
    
        gtk_label_set_text(GTK_LABEL(pApp->pLabel),"Please insert your card");
    
        return FALSE;
    }
    
    void checkpass(GtkWidget *pEntry,gpointer data)
    {
        unsigned short id=0;
    
        MainWindow *pApp;
        pApp = (MainWindow*) data;
    
        const gchar *entry_Pass;
    
        entry_Pass = gtk_entry_get_text(GTK_ENTRY(pApp->pEntry));
    
        id = atol(entry_Pass);
    
        if(id == pApp->pass && pApp->fail <3)
        {
            choice(pApp);
        }
    
        else if(id != pApp->pass && pApp->fail <3)
        {
            pApp->fail=pApp->fail+1;
    
            gtk_label_set_text(GTK_LABEL(pApp->pLabel),"Please enter the right password");
        }
    
        else
        {
            gtk_label_set_text(GTK_LABEL(pApp->pLabel),"Locked account, please contact your bank");
            update(pApp);
            begin(pApp);
        }
    
    
    }
    
    void choice(gpointer data)
    {
        MainWindow *pApp;
        pApp = (MainWindow*) data;
    
        gtk_widget_destroy(pApp->pLabel);
        gtk_widget_destroy(pApp->pEntry);
    
        pApp->pButton[0]= gtk_button_new_with_label("Withdrawal");
        pApp->pButton[1]= gtk_button_new_with_label("Transfer");
        pApp->pButton[2]= gtk_button_new_with_label("Check");
        pApp->pButton[3]= gtk_button_new_with_label("Password");
        pApp->pButton[4]= gtk_button_new_with_label("Recharge");
        pApp->pButton[5]= gtk_button_new_with_label("End");
    
        gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pButton[0],0, 1, 0, 1,GTK_EXPAND | GTK_FILL, GTK_EXPAND,0, 0);
        gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pButton[1],0, 1, 1, 2,GTK_EXPAND | GTK_FILL, GTK_EXPAND,0, 0);
        gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pButton[2],0, 1, 2, 3,GTK_EXPAND | GTK_FILL, GTK_EXPAND,0, 0);
        gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pButton[3],2, 3, 0, 1,GTK_EXPAND | GTK_FILL, GTK_EXPAND,0, 0);
        gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pButton[4],2, 3, 1, 2,GTK_EXPAND | GTK_FILL, GTK_EXPAND,0, 0);
        gtk_table_attach(GTK_TABLE(pApp->pTable), pApp->pButton[5],2, 3, 2, 3,GTK_EXPAND | GTK_FILL, GTK_EXPAND,0, 0);
    
        g_signal_connect(G_OBJECT(pApp->pButton[0]), "clicked", G_CALLBACK(withdrawal), (gpointer) pApp);
        g_signal_connect(G_OBJECT(pApp->pButton[1]), "clicked", G_CALLBACK(transfer), (gpointer) pApp);
        g_signal_connect(G_OBJECT(pApp->pButton[2]), "clicked", G_CALLBACK(check), (gpointer) pApp);
        g_signal_connect(G_OBJECT(pApp->pButton[3]), "clicked", G_CALLBACK(password), (gpointer) pApp);
        g_signal_connect(G_OBJECT(pApp->pButton[4]), "clicked", G_CALLBACK(recharge), (gpointer) pApp);
        g_signal_connect(G_OBJECT(pApp->pButton[5]), "clicked", G_CALLBACK(back), (gpointer) pApp);
    
        gtk_widget_show_all(pApp->pWindow);
    
    }
    
    void back(GdkEventKey* pKey,gpointer data)
    {
        MainWindow *pApp;
        pApp = (MainWindow*) data;
    
        begin(pApp);
    }

  2. #2
    Membre à l'essai
    Profil pro
    Inscrit en
    Juin 2009
    Messages
    5
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2009
    Messages : 5
    Par défaut
    essaie une boucle du genre :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    while(password != ???)
    {
        printf("Your password isn't availible");
     
    }

Discussions similaires

  1. comment revenir à la ligne avec une zone memo ?
    Par kuhnden dans le forum Access
    Réponses: 2
    Dernier message: 23/11/2005, 22h38
  2. [GTK]problème avec GTK+ sur DEV-C++
    Par afrikha dans le forum Dev-C++
    Réponses: 7
    Dernier message: 01/10/2005, 14h13
  3. [GTK]installer Dev-C++ avec gtk 1.2 ...
    Par vbcasimir dans le forum Dev-C++
    Réponses: 2
    Dernier message: 02/02/2004, 13h34

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