GNOME Bugzilla – Bug 735693
Use introspection annotations for type hints to GObject.Object.emit()
Last modified: 2018-01-10 20:45:48 UTC
Signal emission doesn't make use of introspection which can cause problems for aliased types. For example Gtk.Overlay:get-child-position annotates the allocation argument as CairoRectangleInt, but the signals meta-data says it is a GdkRectangle. These are GdkRectangle is a typedef of CairoRectangleInt but has a unique GType, see bug 683463. The problem is we cannot construct a Gdk.Rectangle() and pass it as an argument to emit() without getting a type conversion error: >>> from gi.repository import GObject, Gtk, Gdk >>> overlay = Gtk.Overlay() >>> allocation = Gdk.Rectangle() >>> overlay.emit('get-child-position', None, allocation) TypeError: could not convert type RectangleInt to GdkRectangle required for parameter 1 Note that Gdk.Rectangle is just really a cairo rectangle: >>> Gdk.Rectangle gi.repository.cairo.RectangleInt A hacky workaround is to sub-class Gdk.Rectangle and set the gtype explicitly: class MyRect(Gdk.Rectangle): __gtype__ = GObject.type_from_name('GdkRectangle')
We also need to take into account output arguments which should be returned from emit(). See also bug 644927.
Is there a plan create a more permanent solution for this? This is a huge issue still when porting from pygtk. I spent hours trying to resolve this issue prior to finding the hacky workaround shown above.
So after looking at this further, I don't think this is still an issue. I recommend closing.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/82.