GNOME Bugzilla – Bug 639945
Gtk.Widget does not have drag_* methods (but in pygtk it did)
Last modified: 2015-02-07 16:56:24 UTC
None of the drag_* methods are available on Gtk.Widget. Instead they are static methods which take a widget as the first parameter. For example in pygtk: mywidget.drag_dest_set(...) Currently in GI PyGObject: Gtk.drag_dest_set(mywidget, ...) An override for these drag_* methods should be created so they are available on the Gtk.Widget instance.
Created attachment 178721 [details] [review] [GI] Add Gtk.drag_* functions as methods on Gtk.Widget override (for compatibility with pygtk). For example: Gtk.drag_source_set(mywidget, ...) now becomes mywidget.drag_source_set(...). This is closer to the old pygtk api.
Hmm, if g-i had a (method) annotation, this would get fixed for all bindings without having to do overrides. This is related to https://bugzilla.gnome.org/show_bug.cgi?id=561264
Yes, (method) would be the preferred way to fix this. If that happens I can change the patch because my patch also includes a test for these methods.
This should really be fixed in the typelib, so all bindings benefit.
Created attachment 178972 [details] [review] Add (method) overrides So methods such as gtk_drag_dest_set() can be put inside Gtk.Widget
Review of attachment 178972 [details] [review]: ::: giscanner/maintransformer.py @@ +948,2 @@ target.methods.append(func) + While I know there's some duplicate code, I think it's weird to have the handling for when we *know* a function is already a method be handled in _pair_method, especially because at that point we will have already e.g. tried to call _pair_constructor(). I think this would be better to do like: def _pair_function(): if is_method: _set_up_stuff_for_method() else _pair_constructor() _pair_function() _pair_static() And in _pair_function() call the common _set_up_stuff_for_method() which basically does: func.instance_parameter = func.parameters.pop(0) subsym_idx = func.symbol.find(subsymbol) self._namespace.float(func) func.name = func.symbol[(subsym_idx + len(uscored_prefix) + 1):] target.methods.append(func)
Created attachment 179501 [details] [review] Add (method) overrides So methods such as gtk_drag_dest_set() can be put inside Gtk.Widget Split setting up the method and getting the uscored_prefix to separate functions.
Review of attachment 179501 [details] [review]: This looks OK, I guess my concern here is it feels like a one-off for the legacy gtkdrag.h stuff. But OK, better than the alternative.
Attachment 179501 [details] pushed as 09bca85 - Add (method) overrides
Now that the g-i fix has landed (thanks Tomeu!) I fixed the overrides in GTK: http://git.gnome.org/browse/gtk+/commit/?id=1bd36ce72365408ed768ba2d4ec50edd9321283f
I've added the (method) attribute for a few drag_* functions Martin missed, as well as gtk_grab_add() and gtk_grab_remove(). http://git.gnome.org/browse/gtk+/commit/?id=295c2fe8d157d67e390fa3819856c7d2d4c4e7a1 http://git.gnome.org/browse/gtk+/commit/?id=395b13bbcef1e4b9cda2fb2c3883998f6457ea66
Now that all methods are annotated as such, I have committed the tests for pygobject introspection from my original patch on this bug. It checks that all the drag_* methods exist on Gtk widgets and are callable. http://git.gnome.org/browse/pygobject/commit/?id=2660be1f227be7a53092483bc9d8ead1bd1fb266
[Mass-moving gobject-introspection tickets to its own Bugzilla product - see bug 708029. Mass-filter your bugmail for this message: introspection20150207 ]