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 644729 - Support Gtk.Window.set_user_data
Support Gtk.Window.set_user_data
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: introspection
unspecified
Other All
: High major
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on: 644736
Blocks:
 
 
Reported: 2011-03-14 14:20 UTC by Johan (not receiving bugmail) Dahlin
Modified: 2013-02-08 05:35 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Johan (not receiving bugmail) Dahlin 2011-03-14 14:20:52 UTC
Gdk.Window.set_user_data should be supported from introspection. It is needed to subclass
a widget.

The tricky part is that it uses a gpointer argument instead of a GtkWidget. An type override annotation would potentially solve it, but it can't be GtkWidget, it has to be marked as a base class such as GObject.
Assuming we can't add an annotation, the way to do it is to essentially copy the static binding part from gdkwindow.override in PyGTK, if the argument is of PyGObject_Type, get out the GObject pointer from the wrapper and send it to the function, however this shouldn't be done generically as gpointer functions shouldn't be supported from introspection.

J5 proposed that we'd create a special object, that converts a pointer to a PyGObject, like a cast, that would be private and only used in the override:

  def set_user_data(self, widget):
     pointer =  gi._private_cast(widget, G_TYPE_POINTER)
     Gdk.Window.set_user_data(self, pointer)

I would prefer the annotation version though. which would just be @user_data: (type GObject):
Comment 1 johnp 2011-03-14 15:39:00 UTC
As discussed on irc, the best plan is to create a method for GtkWidget tentatively called gtk_widget_own_window.

We would also create a private method in Gdk called gdk_window_set_owner_widget_libgtk_only which takes a GObject and is called by gtk_widget_own_window.

gdk_window_set_user_data will be deprecated and will simply call gdk_window_set_owner_widget_libgtk_only internally.

This should clean up the C code a bit without breaking ABI and also make it wrappable by GI making things like prototyping offscreen window effects possible from PyGObject.
Comment 2 Johan (not receiving bugmail) Dahlin 2011-03-14 15:45:06 UTC
The most important use case for the python side is the ability to subclass widgets.
Comment 3 johnp 2011-07-05 15:58:25 UTC
I'll have to ping Mathias again.  He didn't like the idea of renaming the last time I brought it up to him.
Comment 4 Simon Feltman 2013-02-08 05:35:19 UTC
We ended up adding a __gpointer__ property to the PyGObject class. This returns a PyCObject or PyCapsule depending on Python version. Marshaling of pointers also support this so the support on the override side of things is now in.

However, I just noticed gdk_window_set_user_data is being deprecated and there is already a new method in place for doing this:

Gtk.Widget.register_window(self, window:Gdk.Window)
Gtk.Widget.unregister_window(self, window:Gdk.Window)

Check here for details:
https://bugzilla.gnome.org/show_bug.cgi?id=687842#c17