summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/helpers.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2020-12-28 21:44:27 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2020-12-28 21:44:27 (GMT)
commita6a88792bc866d8a1d7cabd50a93374da5dd1e7a (patch)
tree748d5a29339f0ccd09b1d5ef691a988c30eb5fca /plugins/pychrysalide/helpers.c
parentcd59150b26173fc4caa44b604d9e0989de331b3d (diff)
Improved the API for configuration and its Python documentation.
Diffstat (limited to 'plugins/pychrysalide/helpers.c')
-rw-r--r--plugins/pychrysalide/helpers.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/plugins/pychrysalide/helpers.c b/plugins/pychrysalide/helpers.c
index b2ecbec..92a5db9 100644
--- a/plugins/pychrysalide/helpers.c
+++ b/plugins/pychrysalide/helpers.c
@@ -1299,6 +1299,130 @@ int convert_to_gtk_container(PyObject *arg, void *dst)
}
+/******************************************************************************
+* *
+* Paramètres : color = couleur dans sa définition native à copier. *
+* *
+* Description : Construit un objet Python pour une couleur RGBA. *
+* *
+* Retour : Objet Python prêt à emploi ou NULL en cas d'échec. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+PyObject *create_gdk_rgba(const GdkRGBA *color)
+{
+ PyObject *result; /* Coloration à retourner */
+ PyObject *gdk_mod; /* Module Python Gdk */
+ PyObject *rgba_type; /* Classe "GtkRGBA" */
+ PyObject *rgba_args; /* Arguments pour l'appel */
+
+ result = NULL;
+
+ gdk_mod = PyImport_ImportModule("gi.repository.Gdk");
+
+ if (gdk_mod == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, "unable to find the Gtk Python module");
+ goto done;
+ }
+
+ rgba_type = PyObject_GetAttrString(gdk_mod, "RGBA");
+
+ Py_DECREF(gdk_mod);
+
+ rgba_args = PyTuple_New(4);
+ PyTuple_SetItem(rgba_args, 0, PyFloat_FromDouble(color->red));
+ PyTuple_SetItem(rgba_args, 1, PyFloat_FromDouble(color->green));
+ PyTuple_SetItem(rgba_args, 2, PyFloat_FromDouble(color->blue));
+ PyTuple_SetItem(rgba_args, 3, PyFloat_FromDouble(color->alpha));
+
+ result = PyObject_CallObject(rgba_type, rgba_args);
+
+ Py_DECREF(rgba_args);
+
+ done:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : arg = argument quelconque à tenter de convertir. *
+* dst = destination des valeurs récupérées en cas de succès. *
+* *
+* Description : Tente de convertir en instance de couleur RGBA. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_gdk_rgba(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+ PyObject *gdk_mod; /* Module Python Gdk */
+ PyObject *rgba_type; /* Module "RGBA" */
+ int ret; /* Bilan d'une conversion */
+ PyObject *value; /* Valeur d'une composante */
+
+ result = 0;
+
+ gdk_mod = PyImport_ImportModule("gi.repository.Gdk");
+
+ if (gdk_mod == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, "unable to find the Gdk Python module");
+ goto done;
+ }
+
+ rgba_type = PyObject_GetAttrString(gdk_mod, "RGBA");
+
+ Py_DECREF(gdk_mod);
+
+ ret = PyObject_TypeCheck(arg, (PyTypeObject *)rgba_type);
+
+ Py_DECREF(rgba_type);
+
+ if (!ret)
+ {
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to GDK RGBA color");
+ goto done;
+ }
+
+ value = PyObject_GetAttrString(arg, "red");
+ assert(PyFloat_Check(value));
+
+ ((GdkRGBA *)dst)->red = PyFloat_AsDouble(value);
+
+ value = PyObject_GetAttrString(arg, "blue");
+ assert(PyFloat_Check(value));
+
+ ((GdkRGBA *)dst)->blue = PyFloat_AsDouble(value);
+
+ value = PyObject_GetAttrString(arg, "green");
+ assert(PyFloat_Check(value));
+
+ ((GdkRGBA *)dst)->green = PyFloat_AsDouble(value);
+
+ value = PyObject_GetAttrString(arg, "alpha");
+ assert(PyFloat_Check(value));
+
+ ((GdkRGBA *)dst)->alpha = PyFloat_AsDouble(value);
+
+ result = 1;
+
+ done:
+
+ return result;
+
+}
+
+
/* ---------------------------------------------------------------------------------- */
/* TRANSFERT DES VALEURS CONSTANTES */