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
| #include <gtk/gtk.h>
gchar nbSecondesEcoulees = 6;
gboolean decompte_b (GtkWidget* Bouton)
{
gtk_widget_set_sensitive (GTK_WIDGET (Bouton), FALSE);
if (nbSecondesEcoulees == -1)
{
gtk_widget_set_sensitive (GTK_WIDGET (Bouton), TRUE);
return FALSE ;
}
gtk_widget_show_all(Bouton);
return TRUE;
}
gboolean decompte (GtkWidget* pLabel)
{
gchar *chaine = NULL;
gint val;
g_print("%d\n", --nbSecondesEcoulees);
val = nbSecondesEcoulees;
if (nbSecondesEcoulees == -1)
{
return FALSE ;
}
chaine = g_strdup_printf ("%d", val);
gtk_label_set_label (GTK_LABEL (pLabel), chaine);
g_free (chaine), chaine = NULL;
gtk_widget_show_all(pLabel);
return TRUE;
}
int main(int argc, char **argv)
{
GtkWidget *pVBox;
GtkWidget* pLabel;
GtkWidget* Fen;
GtkWidget* Bouton;
int cpt=5;
gtk_init(&argc, &argv);
/* Creation de la GtkBox verticale */
pVBox = gtk_vbox_new(TRUE, 0);
Fen = gtk_window_new (GTK_WINDOW_TOPLEVEL);
Bouton = gtk_button_new_with_label ("Quitter");
pLabel=gtk_label_new("");
/* Ajout de la GtkVBox dans la fenetre */
gtk_container_add(GTK_CONTAINER(Fen), pVBox);
gtk_box_pack_start(GTK_BOX(pVBox), Bouton, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(pVBox), pLabel, TRUE, TRUE, 0);
/*gtk_container_add(GTK_CONTAINER(Fen), GTK_WIDGET(pLabel));
gtk_container_add(GTK_CONTAINER(Fen),GTK_WIDGET(Bouton));*/
g_signal_connect(G_OBJECT(Bouton),"clicked",G_CALLBACK(gtk_main_quit), NULL);
// Appelle la fonction decompte toutes les 1000 ms // http://developer.gnome.org/doc/API/2.0/glib/glib-The-Main-Event-Loop.html
g_timeout_add(1000, (gpointer)decompte, pLabel);
g_timeout_add(1000, (gpointer)decompte_b, Bouton);
gtk_widget_show_all(Fen);
gtk_main(); return 0;
} |
Partager