Index: tests/test_properties.py
===================================================================
--- tests/test_properties.py	(revisão 658)
+++ tests/test_properties.py	(cópia de trabalho)
@@ -3,53 +3,22 @@
 import unittest
 
 from common import testhelper
-from gobject import GObject, GType, new, PARAM_READWRITE, \
+import gobject
+from gobject import GObject, GType, GEnum, new, PARAM_READWRITE, \
      PARAM_CONSTRUCT, PARAM_READABLE, PARAM_WRITABLE, PARAM_CONSTRUCT_ONLY, \
      TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG, \
      TYPE_INT64, TYPE_UINT64
 
 class PropertyObject(GObject):
-    __gproperties__ = {
-        'normal': (str, 'blurb', 'description',  'default',
-                     PARAM_READWRITE),
-        'construct': (str, 'blurb', 'description', 'default',
-                     PARAM_READWRITE|PARAM_CONSTRUCT),
-        'construct-only': (str, 'blurb', 'description', 'default',
-                     PARAM_READWRITE|PARAM_CONSTRUCT_ONLY),
-        'uint64': (TYPE_UINT64, 'blurb', 'description', 0, 10, 0,
-                   PARAM_READWRITE),
-    }
-
-    def __init__(self):
-        GObject.__init__(self)
-        self._value = 'default'
-        self._construct_only = None
-        self._construct = None
-        self._uint64 = 0L
-
-    def do_get_property(self, pspec):
-        if pspec.name == 'normal':
-            return self._value
-        elif pspec.name == 'construct':
-            return self._construct
-        elif pspec.name == 'construct-only':
-            return self._construct_only
-        elif pspec.name == 'uint64':
-            return self._uint64
-        else:
-            raise AssertionError
-
-    def do_set_property(self, pspec, value):
-        if pspec.name == 'normal':
-            self._value = value
-        elif pspec.name == 'construct':
-            self._construct = value
-        elif pspec.name == 'construct-only':
-            self._construct_only = value
-        elif pspec.name == 'uint64':
-            self._uint64 = value
-        else:
-            raise AssertionError
+    normal = gobject.property(type=str)
+    construct = gobject.property(
+        type=str,
+        flags=PARAM_READWRITE|PARAM_CONSTRUCT, default='default')
+    construct_only = gobject.property(
+        type=str,
+        flags=PARAM_READWRITE|PARAM_CONSTRUCT_ONLY)
+    uint64 = gobject.property(
+        type=TYPE_UINT64, flags=PARAM_READWRITE|PARAM_CONSTRUCT)
 
 class TestProperties(unittest.TestCase):
     def testGetSet(self):
@@ -106,7 +75,7 @@
                           obj.set_property, 'construct-only', '456')
 
     def testUint64(self):
-        obj = new(PropertyObject)
+        obj = PropertyObject()
         self.assertEqual(obj.props.uint64, 0)
         obj.props.uint64 = 1L
         self.assertEqual(obj.props.uint64, 1L)
@@ -200,3 +169,70 @@
         normal, uint64 = obj.get_properties("normal", "uint64")
         self.assertEqual(normal, "foo")
         self.assertEqual(uint64, 7)
