diff options
author | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2005-01-08 12:47:05 +0000 |
---|---|---|
committer | Gustavo J. A. M. Carneiro <gjc@src.gnome.org> | 2005-01-08 12:47:05 +0000 |
commit | 8499846c9ade25423a3d144b24849dd8316348d0 (patch) | |
tree | 176226035c844beba3aea9c986ee7713a3e3f4c3 | |
parent | b680bf2e2078b6173be059dbe982c6618fa06871 (diff) | |
download | pygobject-8499846c9ade25423a3d144b24849dd8316348d0.tar.gz pygobject-8499846c9ade25423a3d144b24849dd8316348d0.tar.xz pygobject-8499846c9ade25423a3d144b24849dd8316348d0.zip |
[Bug 145314] Overriding GTK+ virtual methods
-rw-r--r-- | gobject/gobjectmodule.c | 39 | ||||
-rw-r--r-- | gobject/pygobject.h | 5 |
2 files changed, 43 insertions, 1 deletions
diff --git a/gobject/gobjectmodule.c b/gobject/gobjectmodule.c index 89ada7d..bbd152e 100644 --- a/gobject/gobjectmodule.c +++ b/gobject/gobjectmodule.c @@ -30,6 +30,8 @@ static PyObject *gerror_exc = NULL; static const gchar *pyginterface_type_id = "PyGInterface::type"; GQuark pyginterface_type_key = 0; +static const gchar *pygobject_class_init_id = "PyGObject::class-init"; +GQuark pygobject_class_init_key = 0; static void pyg_flags_add_constants(PyObject *module, GType flags_type, const gchar *strip_prefix); @@ -847,6 +849,31 @@ add_properties (GType instance_type, PyObject *properties) return ret; } +static void +pyg_register_class_init(GType gtype, PyGClassInitFunc class_init) +{ + g_type_set_qdata(gtype, pygobject_class_init_key, class_init); +} + +static int +pyg_run_class_init(GType gtype, gpointer gclass, PyTypeObject *pyclass) +{ + PyGClassInitFunc class_init; + GType parent_type; + int rv; + + parent_type = g_type_parent(gtype); + if (parent_type) { + rv = pyg_run_class_init(parent_type, gclass, pyclass); + if (rv) return rv; + } + class_init = g_type_get_qdata(gtype, pygobject_class_init_key); + if (class_init) + return class_init(gclass, pyclass); + return 0; +} + + static PyObject * pyg_type_register(PyObject *self, PyObject *args) { @@ -856,6 +883,7 @@ pyg_type_register(PyObject *self, PyObject *args) gchar *type_name = NULL; gint i, name_serial; GTypeQuery query; + gpointer gclass; GTypeInfo type_info = { 0, /* class_size */ @@ -982,6 +1010,12 @@ pyg_type_register(PyObject *self, PyObject *args) PyErr_Clear(); } + gclass = g_type_class_ref(instance_type); + if (pyg_run_class_init(instance_type, gclass, class)) { + g_type_class_unref(gclass); + return NULL; + } + g_type_class_unref(gclass); Py_INCREF(Py_None); return Py_None; } @@ -2074,7 +2108,8 @@ struct _PyGObject_Functions pygobject_api_functions = { FALSE, /* threads_enabled */ pyg_enable_threads, pyg_gil_state_ensure_py23, - pyg_gil_state_release_py23 + pyg_gil_state_release_py23, + pyg_register_class_init, }; #define REGISTER_TYPE(d, type, name) \ @@ -2125,6 +2160,8 @@ initgobject(void) pyg_object_descr_doc_get()); pyginterface_type_key = g_quark_from_static_string(pyginterface_type_id); + pygobject_class_init_key = g_quark_from_static_string(pygobject_class_init_id); + REGISTER_GTYPE(d, PyGBoxed_Type, "GBoxed", G_TYPE_BOXED); REGISTER_GTYPE(d, PyGPointer_Type, "GPointer", G_TYPE_POINTER); PyGEnum_Type.tp_base = &PyInt_Type; diff --git a/gobject/pygobject.h b/gobject/pygobject.h index 2ccd047..ae399d1 100644 --- a/gobject/pygobject.h +++ b/gobject/pygobject.h @@ -66,6 +66,9 @@ typedef struct { #define PyGParamSpec_Get(v) (((PyGParamSpec *)v)->pspec) #define PyGParamSpec_Check(v) (PyObject_TypeCheck(v, &PyGParamSpec_Type)) +typedef int (*PyGClassInitFunc) (gpointer gclass, PyTypeObject *pyclass); + + struct _PyGObject_Functions { void (* register_class)(PyObject *dict, const gchar *class_name, GType gtype, PyTypeObject *type, PyObject *bases); @@ -155,6 +158,7 @@ struct _PyGObject_Functions { int (*enable_threads) (void); int (*gil_state_ensure) (void); void (*gil_state_release) (int flag); + void (*register_class_init) (GType gtype, PyGClassInitFunc class_init); }; #ifndef _INSIDE_PYGOBJECT_ @@ -206,6 +210,7 @@ struct _PyGObject_Functions *_PyGObject_API; #define pyg_flags_add (_PyGObject_API->flags_add) #define pyg_flags_from_gtype (_PyGObject_API->flags_from_gtype) #define pyg_enable_threads (_PyGObject_API->enable_threads) +#define pyg_register_class_init (_PyGObject_API->register_class_init) #define pyg_block_threads() G_STMT_START { \ if (_PyGObject_API->block_threads != NULL) \ |