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 733800 - Make it easier to override properties
Make it easier to override properties
Status: RESOLVED OBSOLETE
Product: pygobject
Classification: Bindings
Component: general
Git master
Other Linux
: Normal enhancement
: ---
Assigned To: Nobody's working on this now (help wanted and appreciated)
Python bindings maintainers
Depends on:
Blocks:
 
 
Reported: 2014-07-26 21:09 UTC by Christoph Reiter (lazka)
Modified: 2018-01-10 20:43 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Christoph Reiter (lazka) 2014-07-26 21:09:44 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
Comment 1 Simon Feltman 2014-07-26 22:44:40 UTC
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.
Comment 2 GNOME Infrastructure Team 2018-01-10 20:43:58 UTC
-- 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.