After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 672864 - Can not listen to signals in subclassed subclasses
Can not listen to signals in subclassed subclasses
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
3.2.x
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2012-03-26 18:08 UTC by Simon Schampijer
Modified: 2012-06-01 09:59 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
fix vfunc lookup with intermediate subclasses (1.42 KB, patch)
2012-05-14 13:35 UTC, Carlos Garnacho
none Details | Review

Description Simon Schampijer 2012-03-26 18:08:50 UTC
The following worked in the static GTK+ 2 bindings, only the 'do_clicked' method of SubButton is called:

{{{
import gtk
import gobject

def _destroy_cb(widget, data=None):
    gtk.main_quit()

class Button(gtk.Button):
    __gtype_name__ = 'SugarButton'
    def __init__(self, **kwargs):
	gtk.Button.__init__(self, **kwargs)

    def do_clicked(self):
        print 'Button clicked'

class SubButton(Button):
    __gtype_name__ = 'SugarSubButton'
    def __init__(self, **kwargs):
        Button.__init__(self, **kwargs)

    def do_clicked(self):
	print 'SubButton clicked'

window = gtk.Window()
window.set_default_size(450, 450)
window.connect("destroy", _destroy_cb)

b = SubButton(label='hallo')
window.add(b)
b.show()

window.show()

gtk.main()
}}}

In GTK+3 with the dynamic bindings, the  'do_clicked' method of Button gets called not the overriden one of SubButton.

{{{
from gi.repository import Gtk

def _destroy_cb(widget, data=None):
    Gtk.main_quit()

class Button(Gtk.Button):
    __gtype_name__ = 'SugarButton'
    def __init__(self, **kwargs):
        Gtk.Button.__init__(self, **kwargs)

    def do_clicked(self):
        print 'Button clicked'

class SubButton(Button):
    __gtype_name__ = 'SugarSubButton'
    def __init__(self, **kwargs):
        Button.__init__(self, **kwargs)

    def do_clicked(self):
	print 'SubButton clicked'

window = Gtk.Window()
window.set_default_size(450, 450)
window.connect("destroy", _destroy_cb)

b = SubButton(label='hallo')
window.add(b)
b.show()

window.show()

Gtk.main()
}}}
Comment 1 Simon Schampijer 2012-03-27 11:46:25 UTC
Abother request of the same issue: http://mail.gnome.org/archives/python-hackers-list/2011-December/msg00013.html
Comment 2 Martin Pitt 2012-04-24 13:51:53 UTC
Confirmed with 3.2.
Comment 3 Carlos Garnacho 2012-05-14 13:35:48 UTC
Created attachment 214001 [details] [review]
fix vfunc lookup with intermediate subclasses

This patch fixes the issue, it uses __mro__ to find out the VFuncInfo, as the corresponding attribute is shadowed with the unbounded method in the intermediate python subclass
Comment 4 Simon Schampijer 2012-05-22 15:35:31 UTC
Thanks Carlos for the patch!

Applied here to master and it does reproduce the desired result. The test case from above passes fine.
Comment 5 Martin Pitt 2012-06-01 08:06:19 UTC
Thanks Carlos!

I created a test case for this, and committed it with your patch:

http://git.gnome.org/browse/pygobject/commit/?id=07a08b49aae83a297e2f91240448314e4663f724
Comment 6 Simon Schampijer 2012-06-01 09:59:49 UTC
Thanks Martin, you rock! /me can make another cross on his bug list...