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



   Signals need to be improved with GtkBuilder/Glade, its really not
so much work
when you consider the possible gains, I've outlined a roadmap[0] to get it done,
if anyone thinks this is interesting I'd be happy to lend them a hand
getting it done.

For now user data must be an object, but it must be an object that is defined
in the same xml (GtkBuilder does not know about any symbols you may have
defined outside of the xml), and be careful; when you connect a signal with
an object argument then your signal will be connected with the swap flag,
which means the user data argument will be the _first_ argument.

Cheers,
          -Tristan

http://live.gnome.org/Glade/Roadmap/RealUsableSignals

On Wed, Sep 16, 2009 at 11:23 AM, Miguel Telleria de Esteban
<miguel at mtelleria.com> wrote:
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/
-------------------------------------------------------------------


_______________________________________________
Glade-users maillist ?- ?Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users






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