Re: Supporting attribute-like properties



Hi Kerrick,

Properties on classes and objects pulled in through introspection have a "props" accessor. So with your example but using myLabel.props.angle should already work.

If the GObject property was created in python, then the property will be directly accessible on the object as well (GObject.Property supports the descriptor and decoration protocols similar pythons built-in "property")

from gi.repository import GObject
class Label(GObject.GObject):
    angle = GObject.Property(type=float)
myLabel = Label()
myLabel.angle = myLabel.angle + 180

-Simon

On Fri, May 25, 2012 at 10:43 PM, Kerrick Staley <mail kerrickstaley com> wrote:
Hello,
Are there any plans to allow GObject properties to be accessed just like ordinary attributes (using __getattr__ and __setattr__)? This would allow something like

myLabel.angle += 180

instead of

myLabel.set_angle(myLabel.get_angle() + 180)

- Kerrick


_______________________________________________
python-hackers-list mailing list
python-hackers-list gnome org
https://mail.gnome.org/mailman/listinfo/python-hackers-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]