GNOME Bugzilla – Bug 733800
Make it easier to override properties
Last modified: 2018-01-10 20:43:58 UTC
If there already is something like this, please close. Came up in IRC.. for example implementing Gtk.Scrollable can be implemented like this, I think: http://bpaste.net/show/ebvIUoOv7Ij3k5SCICLk/ while it seems to me it could be as easy as this (using g_object_class_override_property?): class Foo(GObject.Object, Gtk.Scrollable): def __init__(self, **kwargs): super(Foo, self).__init__(**kwargs) self._hscroll = Gtk.Scrollable.props.hscroll_policy.default_value @Gtk.Scrollable.props.hscroll_policy def hscroll_policy(self): return self._hscroll @hscroll_policy.setter def hscroll_policy(self, value): self._hscroll = value
The following should also work: class Foo(GObject.Object, Gtk.Scrollable): hscroll_policy = GObject.Property(type=Gtk.ScrollablePolicy, default=Gtk.ScrollablePolicy.MINIMUM) For the record Python's property() works like this: class C: p = property(fget=lambda x: 1) class B(C): @C.p.getter def p(self): return 2 I think each subsequent call to getter() or setter() creates a copy of the property and fills in the new accessor (the Python implemented GObject.Property works the same way). If we wanted to match that with existing GObject properties it could start getting a bit lengthy though: @Gtk.Scrollable.props.hscroll_policy.getter def hscroll_policy(self): ... Allowing @Gtk.Scrollable.props.hscroll_policy() directly as suggested would probably be ok, but I'd rather try to match what Python does. To counteract the lengthiness, perhaps getting rid of the "props" accessor and allowing direct property access would be a better options: @Gtk.Scrollable.hscroll_policy.getter() Another option would be to add something like GObject.PropertyOverride which matches GObject.SignalOverride. I think would also be a lot easier to implement.
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/pygobject/issues/75.