Re: some erros -- resolved
- From: James Scott Jr <skoona verizon net>
- To: frederico schardong <frede sch gmail com>
- Cc: gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: Re: some erros -- resolved
- Date: Sun, 18 Jan 2009 23:06:29 -0500
Frederico,
Your CCLIST dropped the reference to gtk-app-devel-list gnome org
Which will certaily impact who can respond.
Here is your example you asked for.
Regards,
James Scott, Jr.
Registered Linux User #270764
/* Sampler.c */
#include <gtk/gtk.h>
static gchar* fn_get_file (GtkWindow *parent, gchar
**filter_string_array)
{
GtkWidget *chooser = NULL;
gchar *fname = NULL;
gint index = 0;
/*
* Create the Chooser Dialog
*/
chooser = GTK_WIDGET (gtk_file_chooser_dialog_new ("Open File",
parent,
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
NULL));
/*
* Populate and add filter to dialog, dialog owns them afterwards
*/
for (index = 0; filter_string_array[index] != NULL; index++) {
GtkFileFilter *filtro = NULL;
gchar pattn[32];
filtro = gtk_file_filter_new();
g_snprintf (pattn, sizeof(pattn), "*.%s",
filter_string_array[index]);
gtk_file_filter_add_pattern(filtro, pattn);
gtk_file_filter_set_name(filtro, filter_string_array[index]);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER(chooser), filtro);
}
/*
* Show and Run the dialog
*/
gtk_widget_show(chooser);
if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT)
{
fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (chooser));
}
gtk_widget_destroy (chooser);
return fname;
}
static void cb_get_file (GtkWidget *button, GtkWidget *label)
{
GtkWindow *window = NULL;
gchar *sz_filename = NULL;
gchar **sz_a_filters = NULL;
g_return_if_fail (label != NULL);
sz_a_filters = (gchar **)g_object_get_data(G_OBJECT(button),
"FILE_FILTERS");
window = (GtkWindow *)gtk_widget_get_ancestor (button,
GTK_TYPE_WINDOW);
if (window != NULL) {
sz_filename = fn_get_file (GTK_WINDOW(window), sz_a_filters);
if (sz_filename != NULL) {
gtk_label_set_text(GTK_LABEL(label), sz_filename);
g_free(sz_filename);
}
}
}
int main (int argc, char *argv[])
{
GtkWidget *window = NULL;
GtkWidget *vbox = NULL;
GtkWidget *button = NULL;
GtkWidget *label = NULL;
gchar *sz_a_filters[] = { "c", "bmp", "png", "jpg", NULL};
gtk_init (&argc, &argv);
/* create window, etc */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Quick Sample");
gtk_container_set_border_width (GTK_CONTAINER (window), 5);
gtk_window_set_default_size (GTK_WINDOW (window), 320, 200);
g_signal_connect (G_OBJECT (window), "destroy",
G_CALLBACK (gtk_main_quit), NULL);
vbox = gtk_vbox_new (FALSE, 5);
gtk_container_add (GTK_CONTAINER (window), vbox);
label = gtk_label_new ("gFileChooser");
gtk_box_pack_start (GTK_BOX (vbox),
label,
FALSE, FALSE, 0);
button = gtk_button_new_with_label ("Open a File");
g_object_set_data(G_OBJECT(button), "FILE_FILTERS",
sz_a_filters);
g_signal_connect (button, "clicked", G_CALLBACK (cb_get_file),
label);
gtk_box_pack_start (GTK_BOX (vbox), button, TRUE, TRUE, 0);
gtk_widget_show_all (window);
gtk_main();
return 0;
}
END CODE
On Sat, 2009-01-17 at 11:26 -0200, frederico schardong wrote:
please, help me
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]