gloobing
Messages postés7Date d'inscriptionmardi 10 février 2004StatutMembreDernière intervention30 juin 2004
-
10 févr. 2004 à 18:14
gloobing
Messages postés7Date d'inscriptionmardi 10 février 2004StatutMembreDernière intervention30 juin 2004
-
11 févr. 2004 à 11:26
Salut a tous... Je débute avec gtk mais je dois tres tres vite apprendre beaucoup de choses...
Donc voila deux truc me pose probléme :
=> Tout d'abord pour le splashscreen je n'arrive pas a détruire la fenêtre avec laquelle j'affiche le splashscreen [c'est a dire le message qui s'ouvre quand on ouvre un logiciel par exemple word, DevC++]. J'ai essaye de faire mettre l'image sur un bouton et de detruire la fenetre quand l'utilisateur clique dessus, ou une fonction qui au bout de 2 sec ferme la fenetre, mais ca marche pas!!!!!!
Donc pouvez vous m'aider
=> D'autre part, j'aimerais pouvoir "recharger" une image.
Au debut un bout de mon code ouvre un sorte d'explorer en gtk ou l'utilisateur sélectionne un image. Il est renvoyer vers ma fenetre principale. La j'aimerais qu'il puisse cliquer sur ouvrir selectionner un autre image et qu'elle bien afficher !!
comment faire
VOILA MON MAIN =>
#include "_Lib.h"
int main(int argc, char **argv)
{
gchar ExploPath[1024]; // Chaine pour stocker le path si argc < 2
gchar ImgPath[1024]; // Chaine pour stocker le path + 'Vous avez choisi'
GtkWidget *pWindow; // Fenêtre window
GtkWidget *pImage; // Image
gchar *pPath; // objet path du fichier
GtkWidget *pLabel; // objet path du txt
GtkWidget *vbox, *hbox; // box vertical & horizontal
GtkWidget *pButSplah;
GtkWidget *pQuitter; // Bouton Quitter
GtkWidget *pBrowse; // Bouton parcourir
GtkWidget *pFiltre; // Bouton pour application filtre
GtkWidget *pSave; // Bouton Save
GtkWidget *pJPG2BMP; // Convertir en JPEG
GtkWidget *BMPinfo; // Information BMP
pPath = argv[1];
/*////////////////////////////////////////////////////////////////////////////*/
// Initialisation des objets
gtk_init(&argc, &argv);
// Affichage du splash Screen
//Splash();
// Initialisation de la fenêtre
pWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
// Initialisation des box
vbox = gtk_vbox_new(0,0);
hbox = gtk_hbox_new(0,0);
// Initialisation des Boutons
pQuitter = gtk_button_new_from_stock(GTK_STOCK_QUIT);
pBrowse = gtk_button_new_from_stock(GTK_STOCK_OPEN);
pSave = gtk_button_new_from_stock(GTK_STOCK_SAVE);
pJPG2BMP = gtk_button_new_from_stock(GTK_STOCK_CONVERT);
BMPinfo = gtk_button_new_from_stock(GTK_STOCK_PROPERTIES);
if( argc < 2 )
{
parcourir((gchar *)&ExploPath);
pPath = ExploPath;
sprintf(ImgPath, "Image : %s", ExploPath);
pLabel = gtk_label_new(ImgPath);
}
else
{
sprintf(ImgPath, "Image : %s", pPath);
pLabel = gtk_label_new(ImgPath);
}
// Initialisation des images
pImage = gtk_image_new_from_file(pPath);
//gtk_image_set_from_pixbuf((GtkImage *)pImage, picbuff);
/*////////////////////////////////////////////////////////////////////////////*/
/*////////////////////////////////////////////////////////////////////////////*/
/* Ajout des controles aux boxes on commence par le début (pack_start) */
// hbox => boxes horizontales
gtk_box_pack_end((GtkBox*)hbox, pQuitter, 0, 0, 0);
gtk_box_pack_end((GtkBox*)hbox, pSave, 0, 0, 0);
gtk_box_pack_end((GtkBox*)hbox, pBrowse, 0, 0, 0);
gtk_box_pack_end((GtkBox*)hbox, BMPinfo, 0, 0, 0);
gtk_box_pack_end((GtkBox*)hbox, pJPG2BMP, 0, 0, 0);
// vbox => boxes verticales
gtk_box_pack_start((GtkBox*)vbox, pLabel, 0, 0, 0);
gtk_box_pack_start((GtkBox*)vbox, pImage, 0, 0, 0);
gtk_box_pack_start((GtkBox*)vbox, hbox, 0, 0, 0);
/*////////////////////////////////////////////////////////////////////////////*/
/*////////////////////////////////////////////////////////////////////////////*/
// Fonctions de call back
g_signal_connect((gpointer)pQuitter,"clicked", G_CALLBACK(gtk_main_quit),NULL);
g_signal_connect((gpointer)pBrowse, "clicked", G_CALLBACK(OnButton),NULL);
g_signal_connect((gpointer)pWindow, "destroy", G_CALLBACK(gtk_main_quit), NULL);
/*////////////////////////////////////////////////////////////////////////////*/
// Ajoute la box pricinpale contenant les objets au container
gtk_container_add((GtkContainer*)pWindow, vbox);
gtk_widget_show_all(pWindow);
gtk_main();
return EXIT_SUCCESS;
}
=> Mes fonctions
#include "_Lib.h"
#include <stdlib.h>
#include <gtk/gtk.h>
#include <windows.h>
/*
void Splash()
{
GtkWidget *pSplash; // SplashScreen
GtkWidget *pWindow2; // Fenêtre pour le SplashScreen
GtkWidget *pBuSplash; // Bouton pour le Splash
int i;
pWindow2 = gtk_window_new(GTK_WINDOW_POPUP);
pSplash = gtk_image_new_from_file("Splash-GNOME2-Pill.png");
pBuSplash = gtk_button_new();
gtk_window_set_position((GtkWindow*)pWindow2, GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(pWindow2),"Bienvenue !!!");
gtk_window_set_modal ((GtkWindow *)pWindow2, TRUE);
gtk_container_add((GtkContainer*)pBuSplash, pSplash);
gtk_container_add((GtkContainer*)pWindow2, pBuSplash);
g_signal_connect((gpointer)pBuSplash, "clicked", GTK_SIGNAL_FUNC(gtk_widget_destroy),pWindow2);
gtk_widget_show_all(pWindow2);
}*/
void parcourir(gchar *FichierChoisi)
{
GtkWidget *pFileSelection;
GtkWidget *pDialog;
gchar *sUtf8;
const gchar *choix;
/* Creation du titre de la fenetre */
sUtf8 = g_locale_to_utf8("Sélectionnez un fichier",-1,NULL, NULL, NULL);
/* Creation de la fenetre de selection */
pFileSelection = gtk_file_selection_new(sUtf8);
/* On limite les actions a cette fenetre */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
/* Liberation memoire */
g_free(sUtf8);
sUtf8 = NULL;
/* Affichage fenetre */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection)))
{
case GTK_RESPONSE_OK:
/* Recuperation du chemin */
choix = gtk_file_selection_get_filename(GTK_FILE_SELECTION(pFileSelection));
strcpy(FichierChoisi,choix);
break;
default:
FichierChoisi = NULL;
break;
}
gtk_widget_destroy(pFileSelection);
}
void OnButton(GtkWidget *pWidget)
{
gchar tmp[1024];
parcourir((gchar*)&tmp);
gdk_pixbuf_new_from_file (tmp, NULL);
}