diff options
| author | Johan Dahlin <johan@src.gnome.org> | 2005-07-05 20:38:56 +0000 |
|---|---|---|
| committer | Johan Dahlin <johan@src.gnome.org> | 2005-07-05 20:38:56 +0000 |
| commit | 8914f109dc0515d8927c76b29ec5b46317965b68 (patch) | |
| tree | 682f2eb1919ba86d87a98d14a22616e201a12552 /gobject | |
| parent | 4dd8caf2aae815a22e07f035839bf43739d03feb (diff) | |
| download | pygobject-8914f109dc0515d8927c76b29ec5b46317965b68.tar.gz pygobject-8914f109dc0515d8927c76b29ec5b46317965b68.tar.xz pygobject-8914f109dc0515d8927c76b29ec5b46317965b68.zip | |
Add GType.is_a and deprecate gobject.type_* Update tests and make
* gobject/gobjectmodule.c: (pyg_type_name), (pyg_type_from_name),
(pyg_type_parent), (pyg_type_is_a), (pyg_type_children),
(pyg_type_interfaces), (get_type_name_for_class), (initgobject):
* gobject/pygtype.c: (_wrap_g_type_is_a), (pyg_type_wrapper_init):
* tests/test_enum.py:
* tests/test_gtype.py:
* tests/test_unknown.py:
Add GType.is_a and deprecate gobject.type_*
Update tests
and make GType.is_a/gobject.type_is_a return a bool instead of int
Diffstat (limited to 'gobject')
| -rw-r--r-- | gobject/gobjectmodule.c | 39 | ||||
| -rw-r--r-- | gobject/pygtype.c | 43 |
2 files changed, 75 insertions, 7 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index e24313e..d054635 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -238,6 +238,11 @@ pyg_type_name (PyObject *self, PyObject *args) GType type; const gchar *name; + if (PyErr_Warn(PyExc_DeprecationWarning, + "gobject.type_name is deprecated; " + "use GType.name instead")) + return NULL; + if (!PyArg_ParseTuple(args, "O:gobject.type_name", >ype)) return NULL; if ((type = pyg_type_from_object(gtype)) == 0) @@ -255,6 +260,11 @@ pyg_type_from_name (PyObject *self, PyObject *args) const gchar *name; GType type; + if (PyErr_Warn(PyExc_DeprecationWarning, + "gobject.type_from_name is deprecated; " + "use GType.from_name instead")) + return NULL; + if (!PyArg_ParseTuple(args, "s:gobject.type_from_name", &name)) return NULL; type = g_type_from_name(name); @@ -270,6 +280,11 @@ pyg_type_parent (PyObject *self, PyObject *args) PyObject *gtype; GType type, parent; + if (PyErr_Warn(PyExc_DeprecationWarning, + "gobject.type_parent is deprecated; " + "use GType.parent instead")) + return NULL; + if (!PyArg_ParseTuple(args, "O:gobject.type_parent", >ype)) return NULL; if ((type = pyg_type_from_object(gtype)) == 0) @@ -287,13 +302,18 @@ pyg_type_is_a (PyObject *self, PyObject *args) PyObject *gtype, *gparent; GType type, parent; + if (PyErr_Warn(PyExc_DeprecationWarning, + "gobject.type_is_a is deprecated; " + "use GType.is_a instead")) + return NULL; + if (!PyArg_ParseTuple(args, "OO:gobject.type_is_a", >ype, &gparent)) return NULL; if ((type = pyg_type_from_object(gtype)) == 0) return NULL; if ((parent = pyg_type_from_object(gparent)) == 0) return NULL; - return PyInt_FromLong(g_type_is_a(type, parent)); + return PyBool_FromLong(g_type_is_a(type, parent)); } static PyObject * @@ -303,6 +323,11 @@ pyg_type_children (PyObject *self, PyObject *args) GType type, *children; guint n_children, i; + if (PyErr_Warn(PyExc_DeprecationWarning, + "gobject.type_children is deprecated; " + "use GType.children instead")) + return NULL; + if (!PyArg_ParseTuple(args, "O:gobject.type_children", >ype)) return NULL; if ((type = pyg_type_from_object(gtype)) == 0) @@ -329,6 +354,11 @@ pyg_type_interfaces (PyObject *self, PyObject *args) GType type, *interfaces; guint n_interfaces, i; + if (PyErr_Warn(PyExc_DeprecationWarning, + "gobject.type_interfaces is deprecated; " + "use GType.interfaces instead")) + return NULL; + if (!PyArg_ParseTuple(args, "O:gobject.type_interfaces", >ype)) return NULL; if ((type = pyg_type_from_object(gtype)) == 0) @@ -962,7 +992,7 @@ get_type_name_for_class(PyTypeObject *class) gint i, name_serial; char name_serial_str[16]; PyObject *module; - char *type_name = NULL; + char *type_name; /* make name for new GType */ name_serial = 1; @@ -2512,8 +2542,6 @@ DL_EXPORT(void) initgobject(void) { PyObject *m, *d, *o, *tuple; - - PyGTypeWrapper_Type.ob_type = &PyType_Type; PyGParamSpec_Type.ob_type = &PyType_Type; m = Py_InitModule("gobject", pygobject_functions); @@ -2532,8 +2560,7 @@ initgobject(void) pyginterface_info_key = g_quark_from_static_string("PyGInterface::info"); pygpointer_class_key = g_quark_from_static_string("PyGPointer::class"); - PyType_Ready(&PyGTypeWrapper_Type); - PyDict_SetItemString(d, "GType", (PyObject *)&PyGTypeWrapper_Type); + REGISTER_TYPE(d, PyGTypeWrapper_Type, "GType"); PY_TYPE_OBJECT = g_boxed_type_register_static("PyObject", pyobject_copy, diff --git a/gobject/pygtype.c b/gobject/pygtype.c index 4e5bd33..843060f 100644 --- a/gobject/pygtype.c +++ b/gobject/pygtype.c @@ -215,6 +215,20 @@ _wrap_g_type_from_name(PyGTypeWrapper *_, PyObject *args) return pyg_type_wrapper_new(type); } +static PyObject* +_wrap_g_type_is_a(PyGTypeWrapper *self, PyObject *args) +{ + PyObject *gparent; + GType parent; + + if (!PyArg_ParseTuple(args, "O:GType.is_a", &gparent)) + return NULL; + else if ((parent = pyg_type_from_object(gparent)) == 0) + return NULL; + + return PyBool_FromLong(g_type_is_a(self->type, parent)); +} + static PyMethodDef _PyGTypeWrapper_methods[] = { { "is_interface", (PyCFunction)_wrap_g_type_is_interface, METH_NOARGS }, { "is_classed", (PyCFunction)_wrap_g_type_is_classed, METH_NOARGS }, @@ -226,9 +240,30 @@ static PyMethodDef _PyGTypeWrapper_methods[] = { { "is_value_type", (PyCFunction)_wrap_g_type_is_value_type, METH_NOARGS }, { "has_value_table", (PyCFunction)_wrap_g_type_has_value_table, METH_NOARGS }, { "from_name", (PyCFunction)_wrap_g_type_from_name, METH_VARARGS | METH_STATIC }, + { "is_a", (PyCFunction)_wrap_g_type_is_a, METH_VARARGS }, { NULL, 0, 0 } }; +static int +pyg_type_wrapper_init(PyGTypeWrapper *self, PyObject *args, PyObject *kwargs) +{ + static char *kwlist[] = { "object", NULL }; + PyObject *py_object; + GType type; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, + "O:GType.__init__", + kwlist, &py_object)) + return -1; + + if (!(type = pyg_type_from_object(py_object))) + return -1; + + self->type = type; + + return 0; +} + PyTypeObject PyGTypeWrapper_Type = { PyObject_HEAD_INIT(NULL) 0, @@ -260,7 +295,13 @@ PyTypeObject PyGTypeWrapper_Type = { (iternextfunc)0, _PyGTypeWrapper_methods, 0, - _PyGTypeWrapper_getsets + _PyGTypeWrapper_getsets, + NULL, + NULL, + (descrgetfunc)0, + (descrsetfunc)0, + 0, + (initproc)pyg_type_wrapper_init }; /** |
