[Glade-users] A concept problem about lookup_widget().

Andreas Volz lists@brachttal.net
Tue, 3 Aug 2004 15:40:07 +0200


Am Tue,  3 Aug 2004 01:27:49 -0400 schrieb SRTsbbg:

>   What I want to ask is that if somehow there is possible way to
>   lookup those entries in
> this handler. Or is there any other solution such as make handler take
> more arguments?...
> 

Hi,

I should work if you connect the toplevel windows with g_object_set_data
and later get the object with gtk_widget_get_toplevel and
g_object_get_data. Here is a small example how to use this commands:

#include <gtk/gtk.h>

void run (GtkWidget *button, gpointer entry)
{
        GtkWidget *window1;
        GtkWidget *window2;

        window1 = gtk_widget_get_toplevel (
                GTK_WIDGET(button));

        window2 = g_object_get_data (G_OBJECT (
                window1),"window2");

        gtk_window_set_title (GTK_WINDOW (window2),
                "Zugriff auf Widget-Pointer");
}

int main( int   argc, char *argv[])
{
        GtkWidget *window1;
        GtkWidget *window2;
        GtkWidget *box;
        GtkWidget *button;

        gtk_init (&argc, &argv);

        window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        window2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);

        g_object_set_data (G_OBJECT (window1),
             "window2", window2);

        g_object_set_data (G_OBJECT (window2),
             "window1", window1);

         /* box2 */
        box = gtk_hbox_new (FALSE, 0);
        gtk_container_add (GTK_CONTAINER (window1), box);

        /* button - run */
        button = gtk_button_new_from_stock (GTK_STOCK_EXECUTE);
        g_signal_connect (G_OBJECT (button), "clicked",
            G_CALLBACK(run), NULL);

        gtk_box_pack_start(GTK_BOX (box), button, TRUE, TRUE, 5);

        gtk_widget_show (box);
        gtk_widget_show (button);
        gtk_widget_show (window1);
        gtk_widget_show (window2);
        gtk_main ();

        return 0;
}

You can combine this with lookup_widget if you need. If you use libglade
to create the GUI there's a easier way to get the widgets.

regards
Andreas