diff options
Diffstat (limited to 'plugins/pychrysalide/core/params.c')
-rw-r--r-- | plugins/pychrysalide/core/params.c | 100 |
1 files changed, 27 insertions, 73 deletions
diff --git a/plugins/pychrysalide/core/params.c b/plugins/pychrysalide/core/params.c index e31c129..b9d8741 100644 --- a/plugins/pychrysalide/core/params.c +++ b/plugins/pychrysalide/core/params.c @@ -40,7 +40,7 @@ static PyObject *py_params_get_main_configuration(PyObject *, PyObject *); /* Définit les constantes pour les paramètres. */ -static bool py_params_define_constants(PyTypeObject *); +static bool py_params_define_constants(PyObject *); @@ -74,51 +74,7 @@ static PyObject *py_params_get_main_configuration(PyObject *self, PyObject *args /****************************************************************************** * * -* Paramètres : - * -* * -* Description : Fournit un accès à une définition de type à diffuser. * -* * -* Retour : Définition d'objet pour Python. * -* * -* Remarques : - * -* * -******************************************************************************/ - -PyTypeObject *get_python_params_type(void) -{ - static PyMethodDef py_params_methods[] = { - - { "get_main_configuration", py_params_get_main_configuration, - METH_NOARGS | METH_STATIC, - "get_main_configuration(, /)\n--\n\nGive access to the main configuration of Chrysalide." - }, - { NULL } - - }; - - static PyTypeObject py_params_type = { - - PyVarObject_HEAD_INIT(NULL, 0) - - .tp_name = "pychrysalide.core.params", - .tp_basicsize = sizeof(PyObject), - - .tp_flags = Py_TPFLAGS_DEFAULT, - - .tp_doc = "Python object for parameters", - - .tp_methods = py_params_methods - - }; - - return &py_params_type; - -} - - -/****************************************************************************** -* * -* Paramètres : obj_type = type dont le dictionnaire est à compléter. * +* Paramètres : dict = dictionnaire de module à compléter. * * * * Description : Définit les constantes pour les paramètres. * * * @@ -128,17 +84,17 @@ PyTypeObject *get_python_params_type(void) * * ******************************************************************************/ -static bool py_params_define_constants(PyTypeObject *obj_type) +static bool py_params_define_constants(PyObject *dict) { bool result; /* Bilan à retourner */ result = true; - result &= PyDict_AddStringMacro(obj_type, MPK_LAST_PROJECT); - result &= PyDict_AddStringMacro(obj_type, MPK_ELLIPSIS_HEADER); - result &= PyDict_AddStringMacro(obj_type, MPK_ELLIPSIS_TAB); - result &= PyDict_AddStringMacro(obj_type, MPK_KEYBINDINGS_EDIT); - result &= PyDict_AddStringMacro(obj_type, MPK_AUTO_SAVE); + result &= PyModDict_AddStringMacro(dict, MPK_LAST_PROJECT); + result &= PyModDict_AddStringMacro(dict, MPK_ELLIPSIS_HEADER); + result &= PyModDict_AddStringMacro(dict, MPK_ELLIPSIS_TAB); + result &= PyModDict_AddStringMacro(dict, MPK_KEYBINDINGS_EDIT); + result &= PyModDict_AddStringMacro(dict, MPK_AUTO_SAVE); return result; @@ -147,9 +103,9 @@ static bool py_params_define_constants(PyTypeObject *obj_type) /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : - * * * -* Description : Prend en charge l'objet 'pychrysalide.core.params'. * +* Description : Définit une extension du module 'core' à compléter. * * * * Retour : Bilan de l'opération. * * * @@ -157,34 +113,32 @@ static bool py_params_define_constants(PyTypeObject *obj_type) * * ******************************************************************************/ -bool ensure_python_params_is_registered(void) +bool populate_core_module_with_params(void) { - PyTypeObject *type; /* Type Python pour 'params' */ + bool result; /* Bilan à retourner */ PyObject *module; /* Module à recompléter */ - int ret; /* Bilan d'un appel */ + PyObject *dict; /* Dictionnaire dudit module */ - type = get_python_params_type(); - - if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) - { - type->tp_new = PyType_GenericNew; - - if (PyType_Ready(type) != 0) - return false; + static PyMethodDef py_params_methods[] = { - if (!py_params_define_constants(type)) - return false; + { "get_main_configuration", py_params_get_main_configuration, + METH_NOARGS, + "get_main_configuration(, /)\n--\n\nGive access to the main configuration of Chrysalide." + }, + { NULL } - module = get_access_to_python_module("pychrysalide.core"); + }; - Py_INCREF(type); - ret = PyModule_AddObject(module, "params", (PyObject *)type); + module = get_access_to_python_module("pychrysalide.core"); - if (ret != 0) - return false; + result = register_python_module_methods(module, py_params_methods); + if (result) + { + dict = PyModule_GetDict(module); + result = py_params_define_constants(dict); } - return true; + return result; } |