diff options
Diffstat (limited to 'plugins/yaml/python/node.c')
-rw-r--r-- | plugins/yaml/python/node.c | 57 |
1 files changed, 49 insertions, 8 deletions
diff --git a/plugins/yaml/python/node.c b/plugins/yaml/python/node.c index 7f7c383..7d2fef0 100644 --- a/plugins/yaml/python/node.c +++ b/plugins/yaml/python/node.c @@ -28,6 +28,7 @@ #include <pygobject.h> +#include <plugins/pychrysalide/access.h> #include <plugins/pychrysalide/helpers.h> @@ -35,6 +36,34 @@ +CREATE_DYN_ABSTRACT_CONSTRUCTOR(yaml_node, G_TYPE_YAML_NODE, NULL); + +/* Initialise une instance sur la base du dérivé de GObject. */ +static int py_yaml_node_init(PyObject *, PyObject *, PyObject *); + +/* Recherche le premier noeud correspondant à un chemin. */ +static PyObject *py_yaml_node_find_first_by_path(PyObject *, PyObject *); + + + +/****************************************************************************** +* * +* Paramètres : self = objet à initialiser (théoriquement). * +* args = arguments fournis à l'appel. * +* kwds = arguments de type key=val fournis. * +* * +* Description : Initialise une instance sur la base du dérivé de GObject. * +* * +* Retour : 0. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static int py_yaml_node_init(PyObject *self, PyObject *args, PyObject *kwds) +{ + int ret; /* Bilan de lecture des args. */ + #define YAML_NODE_DOC \ "YamlNode handles a node in a YAML tree.\n" \ "\n" \ @@ -42,11 +71,14 @@ "* pair, implemented by the pychrysalide.plugins.yaml.YamlPair object;\n" \ "* sequence and mapping, implemented by the pychrysalide.plugins.yaml.YamlCollection object." + /* Initialisation d'un objet GLib */ + ret = forward_pygobjet_init(self); + if (ret == -1) return -1; -/* Recherche le premier noeud correspondant à un chemin. */ -static PyObject *py_yaml_node_find_first_by_path(PyObject *, PyObject *); + return 0; +} /****************************************************************************** @@ -145,7 +177,9 @@ PyTypeObject *get_python_yaml_node_type(void) .tp_methods = py_yaml_node_methods, .tp_getset = py_yaml_node_getseters, - .tp_new = no_python_constructor_allowed + + .tp_init = py_yaml_node_init, + .tp_new = py_yaml_node_new, }; @@ -156,7 +190,7 @@ PyTypeObject *get_python_yaml_node_type(void) /****************************************************************************** * * -* Paramètres : module = module dont la définition est à compléter. * +* Paramètres : - * * * * Description : Prend en charge l'objet 'pychrysalide.plugins.....YamlNode. * * * @@ -166,17 +200,24 @@ PyTypeObject *get_python_yaml_node_type(void) * * ******************************************************************************/ -bool register_python_yaml_node(PyObject *module) +bool ensure_python_yaml_node_is_registered(void) { PyTypeObject *type; /* Type Python 'YamlNode' */ + PyObject *module; /* Module à recompléter */ PyObject *dict; /* Dictionnaire du module */ type = get_python_yaml_node_type(); - dict = PyModule_GetDict(module); + if (!PyType_HasFeature(type, Py_TPFLAGS_READY)) + { + module = get_access_to_python_module("pychrysalide.plugins.yaml"); - if (!register_class_for_pygobject(dict, G_TYPE_YAML_NODE, type)) - return false; + dict = PyModule_GetDict(module); + + if (!register_class_for_pygobject(dict, G_TYPE_YAML_NODE, type)) + return false; + + } return true; |