summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/helpers.h
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/pychrysalide/helpers.h')
-rw-r--r--plugins/pychrysalide/helpers.h181
1 files changed, 144 insertions, 37 deletions
diff --git a/plugins/pychrysalide/helpers.h b/plugins/pychrysalide/helpers.h
index 931be95..57cf96d 100644
--- a/plugins/pychrysalide/helpers.h
+++ b/plugins/pychrysalide/helpers.h
@@ -29,7 +29,9 @@
#include <assert.h>
#include <glib-object.h>
#include <stdbool.h>
-#include <gdk/gdk.h>
+#ifdef INCLUDE_GTK_SUPPORT
+# include <gdk/gdk.h>
+#endif
@@ -85,26 +87,21 @@ bool register_python_module_object(PyObject *, PyTypeObject *);
#name "(" args ")\n--\n\n" doc \
}
-#define PYTHON_VOID_WRAPPER_DEF(name, args, flags, doc) \
- { \
- #name, (PyCFunction)py_return_none, \
- flags, \
- #name "(" args ")\n--\n\n" doc \
+#define PYTHON_WRAPPER_DEF_WITH(name, args, flags, defcb, doc) \
+ { \
+ #name, (PyCFunction)defcb, \
+ flags, \
+ #name "(" args ")\n--\n\n" doc \
}
-#define PYTHON_FALSE_WRAPPER_DEF(name, args, flags, doc)\
- { \
- #name, (PyCFunction)py_return_false, \
- flags, \
- #name "(" args ")\n--\n\n" doc \
- }
+#define PYTHON_VOID_WRAPPER_DEF(name, args, flags, doc) \
+ PYTHON_WRAPPER_DEF_WITH(name, args, flags, py_return_none, doc)
-#define PYTHON_TRUE_WRAPPER_DEF(name, args, flags, doc)\
- { \
- #name, (PyCFunction)py_return_true, \
- flags, \
- #name "(" args ")\n--\n\n" doc \
- }
+#define PYTHON_FALSE_WRAPPER_DEF(name, args, flags, doc) \
+ PYTHON_WRAPPER_DEF_WITH(name, args, flags, py_return_false, doc)
+
+#define PYTHON_TRUE_WRAPPER_DEF(name, args, flags, doc) \
+ PYTHON_WRAPPER_DEF_WITH(name, args, flags, py_return_true, doc)
/**
* Il ne semble pas exister de moyen de déterminer
@@ -158,6 +155,34 @@ bool register_python_module_object(PyObject *, PyTypeObject *);
#define APPLY_ABSTRACT_FLAG(tp) tp->tp_new = PyBaseObject_Type.tp_new
+/* Accompagne la création d'une instance dérivée en Python. */
+PyObject *python_constructor_with_dynamic_gtype(PyTypeObject *, GType, PyObject *, PyObject *);
+
+/* Accompagne la création d'une instance dérivée en Python. */
+PyObject *python_abstract_constructor_with_dynamic_gtype(PyTypeObject *, GType, GClassInitFunc, PyObject *, PyObject *);
+
+
+#define CREATE_DYN_CONSTRUCTOR(pyname, gbase) \
+static PyObject *py_ ## pyname ## _new(PyTypeObject *, PyObject *, PyObject *); \
+static PyObject *py_ ## pyname ## _new(PyTypeObject *type, PyObject *args, PyObject *kwds) \
+{ \
+ PyObject *result; /* Objet à retourner */ \
+ result = python_constructor_with_dynamic_gtype(type, gbase, args, kwds); \
+ return result; \
+}
+
+
+#define CREATE_DYN_ABSTRACT_CONSTRUCTOR(pyname, gbase, cinit) \
+static PyObject *py_ ## pyname ## _new(PyTypeObject *, PyObject *, PyObject *); \
+static PyObject *py_ ## pyname ## _new(PyTypeObject *type, PyObject *args, PyObject *kwds) \
+{ \
+ PyObject *result; /* Objet à retourner */ \
+ result = python_abstract_constructor_with_dynamic_gtype(type, gbase, (GClassInitFunc)cinit, \
+ args, kwds); \
+ return result; \
+}
+
+
/* Marque l'interdiction d'une instanciation depuis Python. */
PyObject *no_python_constructor_allowed(PyTypeObject *, PyObject *, PyObject *);
@@ -200,16 +225,13 @@ PyTypeObject *define_python_dynamic_type(const PyTypeObject *);
/* Enregistre correctement une surcouche de conversion GObject. */
-bool _register_class_for_pygobject(PyObject *, GType, PyTypeObject *, PyTypeObject *, ...);
-
-#define register_class_for_pygobject(dict, gtype, type, base) \
- _register_class_for_pygobject(dict, gtype, type, base, NULL)
+bool register_class_for_pygobject(PyObject *, GType, PyTypeObject *);
/* Enregistre correctement une interface GObject pour Python. */
bool register_interface_for_pygobject(PyObject *, GType, PyTypeObject *, const GInterfaceInfo *);
/* Enregistre un type Python dérivant d'un type GLib dynamique. */
-bool register_class_for_dynamic_pygobject(GType, PyTypeObject *, PyTypeObject *);
+bool register_class_for_dynamic_pygobject(GType, PyTypeObject *);
/* Fait suivre à la partie GObject une initialisation nouvelle. */
int forward_pygobjet_init(PyObject *);
@@ -220,12 +242,36 @@ int convert_to_gtype(PyObject *, void *);
/* Tente de convertir en instance GObject. */
int convert_to_gobject(PyObject *, void *);
+#ifdef INCLUDE_GTK_SUPPORT
+
/* Tente de convertir en instance de composant GTK. */
int convert_to_gtk_widget(PyObject *, void *);
/* Tente de convertir en instance de conteneur GTK. */
int convert_to_gtk_container(PyObject *, void *);
+#endif
+
+
+#if !defined(INCLUDE_GTK_SUPPORT) && !defined(HOMEMADE_RGBA)
+
+# define HOMEMADE_RGBA
+
+/**
+ * Copie depuis /usr/include/gtk-3.0/gdk/gdkrgba.h
+ */
+typedef struct _GdkRGBA
+{
+ gdouble red;
+ gdouble green;
+ gdouble blue;
+ gdouble alpha;
+
+} GdkRGBA;
+
+#endif
+
+
/* Construit un objet Python pour une couleur RGBA. */
PyObject *create_gdk_rgba(const GdkRGBA *);
@@ -261,6 +307,41 @@ int convert_to_gdk_rgba(PyObject *, void *);
})
+#define TRANSLATE_NUMERIC_FIELD(dict, base, field) \
+ ({ \
+ PyObject *__attrib; \
+ __attrib = PyLong_FromUnsignedLongLong(base->field); \
+ Py_INCREF(__attrib); \
+ ADD_FIELD_TRANSLATION(dict, #field, __attrib); \
+ })
+
+
+#define RETRIEVE_NUMERIC_FIELD(dict, base, field) \
+ ({ \
+ bool __status; \
+ PyObject *__attrib; \
+ __status = false; \
+ __attrib = PyDict_GetItemString(dict, #field); \
+ if (__attrib != NULL && PyLong_Check(__attrib)) \
+ { \
+ base->field = PyLong_AsUnsignedLongLong(__attrib); \
+ __status = (PyErr_Occurred() == NULL); \
+ } \
+ __status; \
+ })
+
+
+#define TRANSLATE_BYTES_FIELD(dict, base, field, len) \
+ ({ \
+ void *__data; \
+ PyObject *__attrib; \
+ __data = (void *)&base->field; \
+ __attrib = PyBytes_FromStringAndSize(__data, len); \
+ Py_INCREF(__attrib); \
+ ADD_FIELD_TRANSLATION(dict, #field, __attrib); \
+ })
+
+
#define TRANSLATE_STRING_FIELD(dict, base, field) \
({ \
PyObject *__attrib; \
@@ -308,20 +389,46 @@ int convert_to_gdk_rgba(PyObject *, void *);
})
/* Officialise un groupe de constantes avec sémentique. */
-bool _attach_constants_group(const char *, PyObject *, bool, const char *, PyObject *, const char *);
-
-#define attach_constants_group_to_type(type, flags, name, values, doc) \
- _attach_constants_group(type->tp_name, type->tp_dict, flags, name, values, doc)
-
-#define attach_constants_group_to_module(mod, flags, name, values, doc) \
- ({ \
- bool __result; \
- const char *__owner; \
- PyObject *__dict; \
- __owner = PyModule_GetName(mod); \
- __dict = PyModule_GetDict(mod); \
- __result = _attach_constants_group(__owner, __dict, flags, name, values, doc); \
- __result; \
+PyObject *_attach_constants_group(const char *, PyObject *, bool, const char *, PyObject *, const char *);
+
+#define attach_constants_group_to_type(type, flags, name, values, doc) \
+ ({ \
+ bool __result; \
+ PyObject *__new; \
+ __new = _attach_constants_group(type->tp_name, type->tp_dict, flags, name, values, \
+ doc); \
+ __result = (__new != NULL); \
+ Py_XDECREF(__new); \
+ __result; \
+ })
+
+#define attach_constants_group_to_module(mod, flags, name, values, doc) \
+ ({ \
+ bool __result; \
+ const char *__owner; \
+ PyObject *__dict; \
+ PyObject *__new; \
+ __owner = PyModule_GetName(mod); \
+ __dict = PyModule_GetDict(mod); \
+ __new = _attach_constants_group(__owner, __dict, flags, name, values, doc); \
+ __result = (__new != NULL); \
+ Py_XDECREF(__new); \
+ __result; \
+ })
+
+/* Officialise un groupe de constantes avec lien GLib. */
+PyObject *_attach_constants_group_with_pyg_enum(const char *, PyObject *, bool, const char *, PyObject *, const char *, GType);
+
+
+#define attach_constants_group_to_type_with_pyg_enum(type, flags, name, values, doc, gtype) \
+ ({ \
+ bool __result; \
+ PyObject *__new; \
+ __new = _attach_constants_group_with_pyg_enum(type->tp_name, type->tp_dict, flags, \
+ name, values, doc, gtype); \
+ __result = (__new != NULL); \
+ Py_XDECREF(__new); \
+ __result; \
})
/* Traduit une valeur constante C en équivalent Python. */