diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2020-12-06 19:01:21 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2020-12-06 19:01:21 (GMT) |
commit | aa7cbdda718efd7ec41f0ce580847a0d0c31cfd3 (patch) | |
tree | 1216e62254397446f039a6fe26bd12ba65f68321 /plugins | |
parent | 333e68541e376a7b86703fad8e917f71c0f243d0 (diff) |
Extended the plugin API to notify several stages of loading.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/pychrysalide/constants.c | 3 | ||||
-rw-r--r-- | plugins/pychrysalide/core.c | 22 | ||||
-rw-r--r-- | plugins/pychrysalide/core.h | 2 | ||||
-rw-r--r-- | plugins/pychrysalide/plugin.c | 25 |
4 files changed, 29 insertions, 23 deletions
diff --git a/plugins/pychrysalide/constants.c b/plugins/pychrysalide/constants.c index ded25c3..53d4375 100644 --- a/plugins/pychrysalide/constants.c +++ b/plugins/pychrysalide/constants.c @@ -56,7 +56,8 @@ bool define_plugin_module_constants(PyTypeObject *type) if (result) result = add_const_to_group(values, "BASIC_NONE", PGA_BASIC_NONE); if (result) result = add_const_to_group(values, "PLUGIN_INIT", PGA_PLUGIN_INIT); if (result) result = add_const_to_group(values, "PLUGIN_EXIT", PGA_PLUGIN_EXIT); - if (result) result = add_const_to_group(values, "NATIVE_LOADED", PGA_NATIVE_LOADED); + if (result) result = add_const_to_group(values, "NATIVE_PLUGINS_LOADED", PGA_NATIVE_PLUGINS_LOADED); + if (result) result = add_const_to_group(values, "PLUGINS_LOADED", PGA_PLUGINS_LOADED); if (result) result = add_const_to_group(values, "TYPE_BUILDING", PGA_TYPE_BUILDING); if (result) result = add_const_to_group(values, "GUI_THEME", PGA_GUI_THEME); if (result) result = add_const_to_group(values, "PANEL_CREATION", PGA_PANEL_CREATION); diff --git a/plugins/pychrysalide/core.c b/plugins/pychrysalide/core.c index 1ba738d..94fb899 100644 --- a/plugins/pychrysalide/core.c +++ b/plugins/pychrysalide/core.c @@ -70,7 +70,7 @@ DEFINE_CHRYSALIDE_CONTAINER_PLUGIN("PyChrysalide", "Chrysalide bindings to Python", PACKAGE_VERSION, CHRYSALIDE_WEBSITE("api/python/pychrysalide"), NO_REQ, AL(PGA_PLUGIN_INIT, PGA_PLUGIN_EXIT, - PGA_NATIVE_LOADED, PGA_TYPE_BUILDING)); + PGA_NATIVE_PLUGINS_LOADED, PGA_TYPE_BUILDING)); /* Note la nature du chargement */ @@ -875,20 +875,24 @@ G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *plugin) * * ******************************************************************************/ -G_MODULE_EXPORT void chrysalide_plugin_on_native_loaded(GPluginModule *plugin, PluginAction action) +G_MODULE_EXPORT void chrysalide_plugin_on_plugins_loaded(GPluginModule *plugin, PluginAction action) { PyThreadState *tstate; /* Contexte d'environnement */ - if (!_standalone) + if (action == PGA_NATIVE_PLUGINS_LOADED) { - tstate = get_pychrysalide_main_tstate(); - PyEval_RestoreThread(tstate); - } + if (!_standalone) + { + tstate = get_pychrysalide_main_tstate(); + PyEval_RestoreThread(tstate); + } - load_python_plugins(plugin); + load_python_plugins(plugin); - if (!_standalone) - PyEval_SaveThread(); + if (!_standalone) + PyEval_SaveThread(); + + } } diff --git a/plugins/pychrysalide/core.h b/plugins/pychrysalide/core.h index 0f8b484..6a7b9d1 100644 --- a/plugins/pychrysalide/core.h +++ b/plugins/pychrysalide/core.h @@ -50,7 +50,7 @@ G_MODULE_EXPORT bool chrysalide_plugin_init(GPluginModule *); G_MODULE_EXPORT void chrysalide_plugin_exit(GPluginModule *); /* Accompagne la fin du chargement des modules natifs. */ -G_MODULE_EXPORT void chrysalide_plugin_on_native_loaded(GPluginModule *, PluginAction); +G_MODULE_EXPORT void chrysalide_plugin_on_plugins_loaded(GPluginModule *, PluginAction); /* Crée une instance à partir d'un type dynamique externe. */ G_MODULE_EXPORT gpointer chrysalide_plugin_build_type_instance(GPluginModule *, PluginAction, GType); diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c index b3bcce5..0fd6c26 100644 --- a/plugins/pychrysalide/plugin.c +++ b/plugins/pychrysalide/plugin.c @@ -58,7 +58,7 @@ static void py_plugin_module_init_gclass(GPluginModuleClass *, gpointer); static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds); /* Accompagne la fin du chargement des modules natifs. */ -static void py_plugin_module_notify_native_loaded_wrapper(GPluginModule *, PluginAction); +static void py_plugin_module_notify_plugins_loaded_wrapper(GPluginModule *, PluginAction); /* Complète une liste de resources pour thème. */ static void py_plugin_module_include_theme_wrapper(const GPluginModule *, PluginAction, gboolean, char ***, size_t *); @@ -231,7 +231,7 @@ static void py_plugin_module_init_gclass(GPluginModuleClass *class, gpointer unu class->init = NULL; class->exit = NULL; - class->native_loaded = py_plugin_module_notify_native_loaded_wrapper; + class->plugins_loaded = py_plugin_module_notify_plugins_loaded_wrapper; class->include_theme = py_plugin_module_include_theme_wrapper; class->notify_panel = py_plugin_module_notify_panel_creation_wrapper; @@ -293,7 +293,7 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds) "\n" \ "Depending on the implemented actions, some of the following methods" \ " have to be defined for new classes:\n" \ - "* pychrysalide.PluginModule._notify_native_loaded();\n" \ + "* pychrysalide.PluginModule._notify_plugins_loaded();\n" \ "* pychrysalide.PluginModule._include_theme();\n" \ "* pychrysalide.PluginModule._on_panel_creation;\n" \ "* pychrysalide.PluginModule._on_panel_docking();\n" \ @@ -394,37 +394,38 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds) * * ******************************************************************************/ -static void py_plugin_module_notify_native_loaded_wrapper(GPluginModule *plugin, PluginAction action) +static void py_plugin_module_notify_plugins_loaded_wrapper(GPluginModule *plugin, PluginAction action) { PyGILState_STATE gstate; /* Sauvegarde d'environnement */ PyObject *pyobj; /* Objet Python concerné */ PyObject *args; /* Arguments pour l'appel */ PyObject *pyret; /* Bilan d'exécution */ -#define PLUGIN_MODULE_NOTIFY_NATIVE_LOADED_WRAPPER PYTHON_WRAPPER_DEF \ +#define PLUGIN_MODULE_NOTIFY_PLUGINS_LOADED_WRAPPER PYTHON_WRAPPER_DEF \ ( \ - _notify_native_loaded, "$self, action, /", \ + _notify_plugins_loaded, "$self, action, /", \ METH_VARARGS, \ - "Abstract method called once all the native plugins are loaded.\n" \ + "Abstract method called once all the (native?) plugins are" \ + " loaded.\n" \ "\n" \ "The expected action is a pychrysalide.PluginModule.PluginAction" \ " value.\n" \ "\n" \ - "This method has to be defined in order to handle action such as" \ - " *NATIVE_LOADED*." \ + "This method has to be defined in order to handle actions such as" \ + " *NATIVE_PLUGINS_LOADED* or *PLUGINS_LOADED*." \ ) gstate = PyGILState_Ensure(); pyobj = pygobject_new(G_OBJECT(plugin)); - if (has_python_method(pyobj, "_notify_native_loaded")) + if (has_python_method(pyobj, "_notify_plugins_loaded")) { args = PyTuple_New(1); PyTuple_SetItem(args, 0, PyLong_FromUnsignedLong(action)); - pyret = run_python_method(pyobj, "_notify_native_loaded", args); + pyret = run_python_method(pyobj, "_notify_plugins_loaded", args); Py_XDECREF(pyret); Py_DECREF(args); @@ -1629,7 +1630,7 @@ static PyObject *py_plugin_module_get_filename(PyObject *self, void *closure) PyTypeObject *get_python_plugin_module_type(void) { static PyMethodDef py_plugin_module_methods[] = { - PLUGIN_MODULE_NOTIFY_NATIVE_LOADED_WRAPPER, + PLUGIN_MODULE_NOTIFY_PLUGINS_LOADED_WRAPPER, PLUGIN_MODULE_INCLUDE_THEME_WRAPPER, PLUGIN_MODULE_ON_PANEL_CREATION_WRAPPER, PLUGIN_MODULE_ON_PANEL_DOCKING_WRAPPER, |