GNOME Bugzilla – Bug 707140
3.9.x regression
Last modified: 2013-09-02 05:04:27 UTC
The following used to work in 3.8, doesn't anymore with trunk. Removing the __gsignals__ fixes it. __gsignals__ is left over from pygtk and afaik isn't needed anymore I guess (was that always the case in pygi?) It's only bad because it breaks code that used to work. ############################################### from gi.repository import Gtk class Foo(Gtk.ScrolledWindow): __gsignals__ = {'size-allocate': 'override'} def do_size_allocate(self, alloc): print alloc return Gtk.ScrolledWindow.do_size_allocate(self, alloc) win = Gtk.Window() win.connect("delete-event", Gtk.main_quit) foo = Foo() win.add(foo) win.show_all() Gtk.main()
Using __gsignals__ is not (yet) deprecated and should work for the whole 3.x series. The decorator technique actually relies on it. The following is printed for me when running the example: <GdkRectangle at 0x7fff74211d40> Traceback (most recent call last):
+ Trace 232439
return Gtk.ScrolledWindow.do_size_allocate(self, alloc)
Things are a bit confusing because "size_allocate" is both a signal and a vfunc. PyGObject seems to use the "do_" prefix for both signal overrides and vfuncs. I didn't look into this too deeply and the actual problem is still unclear. Some basic investigation: if you connect a discreet "size-allocate' signal and print the alloc argument, it will show up as a cairo.RectangleInt, whereas I'm pretty sure the vfunc override will print as a GdkRectangle/GtkAllocation (all of these are typedefs of cairo.RectangleInt, so it is also possible something is broken with annotations).
Additional debugging info when printing with: print(alloc, alloc.__gtype__) signal override: <GdkRectangle at ...> <GType CairoRectangleInt (38811360)> signal handler: <CairoRectangleInt at ...> <GType CairoRectangleInt (38811360)> vfunc override: <CairoRectangleInt at ...> <GType CairoRectangleInt (38811360)> This shows we are at least getting the correct gtype (CairoRectangleInt) in the various cases. It looks like marshaling refactoring work probably broke this by becoming a bit stricter.
The stricter type checking was initially added with: https://git.gnome.org/browse/pygobject/commit/?id=635a7d1b This made its way into marshaling unification with: https://git.gnome.org/browse/pygobject/commit/?id=6d3a0751
The root cause of this seems to be a type discrepancy due to gtk_widget_size_allocate (and its vfunc) defined as using GtkAllocation: https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?id=3.8.4#n5206 And the signals argument type is defined using GDK_TYPE_RECTANGLE: https://git.gnome.org/browse/gtk+/tree/gtk/gtkwidget.c?id=3.8.4#n1597 This is described in bug #683463 We seem to be getting the same gtype back for signal overrides as vfunc so it is still not clear as to why this is failing.
Created attachment 253802 [details] [review] Change boxed type checking in marshaling to use __gtype__ attribute Replace usage of pyg_boxed_check(pyboxed) with g_type_is_a and pyg_type_from_object. This has the effect of using the __gtype__ attribute stashed on object class instead of the PyGBoxed internally held gtype. This fixes type descrepencies for objects marshaled into overridden signal class closures and passed back to functions taking an alias their type.
Comment on attachment 253802 [details] [review] Change boxed type checking in marshaling to use __gtype__ attribute Thanks!
Attachment 253802 [details] pushed as 19c1a2d - Change boxed type checking in marshaling to use __gtype__ attribute