[Glade-users] Unable to automatically connect signal handlers with integer arguments



Dear all,

I am using glade 3.6 with the GtkBuilder format and I wanted to try a
simple case in which two widgets share the same handler functions for a
signal name but use different user data.

A simple example is two ToggleButtons with the same "toggled" handler
and passing a different integer number as user argument.

The GtkBuilder XML [1] has the following relevant information

 <object class="GtkToggleButton" id="tbutton1">
     <signal name="toggled" handler="toggled_cb" object="arg1"/>
 </object>

 <object class="GtkToggleButton" id="tbutton2">
    <signal name="toggled" handler="toggled_cb" object="arg2"/>
 </object>

On the Python code [2] I have the following lines in the class
constructor:

    def __init__(self):
        self.arg1 = 1
        self.arg2 = 2

        self.builder = gtk.Builder()
        self.builder.add_from_file("togglebutton_gtkbuilder.glade")

        missing = self.builder.connect_signals(self)
        assert missing == None

and the callback is as follows:

    def toggled_cb(self, widget, data):
        if data == "1":
            print "Button1 pressed"
        elif data == "2":
            print "Button2 pressed"

The problem is that the connect_signals() methods gives me the error:

    GtkWarning: Could not lookup object arg1 on signal toggled of object
    tbutton1

and when I clicked on the button it seems that the argument is not
passed to the callback:

    TypeError: toggled_cb() takes exactly 3 arguments (2 given)

Some google research has made me believe that the argument value should
be a GObject instance some how but I tried to create a GObject instance
with:

        gobject.new(gobject.TYPE_INT)

  without any success neither.

My questions:

A)  Is there a way to define a GTK_VALUE as a user arg from the
    GtkBuilder XML?

B)  Is there a way to build a GOBJECT explicitely in PyGTK that
    could be referenced as the argument value of glade-3 signal
    handlers?

So far it seems that any handler with a user data needs to be connected
manually (getting the object with get_object() and invoking the
connect() method).

Thanks in advance for any help.

        Miguel


[1] http://pastebin.com/d51347024 (with 24h life)
[2] http://pastebin.com/d14244161 (with 24h life)

-- 

      (O-O)
---oOO-(_)-OOo-----------------------------------------------------
 Miguel TELLERIA DE ESTEBAN               http://www.mtelleria.com
 Email: miguel at mtelleria.com           Tel GSM:  +34 650 801098
                                          Tel Fix:  +34 942 280174

 Miembro de http://www.linuca.org    Membre du http://www.bxlug.be
 ?Usuario captivo o libre?    http://www.obtengalinux.org/windows/
 Free or  captive user?        http://www.getgnulinux.org/windows/
-------------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/glade-users/attachments/20090916/85c876ac/attachment.bin 




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