summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohan Dahlin <johan@src.gnome.org>2004-07-19 11:00:18 +0000
committerJohan Dahlin <johan@src.gnome.org>2004-07-19 11:00:18 +0000
commitcfa02147247fa59b82eff91e2058d1488ff438e3 (patch)
tree9790d37c327bef30c210d161a42dc020b25a759b
parentfb6e18271f6dff9d1c4ef9f19019634371559585 (diff)
downloadpygobject-cfa02147247fa59b82eff91e2058d1488ff438e3.tar.gz
pygobject-cfa02147247fa59b82eff91e2058d1488ff438e3.tar.xz
pygobject-cfa02147247fa59b82eff91e2058d1488ff438e3.zip
Update, why do I even bother to update 3 different build systems?
* gobject/Makefile.am: * setup.py: * makefile.msc: Update, why do I even bother to update 3 different build systems? * gobject/: Split out GParamSpec, GMainLoop, GMainContext and GPointer to separate files. Also remove *.h files and go back to the old scheme (everything in pygobject.h)
-rw-r--r--gobject/Makefile.am6
-rw-r--r--gobject/gobjectmodule.c446
-rw-r--r--gobject/pygboxed.c191
-rw-r--r--gobject/pygenum.c3
-rw-r--r--gobject/pygenum.h54
-rw-r--r--gobject/pygflags.c3
-rw-r--r--gobject/pygflags.h52
-rw-r--r--gobject/pygmaincontext.c119
-rw-r--r--gobject/pygmainloop.c163
-rw-r--r--gobject/pygobject-private.h72
-rw-r--r--gobject/pygparamspec.c220
-rw-r--r--gobject/pygpointer.c215
-rw-r--r--gobject/pygtype.c3
-rw-r--r--tests/.cvsignore1
-rw-r--r--tests/enum.py9
15 files changed, 808 insertions, 749 deletions
diff --git a/gobject/Makefile.am b/gobject/Makefile.am
index ed74b42..68a7eba 100644
--- a/gobject/Makefile.am
+++ b/gobject/Makefile.am
@@ -18,10 +18,12 @@ gobject_la_SOURCES = \
gobjectmodule.c \
pygboxed.c \
pygenum.c \
- pygenum.h \
pygflags.c \
- pygflags.h \
pygobject.c \
pygobject.h \
pygobject-private.h \
+ pygmaincontext.c \
+ pygmainloop.c \
+ pygparamspec.c \
+ pygpointer.c \
pygtype.c
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 },
diff --git a/gobject/pygboxed.c b/gobject/pygboxed.c
index 31db218..39f3d1c 100644
--- a/gobject/pygboxed.c
+++ b/gobject/pygboxed.c
@@ -2,7 +2,7 @@
* pygtk- Python bindings for the GTK toolkit.
* Copyright (C) 1998-2003 James Henstridge
*
- * pygboxed.c: wrapper for GBoxed and GPointer types.
+ * pygboxed.c: wrapper for GBoxed
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -245,192 +245,3 @@ pyg_boxed_new(GType boxed_type, gpointer boxed, gboolean copy_boxed,
return (PyObject *)self;
}
-/* ------------------ G_TYPE_POINTER derivatives ------------------ */
-
-static void
-pyg_pointer_dealloc(PyGPointer *self)
-{
- self->ob_type->tp_free((PyObject *)self);
-}
-
-static int
-pyg_pointer_compare(PyGPointer *self, PyGPointer *v)
-{
- if (self->pointer == v->pointer) return 0;
- if (self->pointer > v->pointer) return -1;
- return 1;
-}
-
-static long
-pyg_pointer_hash(PyGPointer *self)
-{
- return (long)self->pointer;
-}
-
-static PyObject *
-pyg_pointer_repr(PyGPointer *self)
-{
- gchar buf[128];
-
- g_snprintf(buf, sizeof(buf), "<%s at 0x%lx>", g_type_name(self->gtype),
- (long)self->pointer);
- return PyString_FromString(buf);
-}
-
-static int
-pyg_pointer_init(PyGPointer *self, PyObject *args, PyObject *kwargs)
-{
- gchar buf[512];
-
- if (!PyArg_ParseTuple(args, ":GPointer.__init__"))
- return -1;
-
- self->pointer = NULL;
- self->gtype = 0;
-
- g_snprintf(buf, sizeof(buf), "%s can not be constructed", self->ob_type->tp_name);
- PyErr_SetString(PyExc_NotImplementedError, buf);
- return -1;
-}
-
-static void
-pyg_pointer_free(PyObject *op)
-{
- PyObject_FREE(op);
-}
-
-PyTypeObject PyGPointer_Type = {
- PyObject_HEAD_INIT(NULL)
- 0, /* ob_size */
- "gobject.GPointer", /* tp_name */
- sizeof(PyGPointer), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor)pyg_pointer_dealloc, /* tp_dealloc */
- (printfunc)0, /* tp_print */
- (getattrfunc)0, /* tp_getattr */
- (setattrfunc)0, /* tp_setattr */
- (cmpfunc)pyg_pointer_compare, /* tp_compare */
- (reprfunc)pyg_pointer_repr, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- (hashfunc)pyg_pointer_hash, /* tp_hash */
- (ternaryfunc)0, /* tp_call */
- (reprfunc)0, /* tp_str */
- (getattrofunc)0, /* tp_getattro */
- (setattrofunc)0, /* tp_setattro */
- 0, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
- NULL, /* Documentation string */
- (traverseproc)0, /* tp_traverse */
- (inquiry)0, /* tp_clear */
- (richcmpfunc)0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- (getiterfunc)0, /* tp_iter */
- (iternextfunc)0, /* tp_iternext */
- 0, /* tp_methods */
- 0, /* tp_members */
- 0, /* tp_getset */
- (PyTypeObject *)0, /* tp_base */
- (PyObject *)0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)pyg_pointer_init, /* tp_init */
- (allocfunc)0, /* tp_alloc */
- (newfunc)0, /* tp_new */
- (freefunc)pyg_pointer_free, /* tp_free */
- (inquiry)0, /* tp_is_gc */
- (PyObject *)0, /* tp_bases */
-};
-
-static GQuark pointer_type_id = 0;
-
-/**
- * pyg_register_pointer:
- * @dict: the module dictionary to store the wrapper class.
- * @class_name: the Python name for the wrapper class.
- * @pointer_type: the GType of the pointer type being wrapped.
- * @type: the wrapper class.
- *
- * Registers a wrapper for a pointer type. The wrapper class will be
- * a subclass of gobject.GPointer, and a reference to the wrapper
- * class will be stored in the provided module dictionary.
- */
-void
-pyg_register_pointer(PyObject *dict, const gchar *class_name,
- GType pointer_type, PyTypeObject *type)
-{
- PyObject *o;
-
- g_return_if_fail(dict != NULL);
- g_return_if_fail(class_name != NULL);
- g_return_if_fail(pointer_type != 0);
-
- if (!pointer_type_id)
- pointer_type_id = g_quark_from_static_string("PyGPointer::class");
-
- if (!type->tp_dealloc) type->tp_dealloc = (destructor)pyg_pointer_dealloc;
-
- type->ob_type = &PyType_Type;
- type->tp_base = &PyGPointer_Type;
-
- if (PyType_Ready(type) < 0) {
- g_warning("could not get type `%s' ready", type->tp_name);
- return;
- }
-
- PyDict_SetItemString(type->tp_dict, "__gtype__",
- o=pyg_type_wrapper_new(pointer_type));
- Py_DECREF(o);
-
- g_type_set_qdata(pointer_type, pointer_type_id, type);
-
- PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type);
-}
-
-/**
- * pyg_pointer_new:
- * @pointer_type: the GType of the pointer value.
- * @pointer: the pointer value.
- *
- * Creates a wrapper for a pointer value. Since G_TYPE_POINTER types
- * don't register any information about how to copy/free them, there
- * is no guarantee that the pointer will remain valid, and there is
- * nothing registered to release the pointer when the pointer goes out
- * of scope. This is why we don't recommend people use these types.
- *
- * Returns: the boxed wrapper.
- */
-PyObject *
-pyg_pointer_new(GType pointer_type, gpointer pointer)
-{
- PyGPointer *self;
- PyTypeObject *tp;
-
- g_return_val_if_fail(pointer_type != 0, NULL);
-
- pyg_block_threads();
-
- if (!pointer) {
- Py_INCREF(Py_None);
- pyg_unblock_threads();
- return Py_None;
- }
-
- tp = g_type_get_qdata(pointer_type, pointer_type_id);
- if (!tp)
- tp = (PyTypeObject *)&PyGPointer_Type; /* fallback */
- self = PyObject_NEW(PyGPointer, tp);
-
- pyg_unblock_threads();
-
- if (self == NULL)
- return NULL;
-
- self->pointer = pointer;
- self->gtype = pointer_type;
-
- return (PyObject *)self;
-}
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index 9615f08..ecc4dbe 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -3,7 +3,7 @@
* Copyright (C) 1998-2003 James Henstridge
* Copyright (C) 2004 Johan Dahlin
*
- * pygenum.c: GEnum and GFlag wrappers
+ * pygenum.c: GEnum wrapper
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -26,7 +26,6 @@
#endif
#include "pygobject-private.h"
-#include "pygenum.h"
static const gchar *pygenum_class_id = "PyGEnum::class";
static GQuark pygenum_class_key = 0;
diff --git a/gobject/pygenum.h b/gobject/pygenum.h
deleted file mode 100644
index 2f9d0d1..0000000
--- a/gobject/pygenum.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4 -*-
- * pygtk- Python bindings for the GTK toolkit.
- * Copyright (C) 1998-2003 James Henstridge
- * Copyright (C) 2004 Johan Dahlin
- *
- * pygenum.c: GEnum and GFlag wrappers
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef __PYGENUM_H__
-#define __PYGENUM_H__
-
-#include <Python.h>
-#include <glib-object.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-#define PyGEnum_Check(x) (g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_ENUM))
-
-typedef struct {
- PyIntObject parent;
- GType gtype;
-} PyGEnum;
-
-extern PyTypeObject PyGEnum_Type;
-
-extern PyObject * pyg_enum_add (PyObject * module,
- const char * typename,
- const char * strip_prefix,
- GType gtype);
-extern PyObject * pyg_enum_from_gtype (GType gtype,
- int value);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __PYGENUM_H__ */
diff --git a/gobject/pygflags.c b/gobject/pygflags.c
index e3816cb..d90f677 100644
--- a/gobject/pygflags.c
+++ b/gobject/pygflags.c
@@ -3,6 +3,8 @@
* Copyright (C) 1998-2003 James Henstridge
* Copyright (C) 2004 Johan Dahlin
*
+ * pygenum.c: GFlags wrapper
+ *
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
@@ -24,7 +26,6 @@
#endif
#include "pygobject-private.h"
-#include "pygflags.h"
static const gchar *pygflags_class_id = "PyGFlags::class";
static GQuark pygflags_class_key = 0;
diff --git a/gobject/pygflags.h b/gobject/pygflags.h
deleted file mode 100644
index 584cdbf..0000000
--- a/gobject/pygflags.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/* -*- Mode: C; c-basic-offset: 4 -*-
- * pygtk- Python bindings for the GTK toolkit.
- * Copyright (C) 1998-2003 James Henstridge
- * Copyright (C) 2004 Johan Dahlin
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
- * USA
- */
-
-#ifndef __PYGFLAGS_H__
-#define __PYGFLAGS_H__
-
-#include <Python.h>
-#include <glib-object.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif /* __cplusplus */
-
-typedef struct {
- PyIntObject parent;
- GType gtype;
-} PyGFlags;
-
-extern PyTypeObject PyGFlags_Type;
-
-#define PyGFlags_Check(x) (g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_FLAGS))
-
-extern PyObject * pyg_flags_add (PyObject * module,
- const char * typename,
- const char * strip_prefix,
- GType gtype);
-extern PyObject * pyg_flags_from_gtype (GType gtype,
- int value);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
-
-#endif /* __PYGFLAGS_H__ */
diff --git a/gobject/pygmaincontext.c b/gobject/pygmaincontext.c
new file mode 100644
index 0000000..7f8fdab
--- /dev/null
+++ b/gobject/pygmaincontext.c
@@ -0,0 +1,119 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ *
+ * pygmainloop.c: GMainContext wrapper
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "pygobject-private.h"
+
+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 *
+_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,
+};
diff --git a/gobject/pygmainloop.c b/gobject/pygmainloop.c
new file mode 100644
index 0000000..e0424cb
--- /dev/null
+++ b/gobject/pygmainloop.c
@@ -0,0 +1,163 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ * Copyright (C) 2004 Johan Dahlin
+ *
+ * pygmainloop.c: GMainLoop wrapper
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "pygobject-private.h"
+
+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,
+};
diff --git a/gobject/pygobject-private.h b/gobject/pygobject-private.h
index da340c7..4ab1a26 100644
--- a/gobject/pygobject-private.h
+++ b/gobject/pygobject-private.h
@@ -23,18 +23,6 @@ extern GType PY_TYPE_OBJECT;
void pyg_destroy_notify (gpointer user_data);
-typedef struct {
- PyObject_HEAD
- GMainLoop *loop;
-} PyGMainLoop;
-extern PyTypeObject PyGMainLoop_Type;
-
-typedef struct {
- PyObject_HEAD
- GMainContext *context;
-} PyGMainContext;
-extern PyTypeObject PyGMainContext_Type;
-
/* from pygtype.h */
extern PyTypeObject PyGTypeWrapper_Type;
@@ -104,9 +92,65 @@ void pyg_register_pointer (PyObject *dict, const gchar *class_name,
GType pointer_type, PyTypeObject *type);
PyObject * pyg_pointer_new (GType pointer_type, gpointer pointer);
+extern char * pyg_constant_strip_prefix(gchar *name, const gchar *strip_prefix);
+
+/* pygflags */
+typedef struct {
+ PyIntObject parent;
+ GType gtype;
+} PyGFlags;
+
+extern PyTypeObject PyGFlags_Type;
+
+#define PyGFlags_Check(x) (g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_FLAGS))
+
+extern PyObject * pyg_flags_add (PyObject * module,
+ const char * typename,
+ const char * strip_prefix,
+ GType gtype);
+extern PyObject * pyg_flags_from_gtype (GType gtype,
+ int value);
+
+/* pygenum */
+#define PyGEnum_Check(x) (g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_ENUM))
+
+typedef struct {
+ PyIntObject parent;
+ GType gtype;
+} PyGEnum;
+
+extern PyTypeObject PyGEnum_Type;
+
+extern PyObject * pyg_enum_add (PyObject * module,
+ const char * typename,
+ const char * strip_prefix,
+ GType gtype);
+extern PyObject * pyg_enum_from_gtype (GType gtype,
+ int value);
+
+/* pygmainloop */
+
+typedef struct {
+ PyObject_HEAD
+ GMainLoop *loop;
+} PyGMainLoop;
+
+extern PyTypeObject PyGMainLoop_Type;
+
+/* pygmaincontext */
+
+typedef struct {
+ PyObject_HEAD
+ GMainContext *context;
+} PyGMainContext;
+
+extern PyTypeObject PyGMainContext_Type;
+
+/* pygparamspec */
+
extern PyTypeObject PyGParamSpec_Type;
-PyObject *pyg_param_spec_new (GParamSpec *pspec);
+PyObject * pyg_param_spec_new (GParamSpec *pspec);
+
-extern char * pyg_constant_strip_prefix(gchar *name, const gchar *strip_prefix);
#endif
diff --git a/gobject/pygparamspec.c b/gobject/pygparamspec.c
new file mode 100644
index 0000000..b515baa
--- /dev/null
+++ b/gobject/pygparamspec.c
@@ -0,0 +1,220 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ * Copyright (C) 2004 Johan Dahlin
+ *
+ * pygenum.c: GEnum and GFlag wrappers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "pygobject-private.h"
+
+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);
+}
+
+PyObject *
+pyg_param_spec_getattr(PyGParamSpec *self, const gchar *attr)
+{
+ if (!strcmp(attr, "__members__")) {
+ if (G_IS_PARAM_SPEC_ENUM(self->pspec))
+ return Py_BuildValue("[sssssssss]", "__doc__", "__gtype__", "blurb",
+ "flags", "name", "nick", "owner_type",
+ "value_type", "enum_class");
+ else if (G_IS_PARAM_SPEC_FLAGS(self->pspec))
+ return Py_BuildValue("[sssssssss]", "__doc__", "__gtype__", "blurb",
+ "flags", "name", "nick", "owner_type",
+ "value_type", "flags_class");
+ else
+ 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;
+}
diff --git a/gobject/pygpointer.c b/gobject/pygpointer.c
new file mode 100644
index 0000000..b7e3cfc
--- /dev/null
+++ b/gobject/pygpointer.c
@@ -0,0 +1,215 @@
+/* -*- Mode: C; c-basic-offset: 4 -*-
+ * pygtk- Python bindings for the GTK toolkit.
+ * Copyright (C) 1998-2003 James Henstridge
+ *
+ * pygpointer.c: wrapper for GPointer
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "pygobject-private.h"
+
+static void
+pyg_pointer_dealloc(PyGPointer *self)
+{
+ self->ob_type->tp_free((PyObject *)self);
+}
+
+static int
+pyg_pointer_compare(PyGPointer *self, PyGPointer *v)
+{
+ if (self->pointer == v->pointer) return 0;
+ if (self->pointer > v->pointer) return -1;
+ return 1;
+}
+
+static long
+pyg_pointer_hash(PyGPointer *self)
+{
+ return (long)self->pointer;
+}
+
+static PyObject *
+pyg_pointer_repr(PyGPointer *self)
+{
+ gchar buf[128];
+
+ g_snprintf(buf, sizeof(buf), "<%s at 0x%lx>", g_type_name(self->gtype),
+ (long)self->pointer);
+ return PyString_FromString(buf);
+}
+
+static int
+pyg_pointer_init(PyGPointer *self, PyObject *args, PyObject *kwargs)
+{
+ gchar buf[512];
+
+ if (!PyArg_ParseTuple(args, ":GPointer.__init__"))
+ return -1;
+
+ self->pointer = NULL;
+ self->gtype = 0;
+
+ g_snprintf(buf, sizeof(buf), "%s can not be constructed", self->ob_type->tp_name);
+ PyErr_SetString(PyExc_NotImplementedError, buf);
+ return -1;
+}
+
+static void
+pyg_pointer_free(PyObject *op)
+{
+ PyObject_FREE(op);
+}
+
+PyTypeObject PyGPointer_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ "gobject.GPointer", /* tp_name */
+ sizeof(PyGPointer), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ /* methods */
+ (destructor)pyg_pointer_dealloc, /* tp_dealloc */
+ (printfunc)0, /* tp_print */
+ (getattrfunc)0, /* tp_getattr */
+ (setattrfunc)0, /* tp_setattr */
+ (cmpfunc)pyg_pointer_compare, /* tp_compare */
+ (reprfunc)pyg_pointer_repr, /* tp_repr */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ (hashfunc)pyg_pointer_hash, /* tp_hash */
+ (ternaryfunc)0, /* tp_call */
+ (reprfunc)0, /* tp_str */
+ (getattrofunc)0, /* tp_getattro */
+ (setattrofunc)0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
+ NULL, /* Documentation string */
+ (traverseproc)0, /* tp_traverse */
+ (inquiry)0, /* tp_clear */
+ (richcmpfunc)0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ (getiterfunc)0, /* tp_iter */
+ (iternextfunc)0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ (PyTypeObject *)0, /* tp_base */
+ (PyObject *)0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)pyg_pointer_init, /* tp_init */
+ (allocfunc)0, /* tp_alloc */
+ (newfunc)0, /* tp_new */
+ (freefunc)pyg_pointer_free, /* tp_free */
+ (inquiry)0, /* tp_is_gc */
+ (PyObject *)0, /* tp_bases */
+};
+
+static GQuark pointer_type_id = 0;
+
+/**
+ * pyg_register_pointer:
+ * @dict: the module dictionary to store the wrapper class.
+ * @class_name: the Python name for the wrapper class.
+ * @pointer_type: the GType of the pointer type being wrapped.
+ * @type: the wrapper class.
+ *
+ * Registers a wrapper for a pointer type. The wrapper class will be
+ * a subclass of gobject.GPointer, and a reference to the wrapper
+ * class will be stored in the provided module dictionary.
+ */
+void
+pyg_register_pointer(PyObject *dict, const gchar *class_name,
+ GType pointer_type, PyTypeObject *type)
+{
+ PyObject *o;
+
+ g_return_if_fail(dict != NULL);
+ g_return_if_fail(class_name != NULL);
+ g_return_if_fail(pointer_type != 0);
+
+ if (!pointer_type_id)
+ pointer_type_id = g_quark_from_static_string("PyGPointer::class");
+
+ if (!type->tp_dealloc) type->tp_dealloc = (destructor)pyg_pointer_dealloc;
+
+ type->ob_type = &PyType_Type;
+ type->tp_base = &PyGPointer_Type;
+
+ if (PyType_Ready(type) < 0) {
+ g_warning("could not get type `%s' ready", type->tp_name);
+ return;
+ }
+
+ PyDict_SetItemString(type->tp_dict, "__gtype__",
+ o=pyg_type_wrapper_new(pointer_type));
+ Py_DECREF(o);
+
+ g_type_set_qdata(pointer_type, pointer_type_id, type);
+
+ PyDict_SetItemString(dict, (char *)class_name, (PyObject *)type);
+}
+
+/**
+ * pyg_pointer_new:
+ * @pointer_type: the GType of the pointer value.
+ * @pointer: the pointer value.
+ *
+ * Creates a wrapper for a pointer value. Since G_TYPE_POINTER types
+ * don't register any information about how to copy/free them, there
+ * is no guarantee that the pointer will remain valid, and there is
+ * nothing registered to release the pointer when the pointer goes out
+ * of scope. This is why we don't recommend people use these types.
+ *
+ * Returns: the boxed wrapper.
+ */
+PyObject *
+pyg_pointer_new(GType pointer_type, gpointer pointer)
+{
+ PyGPointer *self;
+ PyTypeObject *tp;
+
+ g_return_val_if_fail(pointer_type != 0, NULL);
+
+ pyg_block_threads();
+
+ if (!pointer) {
+ Py_INCREF(Py_None);
+ pyg_unblock_threads();
+ return Py_None;
+ }
+
+ tp = g_type_get_qdata(pointer_type, pointer_type_id);
+ if (!tp)
+ tp = (PyTypeObject *)&PyGPointer_Type; /* fallback */
+ self = PyObject_NEW(PyGPointer, tp);
+
+ pyg_unblock_threads();
+
+ if (self == NULL)
+ return NULL;
+
+ self->pointer = pointer;
+ self->gtype = pointer_type;
+
+ return (PyObject *)self;
+}
diff --git a/gobject/pygtype.c b/gobject/pygtype.c
index eff5e0d..23e3066 100644
--- a/gobject/pygtype.c
+++ b/gobject/pygtype.c
@@ -22,9 +22,6 @@
#include "pygobject-private.h"
-#include "pygenum.h"
-#include "pygflags.h"
-
/* -------------- __gtype__ objects ---------------------------- */
typedef struct {
diff --git a/tests/.cvsignore b/tests/.cvsignore
index 282522d..12664c7 100644
--- a/tests/.cvsignore
+++ b/tests/.cvsignore
@@ -1,2 +1,3 @@
Makefile
Makefile.in
+*.pyc
diff --git a/tests/enum.py b/tests/enum.py
index 11b73ea..ed9b98f 100644
--- a/tests/enum.py
+++ b/tests/enum.py
@@ -44,6 +44,15 @@ class EnumTest(unittest.TestCase):
obj = atk.NoOpObject(gobject.GObject())
assert obj.get_role() == atk.ROLE_INVALID
+ def testGParam(self):
+ win = gtk.Window()
+ enums = filter(lambda x: gobject.type_is_a(x.value_type, gobject.GEnum),
+ gobject.list_properties(win))
+ assert enums
+ enum = enums[0]
+ assert hasattr(enum, 'enum_class')
+ assert issubclass(enum.enum_class, gobject.GEnum)
+
class FlagsTest(unittest.TestCase):
def testFlags(self):
assert issubclass(gobject.GFlags, int)