diff options
Diffstat (limited to 'plugins/pychrysalide/bindings.c')
-rw-r--r-- | plugins/pychrysalide/bindings.c | 93 |
1 files changed, 75 insertions, 18 deletions
diff --git a/plugins/pychrysalide/bindings.c b/plugins/pychrysalide/bindings.c index 7e87e27..f120c3b 100644 --- a/plugins/pychrysalide/bindings.c +++ b/plugins/pychrysalide/bindings.c @@ -33,6 +33,7 @@ #include <common/cpp.h> +#include <common/environment.h> #include <common/extstr.h> #include <core/core.h> #include <plugins/pglist.h> @@ -52,10 +53,6 @@ #include "glibext/module.h" /* #include "debug/module.h" */ #include "format/module.h" -/* #ifdef INCLUDE_GTK_SUPPORT */ -/* # include "gtkext/module.h" */ -/* # include "gui/module.h" */ -/* #endif */ /* #include "mangling/module.h" */ #include "plugins/module.h" @@ -149,7 +146,7 @@ static void ensure_native_pygobject_type(PyTypeObject **); static PyObject *get_existing_modules(void); /* Définit les différents modules du support Python. */ -static PyObject *create_basic_modules(void); +static PyObject *create_basic_modules(const pyinit_details_t *); /* Inscrit les défintions des objets Python de Chrysalide. */ static bool populate_python_modules(const pyinit_details_t *); @@ -158,6 +155,7 @@ static bool populate_python_modules(const pyinit_details_t *); static void restore_original_pygobject_type(PyTypeObject *); + /* ------------------------ FONCTIONS GLOBALES DE CHRYSALIDE ------------------------ */ @@ -978,7 +976,7 @@ static PyObject *get_existing_modules(void) /****************************************************************************** * * -* Paramètres : - * +* Paramètres : details = précisions de chargement complémentaires. * * * * Description : Définit les différents modules du support Python. * * * @@ -988,7 +986,7 @@ static PyObject *get_existing_modules(void) * * ******************************************************************************/ -static PyObject *create_basic_modules(void) +static PyObject *create_basic_modules(const pyinit_details_t *details) { PyObject *result; /* Module Python à retourner */ bool status; /* Bilan des inclusions */ @@ -1036,14 +1034,17 @@ static PyObject *create_basic_modules(void) */ if (status) status = add_format_module(result); /* -#ifdef INCLUDE_GTK_SUPPORT - if (status) status = add_gtkext_module(result); - if (status) status = add_gui_module(result); -#endif if (status) status = add_mangling_module(result); */ if (status) status = add_plugins_module(result); + /** + * Ajout de modules UI supplémentaires éventuels. + */ + + if (status && details->add_extra != NULL) + status = details->add_extra(result); + if (!status) { Py_DECREF(result); @@ -1081,8 +1082,8 @@ static bool populate_python_modules(const pyinit_details_t *details) * un chargement préliminaire, si besoin est. */ - if (details->populate_extra) - result = details->populate_extra(); + if (details->populate_extra != NULL) + result = details->populate_extra(false); else result = true; @@ -1101,14 +1102,22 @@ static bool populate_python_modules(const pyinit_details_t *details) */ if (result) result = populate_format_module(); /* -#ifdef INCLUDE_GTK_SUPPORT - if (result) result = populate_gtkext_module(); - if (result) result = populate_gui_module(); -#endif if (result) result = populate_mangling_module(); */ if (result) result = populate_plugins_module(); + /** + * Certaines définitions reposent sur une déclinaison de GtkWidget, + * dont le chargement va remplacer la définition statique de GObject + * par une version allouée dynamiquement. + * + * De telles définitions doivent donc être prise en compte à la fin + * du chargement. + */ + + if (result && details->populate_extra != NULL) + result = details->populate_extra(true); + return result; } @@ -1202,7 +1211,7 @@ PyObject *init_python_pychrysalide_module(const pyinit_details_t *details) ensure_native_pygobject_type(&py_gobj_def); - result = create_basic_modules(); + result = create_basic_modules(details); if (result == NULL) PyErr_SetString(PyExc_SystemError, "failed to create all PyChrysalide modules."); @@ -1356,6 +1365,54 @@ void log_pychrysalide_exception(const char *prefix, ...) /* ---------------------------------------------------------------------------------- */ +/* INTERVENTION DANS LA GESTION DE GREFFONS */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : plugin = instance représentant le greffon courant. * +* path = chemin supplémentaire pour l'espace de recherche. * +* * +* Description : Complète les chemins de recherches de Python. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void extend_python_path(const GPluginModule *plugin, const char *path) +{ + PyGILState_STATE gstate; /* Sauvegarde d'environnement */ + PyObject *list; /* Liste de chemins à compléter*/ + PyObject *new; /* Nouveau chemin à intégrer */ + + gstate = PyGILState_Ensure(); + + list = PySys_GetObject("path"); + assert(list != NULL); + + new = PyUnicode_FromString(path); + assert(new != NULL); + + PyList_Append(list, new); + + Py_DECREF(new); + + add_to_env_var("PYTHONPATH", path, ":"); + + PyGILState_Release(gstate); + + g_plugin_module_log_variadic_message(plugin, LMT_INFO, + _("PYTHONPATH environment variable set to '%s'"), + getenv("PYTHONPATH")); + +} + + + +/* ---------------------------------------------------------------------------------- */ /* FONCTIONS GLOBALES DE CHRYSALIDE */ /* ---------------------------------------------------------------------------------- */ |