GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Jul 24, 2014 6:25 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: How to access two GTK+ widgets from a single callback
PostPosted: Thu May 15, 2008 9:14 pm 
Offline

Joined: Thu May 15, 2008 8:11 pm
Posts: 3
I hope the code below may be useful to some people.
This method works, but I am new to GTK+ myself so I am not sure whether this is the best solution, however, but I believe it is one of the better ones. I would be interested to know if someone has a better way of achieving this :-)
Other solutions would be to use globals or possibly structs.

What the function does:
It is a simple callback function that has been connected to the GladeXML file by the following line:
Code:
glade_xml_signal_connect(gxml, "on_execute_recording_button_clicked", G_CALLBACK(on_execute_recording_button_clicked));

where gxml is the main GladeXML file that was created using Glade-3.

Using glade_get_widget_tree() we can get hold of the GladeXML file inside the callback function without using globals. From there is it easy, we simply use the glade_xml_get_widget() function to get hold of the widgets we want. In my case this is a GtkProgessBar widget and a GtkTreeView widget. Both widgets are then passed to a get_data() function that manipulates them.

Here is my code:
Code:
/*
* Function aquires a handle on the GtkProgressBar and the GtkTreeView widget
* then calls a function that works on both widgets.
*
*/
void on_execute_recording_button_clicked  (GtkButton *button, GtkWidget *window, gpointer gptr)
{
   GladeXML *gxml;
   GtkWidget  *pbarWidget, *data_viewWidget;
   GtkProgressBar *pbar;
   GtkTreeView *data_view;

   gxml = glade_get_widget_tree(GTK_WIDGET(button));

   pbarWidget = glade_xml_get_widget (gxml, "record_progressbar");
   pbar =  GTK_PROGRESS_BAR(pbarWidget);

   data_viewWidget = glade_xml_get_widget (gxml, "data_view");
   data_view = GTK_TREE_VIEW(data_viewWidget);

   get_data(pbar, data_view);
}


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 3 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