+
+class TestNewStyleProperties(unittest.TestCase):
+    def testSimple(self):
+        class C(gobject.GObject):
+            str = gobject.property(type=str)
+            int = gobject.property(type=int)
+            float = gobject.property(type=float)
+            long = gobject.property(type=long)
+
+        self.failUnless(hasattr(C.props, 'str'))
+        self.failUnless(hasattr(C.props, 'int'))
+        self.failUnless(hasattr(C.props, 'float'))
+        self.failUnless(hasattr(C.props, 'long'))
+
+        o = C()
+        self.assertEqual(o.str, '')
+        o.str = 'str'
+        self.assertEqual(o.str, 'str')
+
+        self.assertEqual(o.int, 0)
+        o.int = 1138
+        self.assertEqual(o.int, 1138)
+
+        self.assertEqual(o.float, 0.0)
+        o.float = 3.14
+        self.assertEqual(o.float, 3.14)
+
+        self.assertEqual(o.long, 0L)
+        o.long = 100L
+        self.assertEqual(o.long, 100L)
+
+    def testCustomGetter(self):
+        class C(gobject.GObject):
+            def get_prop(self):
+                return 'value'
+            prop = gobject.property(getter=get_prop)
+
+        o = C()
+        self.assertEqual(o.prop, 'value')
+        self.assertRaises(TypeError, setattr, o, 'prop', 'xxx')
+
+    def testCustomSetter(self):
+        class C(gobject.GObject):
+            def set_prop(self, value):
+                self._value = value
+            prop = gobject.property(setter=set_prop)
+
+            def __init__(self):
+                self._value = None
+                gobject.GObject.__init__(self)
+
+        o = C()
+        self.assertEquals(o._value, None)
+        o.prop = 'bar'
+        self.assertEquals(o._value, 'bar')
+        self.assertRaises(TypeError, getattr, o, 'prop')
+
+    def testErrors(self):
+        self.assertRaises(TypeError, gobject.property, type='str')
+        self.assertRaises(TypeError, gobject.property, nick=False)
+        self.assertRaises(TypeError, gobject.property, blurb=False)
+        self.assertRaises(TypeError, gobject.property, type=bool, default=0)
+        self.assertRaises(TypeError, gobject.property, type=GEnum)
+        self.assertRaises(TypeError, gobject.property, type=GEnum, default=0)
+        self.assertRaises(TypeError, gobject.property, type=object, default=0)
+        self.assertRaises(TypeError, gobject.property, type=complex)
+        self.assertRaises(TypeError, gobject.property, flags=-10)
Index: tests/test_interface.py
===================================================================
--- tests/test_interface.py	(revisão 658)
+++ tests/test_interface.py	(cópia de trabalho)
@@ -3,15 +3,13 @@
 import testmodule
 from common import gobject, testhelper
 from gobject import GObject, GInterface
+import gobject
 
 GUnknown = gobject.type_from_name("TestUnknown")
 Unknown = GUnknown.pytype
 
 class MyUnknown(Unknown, testhelper.Interface):
-    __gproperties__ = {
-        'some-property': (str, 'blurb', 'description',  'default',
-                          gobject.PARAM_READWRITE),
-    }
+    some_property = gobject.property(type=str)
 
     def __init__(self):
         Unknown.__init__(self)
@@ -24,10 +22,7 @@
 gobject.type_register(MyUnknown)
 
 class MyObject(gobject.GObject, testhelper.Interface):
-    __gproperties__ = {
-        'some-property': (str, 'blurb', 'description',  'default',
-                          gobject.PARAM_READWRITE),
-    }
+    some_property = gobject.property(type=str)
 
     def __init__(self):
         GObject.__init__(self)
Index: tests/test_enum.py
===================================================================
--- tests/test_enum.py	(revisão 658)
+++ tests/test_enum.py	(cópia de trabalho)
@@ -1,20 +1,15 @@
 import unittest
 import warnings
 
+import gobject
 from gobject import GEnum, GFlags, GObject, GType, PARAM_READWRITE
 from common import gobject, atk, pango, gtk, gdk
 
 class PObject(GObject):
-    __gproperties__ = {
-        'enum': (gtk.WindowType, 'blurb', 'description',
-                 gtk.WINDOW_TOPLEVEL, PARAM_READWRITE),
-        'enum2': (gtk.WindowType, 'blurb', 'description',
-                  int(gtk.WINDOW_TOPLEVEL), PARAM_READWRITE),
-        'flags': (gtk.AttachOptions, 'blurb', 'description',
-                  gtk.EXPAND, PARAM_READWRITE),
-        'flags2': (gtk.AttachOptions, 'blurb', 'description',
-                   int(gtk.EXPAND), PARAM_READWRITE),
-    }
+    enum = gobject.property(type=gtk.WindowType, default=gtk.WINDOW_TOPLEVEL)
+    enum2 = gobject.property(type=gtk.WindowType, default=int(gtk.WINDOW_TOPLEVEL))
+    flags = gobject.property(type=gtk.AttachOptions, default=gtk.EXPAND)
+    flags2 = gobject.property(type=gtk.AttachOptions, default=int(gtk.EXPAND))
 
 class EnumTest(unittest.TestCase):
     def testEnums(self):

