From fbd3828e7ff974eb61197767e8fb630ac21d17bf Mon Sep 17 00:00:00 2001 From: Johan Dahlin Date: Fri, 26 Aug 2005 18:12:20 +0000 Subject: Refactor to allow us to list signals on interfaces. * gobject/gobjectmodule.c (pyg_signal_list_ids): Refactor to allow us to list signals on interfaces. * tests/test_signal.py (TestList): Two new tests. --- ChangeLog | 7 +++++++ gobject/gobjectmodule.c | 36 ++++++++++++++++++------------------ tests/test_signal.py | 10 ++++++++++ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/ChangeLog b/ChangeLog index 31c8cf15..7a291b88 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2005-08-26 Johan Dahlin + + * gobject/gobjectmodule.c (pyg_signal_list_ids): Refactor to + allow us to list signals on interfaces. + + * tests/test_signal.py (TestList): Two new tests. + 2005-08-25 Gustavo J. A. M. Carneiro * gobject/gobjectmodule.c (pyg_type_register): Don't g_free diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index c4b5e9ce..078201c8 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -1315,12 +1315,12 @@ pyg_signal_list_names (PyObject *self, PyObject *args, PyObject *kwargs) { static char *kwlist[] = { "type", NULL }; PyObject *py_itype, *list; - GObjectClass *class; + GObjectClass *class = NULL; GType itype; guint n; guint *ids; guint i; - + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O:gobject.signal_list_names", kwlist, &py_itype)) @@ -1328,31 +1328,31 @@ pyg_signal_list_names (PyObject *self, PyObject *args, PyObject *kwargs) if ((itype = pyg_type_from_object(py_itype)) == 0) return NULL; - if (!G_TYPE_IS_INSTANTIATABLE(itype) && !G_TYPE_IS_INTERFACE(itype)) { + if (G_TYPE_IS_INSTANTIATABLE(itype)) { + class = g_type_class_ref(itype); + if (!class) { + PyErr_SetString(PyExc_RuntimeError, + "could not get a reference to type class"); + return NULL; + } + } else if (!G_TYPE_IS_INTERFACE(itype)) { PyErr_SetString(PyExc_TypeError, "type must be instantiable or an interface"); return NULL; } - - class = g_type_class_ref(itype); - if (!class) { - PyErr_SetString(PyExc_RuntimeError, - "could not get a reference to type class"); - return NULL; - } + ids = g_signal_list_ids(itype, &n); list = PyTuple_New((gint)n); - if (list == NULL) { - g_free(ids); - g_type_class_unref(class); - return NULL; + if (list != NULL) { + for (i = 0; i < n; i++) + PyTuple_SetItem(list, i, + PyString_FromString(g_signal_name(ids[i]))); } - - for (i = 0; i < n; i++) - PyTuple_SetItem(list, i, PyString_FromString(g_signal_name(ids[i]))); + g_free(ids); - g_type_class_unref(class); + if (class) + g_type_class_unref(class); return list; } diff --git a/tests/test_signal.py b/tests/test_signal.py index 8ceeef5f..5513f2f1 100644 --- a/tests/test_signal.py +++ b/tests/test_signal.py @@ -106,6 +106,16 @@ class TestOldStyleOverride(unittest.TestCase): self.assertEqual(b.adjusted, False) b.set_scroll_adjustments(gtk.Adjustment(), gtk.Adjustment()) self.assertEqual(b.adjusted, True) + +class TestList(unittest.TestCase): + def testListObject(self): + self.assertEqual(gobject.signal_list_names(C), ('my-signal',)) + + def testListInterface(self): + signals = gobject.signal_list_names(gtk.Editable) + self.failUnless('changed' in signals) + self.failUnless('insert-text' in signals) + self.failUnless('delete-text' in signals) if __name__ == '__main__': unittest.main() -- cgit v1.2.1