GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Oct 31, 2014 10:45 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to connect an IMAGE with a MOUSE CLICK event/signal?
PostPosted: Wed Jan 04, 2012 6:47 pm 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
Hello All,

I will be more than grateful if you could find time for answering me.

General:
I am writing a GUI, in which I receive real time video from several cameras of a robot (using ROS).

Hierarchy:
GtkWidget ---points to---> GtkPixbuf ---points to---> IplImage (for each frame of the video).

Goal:
Connect the widget that holds the image to signal/event of a mouse clicking, in order to perform some operations (resizing on click).

I have tried to do it in this way:
Code:
// Connecting the created widget to a "button_press_event".
g_signal_connect_after ( G_OBJECT(pToImageManagmentStruct->pGtkImgWindow),
                         "button_press_event",
                         G_CALLBACK(callbackForImageResizing),
                         NULL
                        );

void  callbackForImageResizing ( GtkWidget* imageWidget, gpointer dataForCallback )
{
    // The needed code
}

But this is not working.

Possible solution:
I have found this link: http://justlinux.com/forum/showthread.php?t=132908.
But:
a. I am not sure that this is the right way.
b. This will also require a change in my working code, which is not wanted.
c. This is a very old link.

Questions:
1. How should I achieve my goal?
2. What is the difference between an event and a signal? What is the right way in my case?
3. Maybe I should use "gtk_widget_add_events" or "gtk_widget_set_events"?

Thank you all in advance,
Felix.


Top
 Profile  
 
 Post subject: Re: How to connect an IMAGE with a MOUSE CLICK event/signal?
PostPosted: Thu Jan 05, 2012 9:05 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 768
Location: UK
Hi,

The information in the link you gave is still valid. GtkImage is unable to handle events (mouse movement, keyboard or mouse button presses etc.) without the help of GtkEventBox.

Have a look at the two GTK manual pages for GtkImage, which also gives an example and GtkEvent, which really is just a container to assist with event handling.

http://developer.gnome.org/gtk3/stable/GtkImage.html
http://developer.gnome.org/gtk3/stable/GtkEventBox.html

So to answer your questions

- You will need to GtkEventBox like in the example you gave a link to. I am sure the extra code will not be too much of a problem and you can still carry on using the GtkImage as usual in the rest of your application. You will only need to use the GtkEventBox to handle the events for the image and I am sure you could pass a pointer to GtkImage to the signal handler for the event.

- You will still need to use "gtk_widget_add_events" or "get_widget_set_events" depending on if the widget has been realised on not, to say what events are to be handled but you can not use it of GtkImage as it can not handle events. In your case you will use these functions on GtkEventBox.

- My way of think of the difference between events and signals is events are real world things such as mouse position, buttons presses etc. and signals are software glue that says something has happened and if something is connected to it a handler can then do something with the information.

_________________
E.


Top
 Profile  
 
 Post subject: Re: How to connect an IMAGE with a MOUSE CLICK event/signal?
PostPosted: Thu Jan 05, 2012 11:27 am 
Offline
Familiar Face

Joined: Mon Oct 17, 2011 10:18 am
Posts: 26
Dear Errol,

I am grateful for your professional answer and the time you have spent to write it. I really appreciate your help, and I will definitely use your advice.

Best,
Felix.


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