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 685218 - Make it possible to call Gtk.Container.list_child_properties
Make it possible to call Gtk.Container.list_child_properties
Status: RESOLVED FIXED
Product: pygobject
Classification: Bindings
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks: 685076 701843
 
 
Reported: 2012-10-01 13:48 UTC by Johan (not receiving bugmail) Dahlin
Modified: 2014-05-26 05:39 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Plug two GObjectClass leaks (1.08 KB, patch)
2012-10-01 13:48 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
Add ObjectInfo.get_class_struct() (1.49 KB, patch)
2012-10-01 13:48 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
Convert classes to GObjectClass when needed (3.80 KB, patch)
2012-10-01 13:48 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
Add struct class methods as classmethods (2.56 KB, patch)
2012-10-01 13:49 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
Plug two GObjectClass leaks (1.08 KB, patch)
2012-10-02 08:43 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
Add ObjectInfo.get_class_struct() (1.49 KB, patch)
2012-10-02 08:43 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
Plug two GObjectClass leaks (1.08 KB, patch)
2012-10-02 08:44 UTC, Johan (not receiving bugmail) Dahlin
committed Details | Review
Add ObjectInfo.get_class_struct() (1.49 KB, patch)
2012-10-02 08:44 UTC, Johan (not receiving bugmail) Dahlin
committed Details | Review
Convert classes to GObjectClass when needed (4.36 KB, patch)
2012-10-02 08:44 UTC, Johan (not receiving bugmail) Dahlin
none Details | Review
Add struct class methods as classmethods (2.71 KB, patch)
2012-10-02 08:44 UTC, Johan (not receiving bugmail) Dahlin
needs-work Details | Review
Script used to show potentially conflicting names between objects and their class objects (783 bytes, text/x-python)
2013-04-24 00:43 UTC, Simon Feltman
  Details
Add marshalling coercion for Python classes and instances to GTypeClass (6.76 KB, patch)
2014-05-26 05:30 UTC, Simon Feltman
committed Details | Review
Add GTypeClass methods as Python GObject class methods (2.70 KB, patch)
2014-05-26 05:33 UTC, Simon Feltman
committed Details | Review
overrides: Make value argument to Container.child_get_property optional (3.60 KB, patch)
2014-05-26 05:36 UTC, Simon Feltman
committed Details | Review

Description Johan (not receiving bugmail) Dahlin 2012-10-01 13:48:52 UTC
Like in PyGTK, but add them as classmethods instead, which is a bit nicer.
Comment 1 Johan (not receiving bugmail) Dahlin 2012-10-01 13:48:54 UTC
Created attachment 225491 [details] [review]
Plug two GObjectClass leaks
Comment 2 Johan (not receiving bugmail) Dahlin 2012-10-01 13:48:57 UTC
Created attachment 225492 [details] [review]
Add ObjectInfo.get_class_struct()
Comment 3 Johan (not receiving bugmail) Dahlin 2012-10-01 13:48:59 UTC
Created attachment 225493 [details] [review]
Convert classes to GObjectClass when needed

When we have an argument that is a GObjectClass,
also accept a GType classes and get the GObjectClass
from them when needed.

This makes it possible to call functions such as
gtk_container_class_list_child_properties() by passing
in a GtkContainer type as the first argument.
Comment 4 Johan (not receiving bugmail) Dahlin 2012-10-01 13:49:03 UTC
Created attachment 225494 [details] [review]
Add struct class methods as classmethods

Take all the methods from the struct class and add them
as class methods on the normal.