Mudanças de propriedades em: gobject
___________________________________________________________________
Nome: svn:ignore
   - Makefile
Makefile.in
.deps
.libs
*.lo
*.la
*.pyc

   + Makefile
Makefile.in
.deps
.libs
*.lo
*.la
*.pyc
generate-constants
constants.py


Index: gobject/generate-constants.c
===================================================================
--- gobject/generate-constants.c	(revisão 0)
+++ gobject/generate-constants.c	(revisão 0)
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include <glibconfig.h>
+
+int main(void)
+{
+  printf("# This part is generated by generate-constants.c\n");
+  printf("G_MINFLOAT = %f\n", G_MINFLOAT);
+  printf("G_MINFLOAT = %f\n", G_MINFLOAT);
+  printf("G_MAXFLOAT = %f\n", G_MAXFLOAT);
+  printf("G_MINDOUBLE = %f\n", G_MINDOUBLE);
+  printf("G_MAXDOUBLE = %f\n", G_MAXDOUBLE);
+  printf("G_MINSHORT = %d\n", G_MINSHORT);
+  printf("G_MAXSHORT = %d\n", G_MAXSHORT);
+  printf("G_MAXUSHORT = %u\n", G_MAXUSHORT);
+  printf("G_MININT = %d\n", G_MININT);
+  printf("G_MAXINT = %d\n", G_MAXINT);
+  printf("G_MAXUINT = %u\n", G_MAXUINT);
+  printf("G_MINLONG = %ldL\n", G_MINLONG);
+  printf("G_MAXLONG = %ldL\n", G_MAXLONG);
+  printf("G_MAXULONG = %luL\n", G_MAXULONG);
+}
Index: gobject/__init__.py
===================================================================
--- gobject/__init__.py	(revisão 658)
+++ gobject/__init__.py	(cópia de trabalho)
@@ -27,15 +27,61 @@
 except ImportError:
     pass
 
+from gobject.constants import *
 from _gobject import *
 _PyGObject_API = _gobject._PyGObject_API
 
+from _property import property
+
 class GObjectMeta(type):
     "Metaclass for automatically registering GObject classes"
     def __init__(cls, name, bases, dict_):
         type.__init__(cls, name, bases, dict_)
+        cls._install_properties()
         cls._type_register(cls.__dict__)
 
+    def _install_properties(cls):
+        gproperties = getattr(cls, '__gproperties__', {})
+        props = {}
+        for name, prop in cls.__dict__.items():
+            if isinstance(prop, property):
+                if name in gproperties:
+                    raise ValueError
+                prop.name = name
+                props[name] = prop.get_pspec_args()
+
+        if not props:
+            return
+
+        if not gproperties:
+            cls.__gproperties__ = props
+        else:
+            gproperties.update(props)
+
+        if (hasattr(cls, 'do_get_property') or
+            hasattr(cls, 'do_set_property')):
+            for prop in props:
+                if (prop.getter != prop.default_getter or
+                    prop.setter != prop.default_setter):
+                    raise TypeError(
+                        "GObject subclass %r defines do_get/set_property"
+                        " and it also uses a property which a custom setter"
+                        " or getter. This is not allowed" % (cls,))
+
+        def obj_get_property(self, pspec):
+            name = pspec.name.replace('-', '_')
+            prop = getattr(cls, name, None)
+            if prop:
+                return prop.getter(self)
+        cls.do_get_property = obj_get_property
+
+        def obj_set_property(self, pspec, value):
+            name = pspec.name.replace('-', '_')
+            prop = getattr(cls, name, None)
+            if prop:
+                prop.setter(self, value)
+        cls.do_set_property = obj_set_property
+
     def _type_register(cls, namespace):
         ## don't register the class if already registered
         if '__gtype__' in namespace:
