diff options
| author | Paul Pogonyshev <pogonyshev@gmx.net> | 2008-08-11 20:17:12 +0000 |
|---|---|---|
| committer | Paul Pogonyshev <paulp@src.gnome.org> | 2008-08-11 20:17:12 +0000 |
| commit | 83b468fdf8301da3653032c28b6685f0ef5986f8 (patch) | |
| tree | f89322f569d181cd8997b8dcb3b18a556a88984e | |
| parent | bc1a275dedc30f56face403118699ebf9aafa846 (diff) | |
| download | pygobject-83b468fdf8301da3653032c28b6685f0ef5986f8.tar.gz pygobject-83b468fdf8301da3653032c28b6685f0ef5986f8.tar.xz pygobject-83b468fdf8301da3653032c28b6685f0ef5986f8.zip | |
Bug 547104 – improve type wrapper creation
2008-08-11 Paul Pogonyshev <pogonyshev@gmx.net>
Bug 547104 – improve type wrapper creation
* gio/gappinfo.override (_wrap_g_app_info_tp_richcompare)
(_wrap_g_app_info_tp_repr): New functions.
* tests/test_gio.py (TestAppInfo.test_eq): New test.
svn path=/trunk/; revision=941
| -rw-r--r-- | ChangeLog | 9 | ||||
| -rw-r--r-- | gio/gappinfo.override | 48 | ||||
| -rw-r--r-- | tests/test_gio.py | 8 |
3 files changed, 65 insertions, 0 deletions
@@ -2,6 +2,15 @@ Bug 547104 – improve type wrapper creation + * gio/gappinfo.override (_wrap_g_app_info_tp_richcompare) + (_wrap_g_app_info_tp_repr): New functions. + + * tests/test_gio.py (TestAppInfo.test_eq): New test. + +2008-08-11 Paul Pogonyshev <pogonyshev@gmx.net> + + Bug 547104 – improve type wrapper creation + * gobject/pygobject.c (pygobject_register_class): Use new pygobject_inherit_slots() to propagate custom slots in normal types too. diff --git a/gio/gappinfo.override b/gio/gappinfo.override index 09a70a5..343bf57 100644 --- a/gio/gappinfo.override +++ b/gio/gappinfo.override @@ -158,3 +158,51 @@ _wrap_g_app_info_launch(PyGObject *self, PyObject *args, PyObject *kwargs) return PyBool_FromLong(ret); } +%% +override-slot GAppInfo.tp_richcompare +static PyObject * +_wrap_g_app_info_tp_richcompare(PyGObject *self, PyGObject *other, int op) +{ + PyObject *result; + + if (PyObject_TypeCheck(self, &PyGAppInfo_Type) + && PyObject_TypeCheck(other, &PyGAppInfo_Type)) { + GAppInfo *info1 = G_APP_INFO(self->obj); + GAppInfo *info2 = G_APP_INFO(other->obj); + + switch (op) { + case Py_EQ: + result = (g_app_info_equal(info1, info2) + ? Py_True : Py_False); + break; + case Py_NE: + result = (!g_app_info_equal(info1, info2) + ? Py_True : Py_False); + break; + default: + result = Py_NotImplemented; + } + } + else + result = Py_NotImplemented; + + Py_INCREF(result); + return result; +} +%% +override-slot GAppInfo.tp_repr +static PyObject * +_wrap_g_app_info_tp_repr(PyGObject *self) +{ + const char *name = g_app_info_get_name(G_APP_INFO(self->obj)); + gchar *representation; + PyObject *result; + + representation = g_strdup_printf("<%s at %p: %s>", + self->ob_type->tp_name, self, + name ? name : "UNKNOWN NAME"); + + result = PyString_FromString(representation); + g_free(representation); + return result; +} diff --git a/tests/test_gio.py b/tests/test_gio.py index d5b92b3..7500e58 100644 --- a/tests/test_gio.py +++ b/tests/test_gio.py @@ -678,6 +678,14 @@ class TestAppInfo(unittest.TestCase): self.assertEquals(self.appinfo.get_description(), "Custom definition for does-not-exist") + def test_eq(self): + info1 = gio.app_info_get_all()[0] + info2 = info1.dup() + self.assert_(info1 is not info2) + self.assertEquals(info1, info2) + + self.assertNotEqual(gio.app_info_get_all()[0], gio.app_info_get_all()[1]) + class TestVfs(unittest.TestCase): def setUp(self): self.vfs = gio.vfs_get_default() |
