diff options
Diffstat (limited to 'gobject/gobjectmodule.c')
-rw-r--r-- | gobject/gobjectmodule.c | 446 |
1 files changed, 15 insertions, 431 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 4d888b8..9de16a5 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -26,9 +26,6 @@ #include "pygobject-private.h" -#include "pygenum.h" -#include "pygflags.h" - static PyObject *gerror_exc = NULL; static const gchar *pyginterface_type_id = "PyGInterface::type"; GQuark pyginterface_type_key = 0; @@ -80,191 +77,6 @@ pyg_destroy_notify(gpointer user_data) pyg_unblock_threads(); } -/* -------------- GParamSpec objects ---------------------------- */ - -static int -pyg_param_spec_compare(PyGParamSpec *self, PyGParamSpec *v) -{ - if (self->pspec == v->pspec) return 0; - if (self->pspec > v->pspec) return -1; - return 1; -} - -static long -pyg_param_spec_hash(PyGParamSpec *self) -{ - return (long)self->pspec; -} - -static PyObject * -pyg_param_spec_repr(PyGParamSpec *self) -{ - char buf[80]; - - g_snprintf(buf, sizeof(buf), "<%s '%s'>", - G_PARAM_SPEC_TYPE_NAME(self->pspec), - g_param_spec_get_name(self->pspec)); - return PyString_FromString(buf); -} - -static void -pyg_param_spec_dealloc(PyGParamSpec *self) -{ - g_param_spec_unref(self->pspec); - PyObject_DEL(self); -} - -static PyObject * -pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr) -{ - if (!strcmp(attr, "__members__")) { - return Py_BuildValue("[ssssssss]", "__doc__", "__gtype__", "blurb", - "flags", "name", "nick", "owner_type", - "value_type"); - } else if (!strcmp(attr, "__gtype__")) { - return pyg_type_wrapper_new(G_PARAM_SPEC_TYPE(self->pspec)); - } else if (!strcmp(attr, "name")) { - const gchar *name = g_param_spec_get_name(self->pspec); - - if (name) - return PyString_FromString(name); - Py_INCREF(Py_None); - return Py_None; - } else if (!strcmp(attr, "nick")) { - const gchar *nick = g_param_spec_get_nick(self->pspec); - - if (nick) - return PyString_FromString(nick); - Py_INCREF(Py_None); - return Py_None; - } else if (!strcmp(attr, "blurb") || !strcmp(attr, "__doc__")) { - const gchar *blurb = g_param_spec_get_blurb(self->pspec); - - if (blurb) - return PyString_FromString(blurb); - Py_INCREF(Py_None); - return Py_None; - } else if (!strcmp(attr, "flags")) { - return PyInt_FromLong(self->pspec->flags); - } else if (!strcmp(attr, "value_type")) { - return pyg_type_wrapper_new(self->pspec->value_type); - } else if (!strcmp(attr, "owner_type")) { - return pyg_type_wrapper_new(self->pspec->owner_type); - } else if (!strcmp(attr, "default_value")) { - GParamSpec *pspec = self->pspec; - if (G_IS_PARAM_SPEC_CHAR(pspec)) { - return PyString_FromFormat("%c", G_PARAM_SPEC_CHAR(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_UCHAR(pspec)) { - return PyString_FromFormat("%c", G_PARAM_SPEC_UCHAR(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_BOOLEAN(pspec)) { - PyObject *retval = G_PARAM_SPEC_BOOLEAN(pspec)->default_value ? Py_True : Py_False; - Py_INCREF(retval); - return retval; - } else if (G_IS_PARAM_SPEC_INT(pspec)) { - return PyInt_FromLong(G_PARAM_SPEC_INT(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_UINT(pspec)) { - return PyInt_FromLong(G_PARAM_SPEC_UINT(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_LONG(pspec)) { - return PyLong_FromLong(G_PARAM_SPEC_LONG(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_ULONG(pspec)) { - return PyLong_FromLong(G_PARAM_SPEC_ULONG(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_INT64(pspec)) { - return PyInt_FromLong(G_PARAM_SPEC_INT64(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_UINT64(pspec)) { - return PyInt_FromLong(G_PARAM_SPEC_UINT64(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_UNICHAR(pspec)) { - return PyString_FromFormat("%c", G_PARAM_SPEC_UNICHAR(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_ENUM(pspec)) { - return PyInt_FromLong(G_PARAM_SPEC_ENUM(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_FLAGS(pspec)) { - return PyInt_FromLong(G_PARAM_SPEC_FLAGS(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_FLOAT(pspec)) { - return PyFloat_FromDouble(G_PARAM_SPEC_FLOAT(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_DOUBLE(pspec)) { - return PyFloat_FromDouble(G_PARAM_SPEC_DOUBLE(pspec)->default_value); - } else if (G_IS_PARAM_SPEC_STRING(pspec)) { - if (G_PARAM_SPEC_STRING(pspec)->default_value) { - return PyString_FromString(G_PARAM_SPEC_STRING(pspec)->default_value); - } - } - - /* If we don't know how to convert it, just set it to None - * for consistency - */ - Py_INCREF(Py_None); - return Py_None; - } else if (!strcmp(attr, "enum_class")) { - if (G_IS_PARAM_SPEC_ENUM(self->pspec)) { - GQuark quark; - PyObject *pyclass; - - quark = g_quark_from_static_string("PyGEnum::class"); - pyclass = (PyObject*)g_type_get_qdata(G_ENUM_CLASS_TYPE(G_PARAM_SPEC_ENUM(self->pspec)->enum_class), quark); - g_assert(pyclass != NULL); - - return pyclass; - } - } else if (!strcmp(attr, "flags_class")) { - if (G_IS_PARAM_SPEC_FLAGS(self->pspec)) { - GQuark quark; - PyObject *pyclass; - - quark = g_quark_from_static_string("PyGFlags::class"); - pyclass = (PyObject*)g_type_get_qdata(G_FLAGS_CLASS_TYPE(G_PARAM_SPEC_FLAGS(self->pspec)->flags_class), quark); - g_assert(pyclass != NULL); - - return pyclass; - } - } - - PyErr_SetString(PyExc_AttributeError, attr); - return NULL; -} - -PyTypeObject PyGParamSpec_Type = { - PyObject_HEAD_INIT(NULL) - 0, - "gobject.GParamSpec", - sizeof(PyGParamSpec), - 0, - (destructor)pyg_param_spec_dealloc, - (printfunc)0, - (getattrfunc)pyg_param_spec_getattr, - (setattrfunc)0, - (cmpfunc)pyg_param_spec_compare, - (reprfunc)pyg_param_spec_repr, - 0, - 0, - 0, - (hashfunc)pyg_param_spec_hash, - (ternaryfunc)0, - (reprfunc)0, - 0L,0L,0L,0L, - NULL -}; - -/** - * pyg_param_spec_new: - * @pspec: a GParamSpec. - * - * Creates a wrapper for a GParamSpec. - * - * Returns: the GParamSpec wrapper. - */ -PyObject * -pyg_param_spec_new(GParamSpec *pspec) -{ - PyGParamSpec *self; - - self = (PyGParamSpec *)PyObject_NEW(PyGParamSpec, - &PyGParamSpec_Type); - if (self == NULL) - return NULL; - - self->pspec = g_param_spec_ref(pspec); - return (PyObject *)self; -} - /* ---------------- GBoxed functions -------------------- */ @@ -390,249 +202,6 @@ pyg_register_interface(PyObject *dict, const gchar *class_name, /* -------------- GMainContext objects ---------------------------- */ -static int -pyg_main_context_new(PyGMainContext *self) -{ - self->context = g_main_context_new(); - return 0; -} - -static int -pyg_main_context_compare(PyGMainContext *self, PyGMainContext *v) -{ - if (self->context == v->context) return 0; - if (self->context > v->context) return -1; - return 1; -} - -static PyObject * -pyg_main_context_default (PyObject *unused) -{ - PyGMainContext *self; - - self = (PyGMainContext *)PyObject_NEW(PyGMainContext, - &PyGMainContext_Type); - if (self == NULL) - return NULL; - - self->context = g_main_context_default(); - return (PyObject *)self; - -} - -static PyObject * -_wrap_g_main_context_iteration (PyGMainContext *self, PyObject *args) -{ - PyObject *py_ret; - gboolean may_block = TRUE; - - if (!PyArg_ParseTuple(args, "|b:GMainContext.iteration", - &may_block)) - return NULL; - - pyg_unblock_threads(); - py_ret = g_main_context_iteration(self->context, may_block) - ? Py_True : Py_False; - pyg_block_threads(); - - Py_INCREF(py_ret); - return py_ret; -} - -static PyObject * -_wrap_g_main_context_pending (PyGMainContext *self) -{ - PyObject *py_ret; - - py_ret = g_main_context_pending(self->context) ? Py_True : Py_False; - - Py_INCREF(py_ret); - return py_ret; -} - -static PyMethodDef _PyGMainContext_methods[] = { - { "iteration", (PyCFunction)_wrap_g_main_context_iteration, METH_VARARGS }, - { "pending", (PyCFunction)_wrap_g_main_context_pending, METH_NOARGS }, - { NULL, NULL, 0 } -}; - -PyTypeObject PyGMainContext_Type = { - PyObject_HEAD_INIT(NULL) - 0, - "gobject.MainContext", - sizeof(PyGMainContext), - 0, - /* methods */ - (destructor)0, - (printfunc)0, - (getattrfunc)0, - (setattrfunc)0, - (cmpfunc)pyg_main_context_compare, - (reprfunc)0, - 0, - 0, - 0, - (hashfunc)0, - (ternaryfunc)0, - (reprfunc)0, - (getattrofunc)0, - (setattrofunc)0, - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - NULL, - (traverseproc)0, - (inquiry)0, - (richcmpfunc)0, - 0, - (getiterfunc)0, - (iternextfunc)0, - _PyGMainContext_methods, - 0, - 0, - NULL, - NULL, - (descrgetfunc)0, - (descrsetfunc)0, - 0, - (initproc)pyg_main_context_new, -}; - -/* -------------- GMainLoop objects ---------------------------- */ - -static int -pyg_main_loop_new(PyGMainLoop *self, PyObject *args, PyObject *kwargs) -{ - - static char *kwlist[] = { "context", "is_running", NULL }; - PyObject *py_context = Py_None; - int is_running; - GMainContext *context; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, - "|Ob:GMainLoop.__init__", - kwlist, &py_context, &is_running)) - return -1; - - if (!PyObject_TypeCheck(py_context, &PyGMainContext_Type) && - py_context != Py_None) { - PyErr_SetString(PyExc_TypeError, - "context must be a gobject.GMainContext or None"); - return -1; - } - - if (py_context != Py_None) { - context = ((PyGMainContext*)py_context)->context; - } else { - context = NULL; - } - - self->loop = g_main_loop_new(context, is_running); - return 0; -} - -static int -pyg_main_loop_compare(PyGMainLoop *self, PyGMainLoop *v) -{ - if (self->loop == v->loop) return 0; - if (self->loop > v->loop) return -1; - return 1; -} - -static PyObject * -_wrap_g_main_loop_get_context (PyGMainLoop *loop) -{ - PyGMainContext *self; - - self = (PyGMainContext *)PyObject_NEW(PyGMainContext, - &PyGMainContext_Type); - - self->context = g_main_loop_get_context(loop->loop); - - if (self->context == NULL) - return NULL; - - return (PyObject *)self; -} - -static PyObject * -_wrap_g_main_loop_is_running (PyGMainLoop *self) -{ - PyObject *py_ret; - - py_ret = g_main_loop_is_running(self->loop) ? Py_True : Py_False; - Py_INCREF(py_ret); - return py_ret; - -} - -static PyObject * -_wrap_g_main_loop_quit (PyGMainLoop *self) -{ - g_main_loop_quit(self->loop); - - Py_INCREF(Py_None); - return Py_None; -} - -static PyObject * -_wrap_g_main_loop_run (PyGMainLoop *self) -{ - pyg_unblock_threads(); - g_main_loop_run(self->loop); - pyg_block_threads(); - - Py_INCREF(Py_None); - return Py_None; -} - -static PyMethodDef _PyGMainLoop_methods[] = { - { "get_context", (PyCFunction)_wrap_g_main_loop_get_context, METH_NOARGS }, - { "is_running", (PyCFunction)_wrap_g_main_loop_is_running, METH_NOARGS }, - { "quit", (PyCFunction)_wrap_g_main_loop_quit, METH_NOARGS }, - { "run", (PyCFunction)_wrap_g_main_loop_run, METH_NOARGS }, - { NULL, NULL, 0 } -}; - -PyTypeObject PyGMainLoop_Type = { - PyObject_HEAD_INIT(NULL) - 0, - "gobject.MainLoop", - sizeof(PyGMainLoop), - 0, - /* methods */ - (destructor)0, - (printfunc)0, - (getattrfunc)0, - (setattrfunc)0, - (cmpfunc)pyg_main_loop_compare, - (reprfunc)0, - 0, - 0, - 0, - (hashfunc)0, - (ternaryfunc)0, - (reprfunc)0, - (getattrofunc)0, - (setattrofunc)0, - 0, - Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, - NULL, - (traverseproc)0, - (inquiry)0, - (richcmpfunc)0, - 0, - (getiterfunc)0, - (iternextfunc)0, - _PyGMainLoop_methods, - 0, - 0, - NULL, - NULL, - (descrgetfunc)0, - (descrsetfunc)0, - 0, - (initproc)pyg_main_loop_new, -}; /* ---------------- gobject module functions -------------------- */ @@ -1870,6 +1439,21 @@ pyg_source_remove(PyObject *self, PyObject *args) return ret; } +static PyObject * +pyg_main_context_default (PyObject *unused) +{ + PyGMainContext *self; + + self = (PyGMainContext *)PyObject_NEW(PyGMainContext, + &PyGMainContext_Type); + if (self == NULL) + return NULL; + + self->context = g_main_context_default(); + return (PyObject *)self; + +} + static PyMethodDef pygobject_functions[] = { { "type_name", pyg_type_name, METH_VARARGS }, { "type_from_name", pyg_type_from_name, METH_VARARGS }, |