@@ -50,28 +96,4 @@
 
 _gobject._install_metaclass(GObjectMeta)
 
-# TYPE_INVALID defined in gobjectmodule.c
-TYPE_NONE = type_from_name('void')
-TYPE_INTERFACE = type_from_name('GInterface')
-TYPE_CHAR = type_from_name('gchar')
-TYPE_UCHAR = type_from_name('guchar')
-TYPE_BOOLEAN = type_from_name('gboolean')
-TYPE_INT = type_from_name('gint')
-TYPE_UINT = type_from_name('guint')
-TYPE_LONG = type_from_name('glong')
-TYPE_ULONG = type_from_name('gulong')
-TYPE_INT64 = type_from_name('gint64')
-TYPE_UINT64 = type_from_name('guint64')
-TYPE_ENUM = type_from_name('GEnum')
-TYPE_FLAGS = type_from_name('GFlags')
-TYPE_FLOAT = type_from_name('gfloat')
-TYPE_DOUBLE = type_from_name('gdouble')
-TYPE_STRING = type_from_name('gchararray')
-TYPE_POINTER = type_from_name('gpointer')
-TYPE_BOXED = type_from_name('GBoxed')
-TYPE_PARAM = type_from_name('GParam')
-TYPE_OBJECT = type_from_name('GObject')
-TYPE_PYOBJECT = type_from_name('PyObject')
-TYPE_UNICHAR = TYPE_UINT
-
 del _gobject
Index: gobject/constants.py.in
===================================================================
--- gobject/constants.py.in	(revisão 0)
+++ gobject/constants.py.in	(revisão 0)
@@ -0,0 +1,47 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# pygobject - Python bindings for the GObject library
+# Copyright (C) 2006-2007 Johan Dahlin
+#
+#   gobject/constants.py: GObject type constants
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+
+from _gobject import type_from_name
+
+# TYPE_INVALID defined in gobjectmodule.c
+TYPE_NONE = type_from_name('void')
+TYPE_INTERFACE = type_from_name('GInterface')
+TYPE_CHAR = type_from_name('gchar')
+TYPE_UCHAR = type_from_name('guchar')
+TYPE_BOOLEAN = type_from_name('gboolean')
+TYPE_INT = type_from_name('gint')
+TYPE_UINT = type_from_name('guint')
+TYPE_LONG = type_from_name('glong')
+TYPE_ULONG = type_from_name('gulong')
+TYPE_INT64 = type_from_name('gint64')
+TYPE_UINT64 = type_from_name('guint64')
+TYPE_ENUM = type_from_name('GEnum')
+TYPE_FLAGS = type_from_name('GFlags')
+TYPE_FLOAT = type_from_name('gfloat')
+TYPE_DOUBLE = type_from_name('gdouble')
+TYPE_STRING = type_from_name('gchararray')
+TYPE_POINTER = type_from_name('gpointer')
+TYPE_BOXED = type_from_name('GBoxed')
+TYPE_PARAM = type_from_name('GParam')
+TYPE_OBJECT = type_from_name('GObject')
+TYPE_PYOBJECT = type_from_name('PyObject')
+TYPE_UNICHAR = TYPE_UINT
+
Index: gobject/Makefile.am
===================================================================
--- gobject/Makefile.am	(revisão 658)
+++ gobject/Makefile.am	(cópia de trabalho)
@@ -9,7 +9,11 @@
 
 # gobject python scripts
 pygobjectdir = $(pkgpyexecdir)/gobject
-pygobject_PYTHON = __init__.py option.py
+pygobject_PYTHON = 	\
+	__init__.py 	\
+	_property.py	\
+	constants.py	\
+	option.py	
 pygobject_LTLIBRARIES = _gobject.la 
 
 
