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 685076 - Add override for Gtk.Container.child_get_property
Add override for Gtk.Container.child_get_property
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: gobject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
: 652941 (view as bug list)
Depends on: 685218
Blocks: 685373
 
 
Reported: 2012-09-28 21:25 UTC by Simon Feltman
Modified: 2014-05-26 06:06 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add an override for Gtk.Container.child_get() (7.85 KB, patch)
2012-10-02 10:17 UTC, Johan (not receiving bugmail) Dahlin
reviewed Details | Review
overrides: Make value argument to Widget.style_get_property optional (3.11 KB, patch)
2014-05-26 05:40 UTC, Simon Feltman
committed Details | Review
overrides: Add Gtk.Container.child_get/set overrides (2.40 KB, patch)
2014-05-26 06:06 UTC, Simon Feltman
committed Details | Review

Description Simon Feltman 2012-09-28 21:25:32 UTC
The child_get_property method is currently not introspectable due to its usage of GValue as an in/out argument. This could be fixed by creating an override which simply re-implements the method using the workaround of "child.get_property".
Comment 1 Johan (not receiving bugmail) Dahlin 2012-10-02 10:17:21 UTC
Created attachment 225569 [details] [review]
Add an override for Gtk.Container.child_get()

As part of that, also add GObject.Value.get() bindings that
will be useful outside of that.
Comment 2 Johan (not receiving bugmail) Dahlin 2012-10-02 10:17:46 UTC
(In reply to comment #1)
> Created an attachment (id=225569) [details] [review]
> Add an override for Gtk.Container.child_get()
> 
> As part of that, also add GObject.Value.get() bindings that
> will be useful outside of that.

This depends on the patches attached to bug 685218
Comment 3 Jose Rostagno 2012-10-02 14:36:32 UTC
from the patch:

+        elif gtype == constants.TYPE_OBJECT:
+            return self.get_object()
+        # TYPE_PYOBJECT
+        elif gtype == constants.TYPE_OBJECT:
+            return self.get_object()

maybe a copy/paste typo?
Comment 4 Simon Feltman 2012-10-02 20:46:17 UTC
Review of attachment 225569 [details] [review]:

Looks good, a few comments.

::: gi/overrides/GObject.py
@@ +81,3 @@
+            raise TypeError("Unsupported GType: %s" % (gtype, ))
+
+__all__.append('Value')

This seems to basically duplicate the code in gi/_gobject/pygtype.c:pyg_value_as_pyobject. It would be great to refactor this and remove the static bindings or somehow share the code, similar to what is noted in: https://bugzilla.gnome.org/show_bug.cgi?id=685275
Minimally a comment should go in both the static binding code and python override referencing a ticket url and description that the code is duplicated so readers and hackers can easily know about it.

::: gi/overrides/Gtk.py
@@ +93,3 @@
+            values.append(value.get(pspec.value_type))
+        return values
+            value = GObject.Value()

It would be nice to override child_get_property and put all the GObject.Value code in there. get_child could then use the overridden version. Passing by reference for out args is just ugly in python and I think we should abstract that whenever possible in pygobject.
Comment 5 Johan (not receiving bugmail) Dahlin 2012-10-03 09:47:03 UTC
(In reply to comment #3)
> from the patch:
> 
> +        elif gtype == constants.TYPE_OBJECT:
> +            return self.get_object()
> +        # TYPE_PYOBJECT
> +        elif gtype == constants.TYPE_OBJECT:
> +            return self.get_object()
> 
> maybe a copy/paste typo?

Yeah, good catch. Thanks.

(In reply to comment #4)
> Review of attachment 225569 [details] [review]:
> 
> Looks good, a few comments.
> 
> ::: gi/overrides/GObject.py
> @@ +81,3 @@
> +            raise TypeError("Unsupported GType: %s" % (gtype, ))
> +
> +__all__.append('Value')
> 
> This seems to basically duplicate the code in
> gi/_gobject/pygtype.c:pyg_value_as_pyobject. It would be great to refactor this
> and remove the static bindings or somehow share the code, similar to what is
> noted in: https://bugzilla.gnome.org/show_bug.cgi?id=685275
> Minimally a comment should go in both the static binding code and python
> override referencing a ticket url and description that the code is duplicated
> so readers and hackers can easily know about it.

Agree. I think that most of the static bindings should be removed in the long run. It'll help on many levels, easier to contribute, debug, understand, run under other python implementations just to mention a few. However, it's actually quite a bit of work, and sometimes there needs to be help in glib with updated annotations, api etc.

Meanwhile while we do this migration, I don't think it's necessarily a bad thing to do keep two implementations of the same. Would it suffice to add a FIXME/TODO to the C static version saying that the python-only version should be preferred?

> ::: gi/overrides/Gtk.py
> @@ +93,3 @@
> +            values.append(value.get(pspec.value_type))
> +        return values
> +            value = GObject.Value()
> 
> It would be nice to override child_get_property and put all the GObject.Value
> code in there. get_child could then use the overridden version. Passing by
> reference for out args is just ugly in python and I think we should abstract
> that whenever possible in pygobject.

Yeah, I guess you're right. It's just that  child_get_property() were never available inside PyGTK, but in the new introspection world it makes sense to implement both and make child_get() return a list.
Comment 6 Simon Feltman 2012-10-03 10:42:56 UTC
(In reply to comment #5)
> > ::: gi/overrides/GObject.py
> > @@ +81,3 @@
> > +            raise TypeError("Unsupported GType: %s" % (gtype, ))
> > +
> > +__all__.append('Value')
> > 
> > This seems to basically duplicate the code in
> > gi/_gobject/pygtype.c:pyg_value_as_pyobject. It would be great to refactor this
> > and remove the static bindings or somehow share the code, similar to what is
> > noted in: https://bugzilla.gnome.org/show_bug.cgi?id=685275
> > Minimally a comment should go in both the static binding code and python
> > override referencing a ticket url and description that the code is duplicated
> > so readers and hackers can easily know about it.
> 
> Agree. I think that most of the static bindings should be removed in the long
> run. It'll help on many levels, easier to contribute, debug, understand, run
> under other python implementations just to mention a few. However, it's
> actually quite a bit of work, and sometimes there needs to be help in glib with
> updated annotations, api etc.
I am just now starting to grasp the basics of how all this fits together and it has been many months of hacking. I think piecemeal refactoring is the right approach if possible to accomplish what you mention. And yes it will be easier to contribute, maintain, etc... For instance, I added the "freeze_notify" context managers in the C bindings. This could have been done in literally a few lines of python but it ended up being a nice chunk of hand crafted C code.

I created a meta ticket for tracking work related to removal of the static bindings. It would be great to hear more of your insight and ideas for how to approach some of this as I would like to contribute to the effort.
https://bugzilla.gnome.org/show_bug.cgi?id=685373

> Meanwhile while we do this migration, I don't think it's necessarily a bad
> thing to do keep two implementations of the same. Would it suffice to add a
> FIXME/TODO to the C static version saying that the python-only version should
> be preferred?
Agreed. Just some bread crumbs will due.
Comment 7 Simon Feltman 2012-11-08 01:44:07 UTC
*** Bug 652941 has been marked as a duplicate of this bug. ***
Comment 8 Simon Feltman 2013-04-11 01:50:19 UTC
Review of attachment 225569 [details] [review]:

A lot of code has changed since this patch was created: GObject.py overrides have already gone in with an override for GValue, I think the patch could probably re-based and become much simpler.
Comment 9 Cole Robinson 2013-04-20 20:18:55 UTC
FYI style_get_property has the same problem
Comment 10 yindong 2013-12-03 01:39:44 UTC
I met this problem also. Is there a plan to fix this problem in upstream?
I have not found any related fix in latest upstream git repository.
Comment 11 Simon Feltman 2013-12-03 02:08:10 UTC
(In reply to comment #10)
> I met this problem also. Is there a plan to fix this problem in upstream?
> I have not found any related fix in latest upstream git repository.

Note that you can still get child properties, it is just a bit obtuse:

####
from gi.repository import Gtk
box = Gtk.Box()
label = Gtk.Label()
box.pack_start(label, expand=False, fill=True, padding=38)

value = GObject.Value(bool)
box.child_get_property(label, 'expand', value)
value.get_boolean()
####
Comment 12 yindong 2013-12-03 02:24:04 UTC
still error:
Traceback (most recent call last):
  • File "xxxx.py", line 218 in __cursor_focused
    value = GObject.Value(bool)
TypeError: function takes at most 0 arguments (1 given)
 
Should I install the latest pygobject from git?
Comment 13 Simon Feltman 2013-12-03 02:27:50 UTC
I'm not sure of the exact version this was introduced (definitely PyGObject 3.8+ though). You might also try:

value = GObject.Value()
value.init(bool)
Comment 14 yindong 2013-12-03 02:33:48 UTC
Good, it works, however it's not so elegant.
Expecting an evolution in future.
Thank you!
Comment 15 Simon Feltman 2014-05-26 05:39:44 UTC
Fix for child_get_property was pushed:
https://git.gnome.org/browse/pygobject/commit/?id=6f5a9a37bcdec5
Comment 16 Simon Feltman 2014-05-26 05:40:37 UTC
The following fix has been pushed:
45a5fb2 overrides: Make value argument to Widget.style_get_property optional
Comment 17 Simon Feltman 2014-05-26 05:40:40 UTC
Created attachment 277175 [details] [review]
overrides: Make value argument to Widget.style_get_property optional

Override Gtk.Widget.style_get_property to optionally accept the "value"
argument. If "value" is not supplied, the override will locate the child
property value type and create the GValue. Additionally return the resulting
GValue converted to a native Python value.
Comment 18 Simon Feltman 2014-05-26 06:06:40 UTC
The following fix has been pushed:
d0b23f0 overrides: Add Gtk.Container.child_get/set overrides
Comment 19 Simon Feltman 2014-05-26 06:06:50 UTC
Created attachment 277176 [details] [review]
overrides: Add Gtk.Container.child_get/set overrides

Add overrides for child_get and child_set to Gtk.Container since these
are not introspectable methods.