[Glade-users] libglade2 problem, how to make a signal handler refer to another widget?!



Hi everybody. I am starting to learn programming a while ago. I can make
some simple programs using Glade2 with build in build option, but now i
have made te switch to the libglade method. 
I use libglade2-0 (version 1:2.5.1) and i can compile a simple UI using
this command:

        cc -o testprogram gl3test.c `pkg-config --cflags --libs
        libglade-2.0` -export-dynamic

at the end of this mail you can find my code for gl3test.c and
gl3test.glade

A signal handler like this works perfect:

        void
        on_button1_clicked                    (GtkButton       *button,
                                                gpointer
                user_data)
        {
        gtk_main_quit();
        }
        
Though I want to change te text of a label (called 'label1' in my UI)
when clicking button1. The problem is i can't get this to work. With
glade2 the correct code was (when entered in callsback.c):

        void
        on_button1_clicked                    (GtkButton       *button,
                                                gpointer       user_data)
        {
        GtkWidget * label = lookup_widget(GTK_WIDGET(button), "label1");
        gtk_label_set_text(GTK_LABEL(label),"This text will be set when
        button1 is clicked");
        }
        
I have tried all kinds off variants on this but none of them worked.
Hopefully one of you can help me with this because I spent a whole day
on it so far with still no success.
Beneath the code of gl3test.c and gl3test.glade

gl3test.c:

        #include <stdio.h>
        #include <gtk/gtk.h>
        #include <glade/glade.h>
        
        void
        on_button1_clicked                    (GtkButton       *button,
                                                gpointer
        user_data)
        {
        gtk_main_quit();
        }
        
        int main(int argc, char *argv[]) {
            GladeXML *xml;
        
            gtk_init(&argc, &argv);
        
            /* load the interface */
            xml = glade_xml_new("gl3test.glade", NULL, NULL);
        
            /* connect the signals in the interface */
            glade_xml_signal_autoconnect(xml);
        
            /* start the event loop */
            gtk_main();
        
            return 0;
        }




gl3test.glade:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE glade-interface SYSTEM "glade-2.0.dtd">
<!--Generated with glade3 3.0.3 on Mon Dec 25 22:08:52 2006 by
koen at koen-desktop-->
<glade-interface>
  <widget class="GtkWindow" id="window1">
    <property name="width_request">200</property>
    <property name="height_request">599</property>
    <property name="visible">True</property>
    <property name="can_focus">True</property>
    <property name="can_default">True</property>
    <property name="title" translatable="yes">testje</property>
    <property name="window_position">GTK_WIN_POS_CENTER</property>
    <property name="default_width">199</property>
    <property name="default_height">600</property>
    <property name="icon">itunes-blue150.jpg</property>
    <child>
      <widget class="GtkVBox" id="vbox1">
        <property name="visible">True</property>
        <child>
          <widget class="GtkHScale" id="hscale1">
            <property name="visible">True</property>
            <property name="adjustment">2 0 10 1 0 0</property>
            <property name="value_pos">GTK_POS_LEFT</property>
          </widget>
        </child>
        <child>
          <widget class="GtkButton" id="button1">
            <property name="visible">True</property>
            <property name="label" translatable="yes">button</property>
            <signal name="clicked" handler="on_button1_clicked"/>
          </widget>
          <packing>
            <property name="position">1</property>
          </packing>
        </child>
        <child>
          <widget class="GtkLabel" id="label1">
            <property name="visible">True</property>
            <property name="label" translatable="yes">tekst</property>
          </widget>
          <packing>
            <property name="position">2</property>
          </packing>
        </child>
      </widget>
    </child>
  </widget>
</glade-interface>

        








[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]