@@ -18,6 +22,14 @@
 common_ldflags += -no-undefined
 endif
 
+constants.py: generate-constants constants.py.in
+	rm -f constants.py
+	cp constants.py.in constants.py
+	$(top_builddir)/gobject/generate-constants >> constants.py
+
+generate_constants_CFLAGS = $(GLIB_CFLAGS)
+noinst_PROGRAMS = generate-constants
+CLEANFILES = constants.py
 
 _gobject_la_CFLAGS = $(GLIB_CFLAGS)
 _gobject_la_LDFLAGS = $(common_ldflags) -export-symbols-regex init_gobject
Index: gobject/_property.py
===================================================================
--- gobject/_property.py	(revisão 0)
+++ gobject/_property.py	(revisão 0)
@@ -0,0 +1,261 @@
+# -*- Mode: Python; py-indent-offset: 4 -*-
+# pygobject - Python bindings for the GObject library
+# Copyright (C) 2007 Johan Dahlin
+#
+#   gobject/_property.py: GObject property wrapper/helper
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+# USA
+
+import _gobject
+from gobject.constants import \
+     TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, \
+     TYPE_BOOLEAN, TYPE_INT, TYPE_UINT, TYPE_LONG, \
+     TYPE_ULONG, TYPE_INT64, TYPE_UINT64, TYPE_ENUM, \
+     TYPE_FLAGS, TYPE_FLOAT, TYPE_DOUBLE, TYPE_STRING, \
+     TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT, \
+     TYPE_PYOBJECT
+from gobject.constants import \
+     G_MINFLOAT, G_MAXFLOAT, G_MINDOUBLE, G_MAXDOUBLE, \
+     G_MININT, G_MAXINT, G_MAXUINT, G_MINLONG, G_MAXLONG, \
+     G_MAXULONG
+
+
+class property(object):
+    """
+    Creates a new property which in conjunction with GObjectMeta will
+    create a GObject property proxy:
+
+    >>> class MyObject(gobject.GObject):
+    >>> ... prop = gobject.property(type=str)
+
+    >>> obj = MyObject()
+    >>> obj.prop = 'value'
+
+    >>> obj.prop
+    'value'
+    """
+
+    def __init__(self, getter=None, setter=None, type=None, default=None, nick='', blurb='',
+                 flags=_gobject.PARAM_READWRITE, minimum=None, maximum=None):
+        """
+        @param  getter: getter to get the value of the property
+        @type   getter: callable
+        @param  setter: setter to set the value of the property
+        @type   setter: callable
+        @param    type: type of property
+        @type     type: type
+        @param default: default value
+        @param    nick: short description
+        @type     bick: string
+        @param   blurb: long description
+        @type    blurb: string
+        @param flags:    parameter flags, one of:
+        - gobject.PARAM_READABLE
+        - gobject.PARAM_READWRITE
+        - gobject.PARAM_WRITABLE
+        - gobject.PARAM_CONSTRUCT
+        - gobject.PARAM_CONSTRUCT_ONLY
+        - gobject.PARAM_LAX_VALIDATION
+        @keyword minimum:  minimum allowed value (int, float, long only)
+        @keyword maximum:  maximum allowed value (int, float, long only)
+        """
+
+        if getter and not setter:
+            setter = self._readonly_setter
+        elif setter and not getter:
+            getter = self._writeonly_getter
+        elif not setter and not getter:
+            getter = self._default_getter
+            setter = self._default_setter
+        self.getter = getter
+        self.setter = setter
+
+        if type is None:
+            type = object
+        self.type = self._type_from_python(type)
+        self.default = self._get_default(default)
+        self._check_default()
+
+        if not isinstance(nick, basestring):
+            raise TypeError("nick must be a string")
+        self.nick = nick
+
+        if not isinstance(blurb, basestring):
+            raise TypeError("blurb must be a string")
+        self.blurb = blurb
+
+        if flags < 0 or flags > 32:
+            raise TypeError("invalid flag value: %r" % (flags,))
+        self.flags = flags
+
+        self.minimum = self._get_minimum()
+        self.maximum = self._get_maximum()
+
+        self.name = None
+
+        self._value = self.default
+        self._exc = None
+
+    def __repr__(self):
+        return '<gobject property %s (%s)>' % (
+            self.name or '(uninitialized)',
+            _gobject.type_name(self.type))
+
+    def __get__(self, instance, klass):
+        if instance is None:
+            return self
+
+        self._exc = None
+        value = instance.get_property(self.name)
+        if self._exc:
+            exc = self._exc
+            self._exc = None
+            raise exc
+
+        return value
+
+    def __set__(self, instance, value):
+        if instance is None:
+            raise TypeError
+
+        self._exc = None
+        instance.set_property(self.name, value)
+        if self._exc:
+            exc = self._exc
+            self._exc = None
+            raise exc
+
+    def _type_from_python(self, type):
+        if type == int:
+            return TYPE_INT
+        elif type == bool:
+            return TYPE_BOOLEAN
+        elif type == long:
+            return TYPE_LONG
+        elif type == float:
+            return TYPE_DOUBLE
+        elif type == str:
+            return TYPE_STRING
+        elif type == object:
+            return TYPE_PYOBJECT
+        elif type in [TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR,
+                      TYPE_UINT, TYPE_LONG, TYPE_ULONG, TYPE_INT64,
+                      TYPE_UINT64, TYPE_ENUM, TYPE_FLAGS, TYPE_FLOAT,
+                      TYPE_POINTER, TYPE_BOXED, TYPE_PARAM, TYPE_OBJECT]:
+            return type
+        else:
+            raise TypeError("Unsupported type: %r" % (type,))
+
+    def _get_default(self, default):
+        ptype = self.type
+        if default is not None:
+            return default
+
+        if ptype in [TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG,
+                     TYPE_INT64, TYPE_UINT64]:
+            return 0
+        elif ptype == TYPE_STRING:
+            return ''
+        elif ptype == TYPE_FLOAT or ptype == TYPE_DOUBLE:
+            return 0.0
+        else:
+            return None
+
+    def _check_default(self):
+        ptype = self.type
+        default = self.default
+        if (ptype == TYPE_BOOLEAN and
+            (default is not True or
+             default is not False)):
+            raise TypeError(
+                "default must be True or False, not %r" % (default,))
+        elif ptype == TYPE_PYOBJECT:
+            if default is not None:
+                raise TypeError("object types does not have default values")
+
+    def _get_minimum(self):
+        ptype = self.type
+        if ptype in [TYPE_UINT, TYPE_ULONG, TYPE_UINT64]:
+            return 0
+        elif ptype == TYPE_FLOAT:
+            return G_MINFLOAT
+        elif ptype == TYPE_DOUBLE:
+            return G_MINDOUBLE
+        elif ptype == TYPE_INT:
+            return G_MININT
+        elif ptype == TYPE_LONG:
+            return G_MINLONG
+        elif ptype == TYPE_INT64:
+            return -2 ** 62 - 1
+
+        return None
+
+    def _get_maximum(self):
+        ptype = self.type
+        if ptype == TYPE_UINT:
+            return G_MAXUINT
+        elif ptype == TYPE_ULONG:
+            return G_MAXULONG
+        elif ptype == TYPE_INT64:
+            return 2 ** 62 - 1
+        elif ptype == TYPE_UINT64:
+            return 2 ** 63 - 1
+        elif ptype == TYPE_FLOAT:
+            return G_MAXFLOAT
+        elif ptype == TYPE_DOUBLE:
+            return G_MAXDOUBLE
+        elif ptype == TYPE_INT:
+            return G_MAXINT
+        elif ptype == TYPE_LONG:
+            return G_MAXLONG
+
+        return None
+
+    #
+    # Getter and Setter
+    #
+
+    def _default_setter(self, instance, value):
+        self._value = value
+
+    def _default_getter(self, instance):
+        return self._value
+
+    def _readonly_setter(self, instance, value):
+        self._exc = TypeError("%s property of %s is read-only" % (
+            self.name, type(instance).__name__))
+
+    def _writeonly_getter(self, instance):
+        self._exc = TypeError("%s property of %s is write-only" % (
+            self.name, type(instance).__name__))
+
+    #
+    # Public API
+    #
+
+    def get_pspec_args(self):
+        ptype = self.type
+        if ptype in [TYPE_INT, TYPE_UINT, TYPE_LONG, TYPE_ULONG,
+                     TYPE_INT64, TYPE_UINT64, TYPE_FLOAT, TYPE_DOUBLE]:
+            args = self._get_minimum(), self._get_maximum(), self.default
+        elif ptype == TYPE_STRING or ptype == TYPE_BOOLEAN:
+            args = (self.default,)
+        elif ptype == TYPE_PYOBJECT:
+            args = ()
+        else:
+            raise NotImplementedError(ptype)
+
+        return (self.type, self.nick, self.blurb) + args + (self.flags,)
Index: examples/properties.py
===================================================================
--- examples/properties.py	(revisão 658)
+++ examples/properties.py	(cópia de trabalho)
@@ -1,43 +1,31 @@
 import gobject
 
 class MyObject(gobject.GObject):
