GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Sep 30, 2014 1:53 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Displaying an image in GtkImage widget
PostPosted: Sun Mar 04, 2007 9:12 pm 
Offline
Familiar Face

Joined: Sun Mar 04, 2007 8:25 pm
Posts: 19
Hi all,

I'm a novice in gtk+ programming; I should actually use it for doing a project. My project is based on ARToolKit which is a library for building Augmented Reality (AR) applications. In short, AR is the superimposition of virtual imagery on the real world. More information on ARToolKit can be found @ http://www.hitl.washington.edu/artoolkit/. So, I have to use GTK+ as interface tool and obviously integrate the interface with ARToolKit....something really unclear to me up till now :shock:. I'll be glad if somebody could comment on this as well.

Something I want to do is to display an image in a GtkImage widget after choosing which image to display via a combo box. For testing purposes, I've used a button (i.e. click on the button & display the image).

I'm trying the following code (on the button - onclick event), but it doesn't work :( :

Code:
GtkWidget *img_objectdesign;
img_objectdesign = gtk_image_new_from_file ("filename.jpg");
gtk_widget_show(img_objectdesign);


I use Glade to design the interface and I work on Windows.

Actually I obtained the following code on the web, so I modified it as above because on the interface window I put a GtkImage widget named as "img_objectdesign":

Code:
GtkWidget *image;
image = gtk_image_new_from_file ("filename.jpg");
gtk_widget_show(image);


I don't know if I'm doing the right thing or if something is missing, but one thing is for sure is that nothing's happening!! I click on the button and no image is displayed. :(

Can't understand something: I used Glade to make the interface, hence it generated some code automatically (creates callbacks.c, interface.c, etc). In Glade you can name your widgets. My question is that can you access a widget directly in your gtk+ code??

I mean can I put something like

Code:
img_objectdesign = gtk_image_new_from_file ("filename.jpg");


directly (on a button event)?? ...and bearing to the fact that I named the GtkImage widget as "img_objectdesign" in Glade. But in doing so, I obtain compilation errors!! :(

So how do I use the widgets (name) directly in the gtk+ code??

I know I'm asking a lot of questions, but I hope you understand that I'm a beginner and many things are unclear to me unfortunately. :(
I don't even know if I'm formulating my questions well or if the questions are really questions? :?

Furthermore I'm really behind schedule in my project. Please help! :idea:


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 9:09 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Quote:
I don't know if I'm doing the right thing or if something is missing, but one thing is for sure is that nothing's happening!! I click on the button and no image is displayed.


Your code to create an image is alright, but it wasn't added to any container. So it doesn't exist anywhere visually. And, since your image is defined in the glade file, you don't want to create a *new* GtkImage but instead set the image of that existing reference to a GtkImage.

Quote:
Can't understand something: I used Glade to make the interface, hence it generated some code automatically (creates callbacks.c, interface.c, etc). In Glade you can name your widgets. My question is that can you access a widget directly in your gtk+ code??


I see by your more recent post, that you have partially figured this out. However, I must point out that the code generation with Glade is deprecated and in Glade3, libglade is the supported method. Something you might want to read up on.

Personally, I'm using Linux and thus cannot be much help for things specific to Windows, but will try to help you as much as possible. If you'd like to post/send your complete little test application, I'll take a look and fix it for you.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 06, 2007 11:31 pm 
Offline
Familiar Face

Joined: Sun Mar 04, 2007 8:25 pm
Posts: 19
Thank you for your help.

I'll post my application as it progresses.

In fact, the problem was how to reference widgets. I had a look at interface.c and saw the following line:
Code:
/* Store pointers to all widgets, for use by lookup_widget(). */


So I pointed out that the lookup_widget() function was the key to access widgets.

So can I conclude that every widget is accessible via lookup_widget()??

I've used it but I don't really understand the parameter passing :(. I don't think I've mastered it and it would be nice if you could explain it to me and perhaps the concept of container as well. I feel it's important because of course I've got to have control over all the widgets.
:)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group