Eg, instead of doing Gtk.ContainerClass.list_child_properties,
just do Gtk.Container.list_child_properties.
Comment 5 Johan (not receiving bugmail) Dahlin 2012-10-01 17:09:24 UTC
(In reply to comment #4)
> Created an attachment (id=225494) [details] [review]
> Add struct class methods as classmethods
> 
> Take all the methods from the struct class and add them
> as class methods on the normal.
> 
> Eg, instead of doing Gtk.ContainerClass.list_child_properties,
> just do Gtk.Container.list_child_properties.

The class methods sometimes conflicts with the normal methods, for instance:
gtk_container_add in Window -> Window.add
GtkWindowClass.add -> Window.add

I'm not sure how to solve this, suggestions are welcome.

(In reply to comment #3)
> Created an attachment (id=225493) [details] [review]
> Convert classes to GObjectClass when needed
> 
> When we have an argument that is a GObjectClass,
> also accept a GType classes and get the GObjectClass
> from them when needed.
> 
> This makes it possible to call functions such as
> gtk_container_class_list_child_properties() by passing
> in a GtkContainer type as the first argument.

This might be done differently, eg for fields.
Comment 6 Johan (not receiving bugmail) Dahlin 2012-10-02 08:43:51 UTC
Created attachment 225558 [details] [review]
Plug two GObjectClass leaks
Comment 7 Johan (not receiving bugmail) Dahlin 2012-10-02 08:43:54 UTC
Created attachment 225559 [details] [review]
Add ObjectInfo.get_class_struct()
Comment 8 Johan (not receiving bugmail) Dahlin 2012-10-02 08:44:24 UTC
Created attachment 225560 [details] [review]
Plug two GObjectClass leaks
Comment 9 Johan (not receiving bugmail) Dahlin 2012-10-02 08:44:31 UTC
Created attachment 225561 [details] [review]
Add ObjectInfo.get_class_struct()
Comment 10 Johan (not receiving bugmail) Dahlin 2012-10-02 08:44:39 UTC
Created attachment 225562 [details] [review]
Convert classes to GObjectClass when needed

When we have an argument that is a GObjectClass,
also accept a GType classes and get the GObjectClass
from them when needed.

This makes it possible to call functions such as
gtk_container_class_list_child_properties() by passing
in a GtkContainer type as the first argument.
Comment 11 Johan (not receiving bugmail) Dahlin 2012-10-02 08:44:46 UTC
Created attachment 225563 [details] [review]
Add struct class methods as classmethods

Take all the methods from the struct class and add them
as class methods on the normal.

Eg, instead of doing Gtk.ContainerClass.list_child_properties,
just do Gtk.Container.list_child_properties.
Comment 12 Martin Pitt 2012-10-04 07:45:10 UTC
Comment on attachment 225560 [details] [review]
Plug two GObjectClass leaks

The second leak was already fixed by Olivier's patch in

http://git.gnome.org/browse/pygobject/commit/?id=2aa61520

I committed the first part. This is also appropriate for the 3.4.x stable series.
Comment 13 Martin Pitt 2012-10-04 07:50:47 UTC
Thanks for working on this! The part that I don't quite like is that this conflates two different classes (GtkContainerClass and GtkContainer) into one in Python, so you get potential namespace conflicts as you already pointed out in comment 5.

Would it be possible somehow to keep them separate, like Gtk.ContainerClass.list_child_properties() ?
Comment 14 Martin Pitt 2012-10-04 07:53:41 UTC
Comment on attachment 225561 [details] [review]
Add ObjectInfo.get_class_struct()

This looks fine. Should go into master as soon as we branched off pygobject-3-4.
Comment 15 Martin Pitt 2012-10-04 07:56:06 UTC
Or might it even suffice to provide get_class_struct() on every GObject and call methods on that one then?
Comment 16 Martin Pitt 2012-10-04 07:56:30 UTC
Comment on attachment 225563 [details] [review]
Add struct class methods as classmethods

Setting to needs-work until we agree how to avoid the potential namespace conflicts.
Comment 17 Johan (not receiving bugmail) Dahlin 2012-10-08 09:25:58 UTC
(In reply to comment #13)
> Thanks for working on this! The part that I don't quite like is that this
> conflates two different classes (GtkContainerClass and GtkContainer) into one
> in Python, so you get potential namespace conflicts as you already pointed out
> in comment 5.
> 
> Would it be possible somehow to keep them separate, like
> Gtk.ContainerClass.list_child_properties() ?

This is not removed, you can still do that.

It's just that it seems a bit more natural to me to put *Class methods as classmethods on the class.

Some things will conflict, like ContainerClass.add(), but as we add the class methods before normal methods you can't really access them and would have to do the Gtk.ContainerClass.add(instance) syntax instead of instance.add().
Comment 18 Martin Pitt 2013-02-25 06:01:51 UTC
Comment on attachment 225561 [details] [review]
Add ObjectInfo.get_class_struct()

This is fine, but should go together with the other patches.
Comment 19 Alessandro Decina 2013-03-03 21:18:37 UTC
We have a related bug in GStreamer: https://bugzilla.gnome.org/show_bug.cgi?id=686572

Should I go and implement classmethods in pygst explicitly? Either way, looks like the get_class_struct() patch could be committed anyway?
Comment 20 Simon Feltman 2013-04-23 22:49:44 UTC
Comment on attachment 225561 [details] [review]
Add ObjectInfo.get_class_struct()

Commited with a simple test.

Attachment 225561 [details] pushed as f22b950 - Add ObjectInfo.get_class_struct()
Comment 21 Simon Feltman 2013-04-24 00:26:12 UTC
Conceptually I agree with Johan in regards to having ObjectClass methods available on the Python classes directly. I think this an accurate translation of the object systems. There is of course the problem of conflicting names because what does not conflict in the C object system naming might when translated to Python. I did some basic analysis of Gtk, Clutter, and Gst and I didn't see any conflicts, but that doesn't necessarily mean there are not in other libs or there will never be one though.

I think having an instance method GObject.Object.get_gclass() or even obj.__gclass__ similar to our __gtype__ accessor would also be fine for the short term. We can use this internally to fix things like bug 685076. Usage would then turn into:

GObject.ObjectClass.find_property(obj.__gclass__, 'foo')
 or even with auto coercion:
GObject.ObjectClass.find_property(obj, 'foo')

But this will be difficult for a Python programmer to find in regards to a public API (I would never expect to find class methods on some auxiliary class). So ideally it should just be:

obj.find_property('foo')
 or
Bar.find_property(obj, 'foo')
Comment 22 Simon Feltman 2013-04-24 00:43:26 UTC
Created attachment 242298 [details]
Script used to show potentially conflicting names between objects and their class objects
Comment 23 Martin Pitt 2013-04-24 05:46:09 UTC
(In reply to comment #21)
> I think having an instance method GObject.Object.get_gclass() or even
> obj.__gclass__ similar to our __gtype__ accessor would also be fine for the
> short term.

That's actually a great idea. So if there is conflicting class and object method, the object method should have precedence, and one can use the above to still access the class method. These cases should be covered by tests.

I think that's a great compromise, thanks!
Comment 24 Simon Feltman 2014-05-26 05:30:06 UTC
Comment on attachment 225562 [details] [review]
Convert classes to GObjectClass when needed

The following fix has been pushed:
778d05c Add marshalling coercion for Python classes and instances to GTypeClass

This is a slightly different approach than what Johan had done.
Comment 25 Simon Feltman 2014-05-26 05:30:11 UTC
Created attachment 277172 [details] [review]
Add marshalling coercion for Python classes and instances to GTypeClass

Automatically marshal Python GObject classes and instances to GTypeClass
structs (GObjectClass). This allows usage of the GTypeClass methods by
passing a Python GObject class or instance to the GTypeClass method.
This is needed to support usage of GTypeClass methods since we don't
manually bind GTypeClasses and they are not very well supported with
introspection.
Comment 26 Simon Feltman 2014-05-26 05:33:21 UTC
The following fix has been pushed:
bf84915 Add GTypeClass methods as Python GObject class methods

Pushed Johans patch with the addition of not clobbering existing method name
and making tests not rely on Gtk.
Comment 27 Simon Feltman 2014-05-26 05:33:30 UTC
Created attachment 277173 [details] [review]
Add GTypeClass methods as Python GObject class methods

Take all the methods from an objects type classs and add them
as class methods. For instance, GObject.ObjectClass.list_properties
is available as GObject.Object.list_properties().

Co-Authored-By: Simon Feltman <sfeltman@src.gnome.org>
Comment 28 Simon Feltman 2014-05-26 05:36:43 UTC
The following fix has been pushed:
73bf4bb overrides: Make value argument to Container.child_get_property optional
Comment 29 Simon Feltman 2014-05-26 05:36:47 UTC
Created attachment 277174 [details] [review]
overrides: Make value argument to Container.child_get_property optional

Override Gtk.Container.child_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.

https://bugzilla.gnome.org/show_bug.cgi?id=685076
Comment 30 Simon Feltman 2014-05-26 05:39:01 UTC
(In reply to comment #29)
> Created an attachment (id=277174) [details] [review]
> overrides: Make value argument to Container.child_get_property optional

Oops, this was meant for bug 685076.