diff options
author | Garrett Regier <garrettregier@gmail.com> | 2013-07-02 06:07:15 -0700 |
---|---|---|
committer | Simon Feltman <sfeltman@src.gnome.org> | 2013-07-02 16:16:57 -0700 |
commit | b96a6dc968566d339a2dfd7dd631ae52d812302a (patch) | |
tree | 0dbe206ff61b27bedbf23f82458c56ddbb3c8f53 | |
parent | 61b268e44af63d6d78feae42578bf75aa5cfd511 (diff) | |
download | pygobject-b96a6dc968566d339a2dfd7dd631ae52d812302a.tar.gz |
Add support for properties of type GInterface
Add support for G_TYPE_INTERFACE/GInterface to switch
statement which handles G_TYPE_OBJECT based properties.
Signed-off-by: Simon Feltman <sfeltman@src.gnome.org>
https://bugzilla.gnome.org/show_bug.cgi?id=703456
-rw-r--r-- | gi/_gobject/gobjectmodule.c | 1 | ||||
-rw-r--r-- | gi/_gobject/propertyhelper.py | 3 | ||||
-rw-r--r-- | tests/test_properties.py | 16 |
3 files changed, 19 insertions, 1 deletions
diff --git a/gi/_gobject/gobjectmodule.c b/gi/_gobject/gobjectmodule.c index 1e1cbd84..81dc44be 100644 --- a/gi/_gobject/gobjectmodule.c +++ b/gi/_gobject/gobjectmodule.c @@ -623,6 +623,7 @@ create_property (const gchar *prop_name, pspec = g_param_spec_pointer (prop_name, nick, blurb, flags); break; case G_TYPE_OBJECT: + case G_TYPE_INTERFACE: if (!PyArg_ParseTuple(args, "")) return NULL; pspec = g_param_spec_object (prop_name, nick, blurb, prop_type, flags); diff --git a/gi/_gobject/propertyhelper.py b/gi/_gobject/propertyhelper.py index e8ccb355..41be81d3 100644 --- a/gi/_gobject/propertyhelper.py +++ b/gi/_gobject/propertyhelper.py @@ -261,7 +261,8 @@ class Property(object): issubclass(type_, (_gobject.GObject, _gobject.GEnum, _gobject.GFlags, - _gobject.GBoxed))): + _gobject.GBoxed, + _gobject.GInterface))): return type_.__gtype__ elif type_ in (TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG, diff --git a/tests/test_properties.py b/tests/test_properties.py index 4b128f39..ef6b8674 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -69,6 +69,9 @@ class PropertyObject(GObject.GObject): type=TYPE_VARIANT, flags=PARAM_READWRITE | PARAM_CONSTRUCT, default=GLib.Variant('i', 42)) + interface = GObject.Property( + type=Gio.File, flags=PARAM_READWRITE | PARAM_CONSTRUCT) + class PropertyInheritanceObject(Regress.TestObj): # override property from the base class, with a different type @@ -133,6 +136,7 @@ class TestPropertyObject(unittest.TestCase): 'enum', 'flags', 'gtype', + 'interface', 'normal', 'strings', 'uint64', @@ -389,6 +393,17 @@ class TestPropertyObject(unittest.TestCase): obj = new(PropertyObject, variant_def=GLib.Variant('u', 5)) self.assertEqual(obj.props.variant_def.print_(True), 'uint32 5') + def test_interface(self): + obj = new(PropertyObject) + + file = Gio.File.new_for_path('/some/path') + obj.props.interface = file + self.assertEqual(obj.props.interface.get_path(), '/some/path') + self.assertEqual(obj.interface.get_path(), '/some/path') + + self.assertRaises(TypeError, setattr, obj, 'interface', 'foo') + self.assertRaises(TypeError, setattr, obj, 'interface', object()) + def test_range(self): # kiwi code def max(c): @@ -827,6 +842,7 @@ class TestProperty(unittest.TestCase): self.assertEqual(tester._type_from_python(GObject.GEnum), GObject.GEnum.__gtype__) self.assertEqual(tester._type_from_python(GObject.GFlags), GObject.GFlags.__gtype__) self.assertEqual(tester._type_from_python(GObject.GBoxed), GObject.GBoxed.__gtype__) + self.assertEqual(tester._type_from_python(GObject.GInterface), GObject.GInterface.__gtype__) for type_ in [TYPE_NONE, TYPE_INTERFACE, TYPE_CHAR, TYPE_UCHAR, TYPE_INT, TYPE_UINT, TYPE_BOOLEAN, TYPE_LONG, |