summaryrefslogtreecommitdiff
path: root/plugins/pychrysalide/glibext/constants.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/glibext/constants.c
parentcd59150b26173fc4caa44b604d9e0989de331b3d (diff)
Improved the API for configuration and its Python documentation.
Diffstat (limited to 'plugins/pychrysalide/glibext/constants.c')
-rw-r--r--plugins/pychrysalide/glibext/constants.c116
1 files changed, 116 insertions, 0 deletions
diff --git a/plugins/pychrysalide/glibext/constants.c b/plugins/pychrysalide/glibext/constants.c
index 3f657e2..373d1bf 100644
--- a/plugins/pychrysalide/glibext/constants.c
+++ b/plugins/pychrysalide/glibext/constants.c
@@ -27,6 +27,7 @@
#include <i18n.h>
#include <glibext/bufferline.h>
+#include <glibext/configuration.h>
#include <glibext/linesegment.h>
#include <glibext/gbinportion.h>
#include <glibext/gloadedpanel.h>
@@ -249,6 +250,121 @@ int convert_to_buffer_line_flags(PyObject *arg, void *dst)
* *
* Paramètres : type = type dont le dictionnaire est à compléter. *
* *
+* Description : Définit les constantes relatives aux paramètres de config. *
+* *
+* Retour : true en cas de succès de l'opération, false sinon. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+bool define_config_param_constants(PyTypeObject *type)
+{
+ bool result; /* Bilan à retourner */
+ PyObject *values; /* Groupe de valeurs à établir */
+
+ values = PyDict_New();
+
+ result = add_const_to_group(values, "BOOLEAN", CPT_BOOLEAN);
+ if (result) result = add_const_to_group(values, "INTEGER", CPT_INTEGER);
+ if (result) result = add_const_to_group(values, "ULONG", CPT_ULONG);
+ if (result) result = add_const_to_group(values, "STRING", CPT_STRING);
+ if (result) result = add_const_to_group(values, "COLOR", CPT_COLOR);
+ if (result) result = add_const_to_group(values, "COUNT", CPT_COUNT);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_type(type, false, "ConfigParamType", values,
+ "Kind of value available for configuration parameter types.");
+
+ values = PyDict_New();
+
+ result = add_const_to_group(values, "UNDEFINED", CPS_UNDEFINED);
+ if (result) result = add_const_to_group(values, "CHANGED", CPS_CHANGED);
+ if (result) result = add_const_to_group(values, "DEFAULT", CPS_DEFAULT);
+ if (result) result = add_const_to_group(values, "EMPTY", CPS_EMPTY);
+
+ if (!result)
+ {
+ Py_DECREF(values);
+ goto exit;
+ }
+
+ result = attach_constants_group_to_type(type, true, "ConfigParamState", values,
+ "States of a value carried by a configuration parameter.");
+
+ exit:
+
+ 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 constante ConfigParamType. *
+* *
+* Retour : Bilan de l'opération, voire indications supplémentaires. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+int convert_to_config_param_type(PyObject *arg, void *dst)
+{
+ int result; /* Bilan à retourner */
+ unsigned long value; /* Valeur récupérée */
+
+ result = PyObject_IsInstance(arg, (PyObject *)&PyLong_Type);
+
+ switch (result)
+ {
+ case -1:
+ /* L'exception est déjà fixée par Python */
+ result = 0;
+ break;
+
+ case 0:
+ PyErr_SetString(PyExc_TypeError, "unable to convert the provided argument to ConfigParamType");
+ break;
+
+ case 1:
+
+ value = PyLong_AsUnsignedLong(arg);
+
+ if (value > CPT_COUNT)
+ {
+ result = 0;
+ PyErr_SetString(PyExc_ValueError, _("invalid configuration parameter type"));
+ }
+
+ else
+ *((ConfigParamType *)dst) = value;
+
+ break;
+
+ default:
+ assert(false);
+ break;
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : type = type dont le dictionnaire est à compléter. *
+* *
* Description : Définit les constantes relatives aux segments de ligne. *
* *
* Retour : true en cas de succès de l'opération, false sinon. *