GNOME Bugzilla – Bug 685218
Make it possible to call Gtk.Container.list_child_properties
Last modified: 2014-05-26 05:39:01 UTC
Like in PyGTK, but add them as classmethods instead, which is a bit nicer.
Created attachment 225491 [details] [review] Plug two GObjectClass leaks
Created attachment 225492 [details] [review] Add ObjectInfo.get_class_struct()
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.
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.
(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.
Created attachment 225558 [details] [review] Plug two GObjectClass leaks
Created attachment 225559 [details] [review] Add ObjectInfo.get_class_struct()
Created attachment 225560 [details] [review] Plug two GObjectClass leaks
Created attachment 225561 [details] [review] Add ObjectInfo.get_class_struct()
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.
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 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.
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 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.
Or might it even suffice to provide get_class_struct() on every GObject and call methods on that one then?
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.
(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 on attachment 225561 [details] [review] Add ObjectInfo.get_class_struct() This is fine, but should go together with the other patches.
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 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()
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')
Created attachment 242298 [details] Script used to show potentially conflicting names between objects and their class objects
(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 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.
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.
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.
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>
The following fix has been pushed: 73bf4bb overrides: Make value argument to Container.child_get_property optional
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
(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.