On Wed, Sep 12, 2007 at 01:52:43PM -0700, tsaud wrote:
> 
> I have created an image from a file using 
> image1 = gtk_image_new_from_file("pictures/Empty.gif");
> gtk_widget_set_name (image1, "image1");
> 
> and displalyed it using:
> gtk_widget_show(image1);
> gtk_box_pack_start(GTK_BOX (hbox1), image1, TRUE, TRUE, 0);
> 
> and that works fine.  The image is correctly displayed where I want it. 
> Later, when a particular event happens (right now I have assigned it to a
> button press), I want to change the image to the image in the file
> "pictures/Full.gif" (which is exactly the same size as Empty.gif).  To do
> that, I did the following:
> 
> void on_button1_pressed (GtkButton *button, gpointer user_data)
> {
>    GtkWidget *imageptr;
>    imageptr = lookup_widget(GTK_WIDGET(button), "image1");
>    if(imageptr != NULL)
>    {
>       gtk_image_set_from_file(GTK_IMAGE(imageptr), "pictures/Full.gif");
>    }
>    else
>       fprintf(stderr, "image1 not found\n");
> }
> 
> When I press the button, the image is replaced by a broken image icon, not
> the new image.  What am I doing wrong?  I am obviously getting the correct
> widget with the lookup_widget call, since the image changed.  The file
> "Empty.gif" and the file "Full.gif" are in the same directory, and when I
> change the gtk_image_new_from_file() call to load the "Full.gif" file, that
> works fine as well, so I know the file is there and readable.  I just don't
> understand why it didn't change to the new image.

Can't the working directory change meanwhile?  Paths such as
"pictures/Full.gif" seem quite fragile to me.

1) Try g_file_test() to check whether "pictures/Full.gif"
   exists as the time on_button1_pressed() is called.
2) Try to load the image with gdk_pixbuf_load() and look at
   the error your obtain.

Yeti

--
http://gwyddion.net/
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to