-    __gproperties__ = {
-        'foo': (gobject.TYPE_STRING, 'foo property', 'the foo of the object',
-                'bar', gobject.PARAM_READWRITE),
-        'boolprop': (gobject.TYPE_BOOLEAN, 'bool prop', 'a test boolean prop',
-                     0, gobject.PARAM_READABLE),
-    }
+
+    foo = gobject.property(type=str, default='bar')
+    boolprop = gobject.property(type=bool, default=False)
 
     def __init__(self):
-        self.__gobject_init__()
-        self.foo = 'bar'
-    def do_set_property(self, pspec, value):
-        print '    do_set_property called for %s=%r' % (pspec.name, value)
-        if pspec.name == 'foo':
-            self.foo = value
-        else:
-            raise AttributeError, 'unknown property %s' % pspec.name
-    def do_get_property(self, pspec):
-        print '    do_get_property called for %s' % pspec.name
-        if pspec.name == 'foo':
-            return self.foo
-        elif pspec.name == 'boolprop':
-            return 1
-        else:
-            raise AttributeError, 'unknown property %s' % pspec.name
+        gobject.GObject.__init__(self)
+
+    @gobject.property
+    def readonly(self):
+        return 'readonly'
+
 gobject.type_register(MyObject)
 
-print "MyObject properties: ", gobject.list_properties(MyObject)
+print "MyObject properties: ", list(MyObject.props)
+
 obj = MyObject()
 
-val = obj.get_property('foo')
-print "obj.get_property('foo') == ", val
+print "obj.foo ==", obj.foo
 
-obj.set_property('foo', 'spam')
-print "obj.set_property('foo', 'spam')"
+obj.foo = 'spam'
+print "obj.foo = spam"
 
-val = obj.get_property('foo')
-print "obj.get_property('foo') == ", val
+print "obj.foo == ", obj.foo
 
-val = obj.get_property('boolprop')
-print "obj.get_property('boolprop') == ", val
+print "obj.boolprop == ", obj.boolprop
+
+print obj.readonly
+obj.readonly = 'does-not-work'
Index: examples/signal.py
===================================================================
--- examples/signal.py	(revisão 658)
+++ examples/signal.py	(cópia de trabalho)
@@ -1,13 +1,8 @@
-import pygtk; pygtk.require("2.0")
 import gobject
 
 class C(gobject.GObject):
-    __gsignals__ = {
-        'my_signal': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
-                      (gobject.TYPE_INT,))
-    }
-    def __init__(self):
-        self.__gobject_init__() # default constructor using our new GType
+    my_signal = gobject.signal(int)
+
     def do_my_signal(self, arg):
         print "C: class closure for `my_signal' called with argument", arg
 
