summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@sugarlabs.org>2009-12-29 13:08:29 +0100
committerTomeu Vizoso <tomeu@sugarlabs.org>2009-12-29 13:09:49 +0100
commit86783c695f3641b9491962e8f95a4dcb91f4017c (patch)
tree3f98a0c9c7ee977d2015db5d2b0edf75ff140e84
parentb90c01cff5ff5cb2796182f2ffd7b5248eaeed6a (diff)
downloadpygobject-86783c695f3641b9491962e8f95a4dcb91f4017c.tar.gz
pygobject-86783c695f3641b9491962e8f95a4dcb91f4017c.tar.xz
pygobject-86783c695f3641b9491962e8f95a4dcb91f4017c.zip
Register enums and flags in PyGI if needed
https://bugzilla.gnome.org/show_bug.cgi?id=603534
-rw-r--r--gobject/pygenum.c20
-rw-r--r--gobject/pygflags.c19
2 files changed, 27 insertions, 12 deletions
diff --git a/gobject/pygenum.c b/gobject/pygenum.c
index 76b35f2..027dbd4 100644
--- a/gobject/pygenum.c
+++ b/gobject/pygenum.c
@@ -28,6 +28,8 @@
#include <pyglib.h>
#include "pygobject-private.h"
+#include "pygi-external.h"
+
GQuark pygenum_class_key;
PYGLIB_DEFINE_TYPE("gobject.GEnum", PyGEnum_Type, PyGEnum);
@@ -150,13 +152,19 @@ pyg_enum_from_gtype (GType gtype, int value)
PyObject *pyclass, *values, *retval, *intvalue;
g_return_val_if_fail(gtype != G_TYPE_INVALID, NULL);
-
+
+ /* Get a wrapper class by:
+ * 1. check for one attached to the gtype
+ * 2. lookup one in a typelib
+ * 3. creating a new one
+ */
pyclass = (PyObject*)g_type_get_qdata(gtype, pygenum_class_key);
- if (pyclass == NULL) {
- pyclass = pyg_enum_add(NULL, g_type_name(gtype), NULL, gtype);
- if (!pyclass)
- return _PyLong_FromLong(value);
- }
+ if (!pyclass)
+ pyclass = pygi_type_import_by_g_type(gtype);
+ if (!pyclass)
+ pyclass = pyg_enum_add(NULL, g_type_name(gtype), NULL, gtype);
+ if (!pyclass)
+ return _PyLong_FromLong(value);
values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
"__enum_values__");
diff --git a/gobject/pygflags.c b/gobject/pygflags.c
index 6dc419e..1865abb 100644
--- a/gobject/pygflags.c
+++ b/gobject/pygflags.c
@@ -29,6 +29,8 @@
#include "pygobject-private.h"
#include "pygflags.h"
+#include "pygi-external.h"
+
GQuark pygflags_class_key;
PYGLIB_DEFINE_TYPE("gobject.GFlags", PyGFlags_Type, PyGFlags);
@@ -170,13 +172,18 @@ pyg_flags_from_gtype (GType gtype, int value)
g_return_val_if_fail(gtype != G_TYPE_INVALID, NULL);
+ /* Get a wrapper class by:
+ * 1. check for one attached to the gtype
+ * 2. lookup one in a typelib
+ * 3. creating a new one
+ */
pyclass = (PyObject*)g_type_get_qdata(gtype, pygflags_class_key);
- if (pyclass == NULL) {
- pyclass = pyg_flags_add(NULL, g_type_name(gtype), NULL, gtype);
- if (!pyclass)
- return _PyLong_FromLong(value);
- }
-
+ if (!pyclass)
+ pyclass = pygi_type_import_by_g_type(gtype);
+ if (!pyclass)
+ pyclass = pyg_flags_add(NULL, g_type_name(gtype), NULL, gtype);
+ if (!pyclass)
+ return _PyLong_FromLong(value);
values = PyDict_GetItemString(((PyTypeObject *)pyclass)->tp_dict,
"__flags_values__");