GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to access two GTK+ widgets from a single callback

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
tak



Joined: 15 May 2008
Posts: 3

PostPosted: Thu May 15, 2008 9:14 pm    Post subject: How to access two GTK+ widgets from a single callback Reply with quote

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: (C)
1
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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

/*
 * 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);
}
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP