home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gobject / examples / properties.py < prev    next >
Encoding:
Python Source  |  2009-02-17  |  592 b   |  32 lines

  1. import gobject
  2.  
  3. class MyObject(gobject.GObject):
  4.  
  5.     foo = gobject.property(type=str, default='bar')
  6.     boolprop = gobject.property(type=bool, default=False)
  7.  
  8.     def __init__(self):
  9.         gobject.GObject.__init__(self)
  10.  
  11.     @gobject.property
  12.     def readonly(self):
  13.         return 'readonly'
  14.  
  15. gobject.type_register(MyObject)
  16.  
  17. print "MyObject properties: ", list(MyObject.props)
  18.  
  19. obj = MyObject()
  20.  
  21. print "obj.foo ==", obj.foo
  22.  
  23. obj.foo = 'spam'
  24. print "obj.foo = spam"
  25.  
  26. print "obj.foo == ", obj.foo
  27.  
  28. print "obj.boolprop == ", obj.boolprop
  29.  
  30. print obj.readonly
  31. obj.readonly = 'does-not-work'
  32.