summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/pychrysalide/constants.c3
-rw-r--r--plugins/pychrysalide/core.c41
-rw-r--r--plugins/pychrysalide/glibext/configuration.c25
-rw-r--r--plugins/pychrysalide/plugin.c127
-rw-r--r--plugins/python/scripting/core.py8
5 files changed, 177 insertions, 27 deletions
diff --git a/plugins/pychrysalide/constants.c b/plugins/pychrysalide/constants.c
index 53d4375..97cf43b 100644
--- a/plugins/pychrysalide/constants.c
+++ b/plugins/pychrysalide/constants.c
@@ -55,9 +55,10 @@ 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_LOADED", PGA_PLUGIN_LOADED);
if (result) result = add_const_to_group(values, "PLUGIN_EXIT", PGA_PLUGIN_EXIT);
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, "ALL_PLUGINS_LOADED", PGA_ALL_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 ee88521..a148654 100644
--- a/plugins/pychrysalide/core.c
+++ b/plugins/pychrysalide/core.c
@@ -665,6 +665,8 @@ static void load_python_plugins(GPluginModule *plugin)
char *modname; /* Nom du module pour Python */
char *filename; /* Chemin d'accès reconstruit */
GPluginModule *pyplugin; /* Lien vers un grffon Python */
+ bool status; /* Bilan d'une opération */
+ GGenConfig *config; /* Configuration à charger */
/* Définition des zones d'influence */
@@ -744,25 +746,42 @@ static void load_python_plugins(GPluginModule *plugin)
pyplugin = g_python_plugin_new(modname, filename);
if (pyplugin == NULL)
+ {
g_plugin_module_log_variadic_message(plugin, LMT_ERROR,
_("No suitable Python plugin found in '%s'"),
filename);
- else
- {
- g_plugin_module_log_variadic_message(plugin, LMT_PROCESS,
- _("Loaded the Python plugin found in the '<b>%s</b>' directory"),
- filename);
+ goto done_with_plugin;
+ }
- /**
- * Comme le greffon n'est pas passé par la résolution des dépendances,
- * on simule l'effet attendu.
- */
- g_object_ref(G_OBJECT(plugin));
+ g_plugin_module_create_config(pyplugin);
- _register_plugin(pyplugin);
+ status = g_plugin_module_manage(pyplugin, PGA_PLUGIN_LOADED);
+ if (!status)
+ {
+ g_plugin_module_log_variadic_message(plugin, LMT_ERROR,
+ _("Plugin '%s' failed to complete loading..."), filename);
+ goto done_with_plugin;
}
+ config = g_plugin_module_get_config(pyplugin);
+ g_generic_config_read(config);
+ g_object_unref(G_OBJECT(config));
+
+ g_plugin_module_log_variadic_message(plugin, LMT_PROCESS,
+ _("Loaded the Python plugin found in the '<b>%s</b>' directory"),
+ filename);
+
+ /**
+ * Comme le greffon n'est pas passé par la résolution des dépendances,
+ * on simule l'effet attendu.
+ */
+ g_object_ref(G_OBJECT(plugin));
+
+ _register_plugin(pyplugin);
+
+ done_with_plugin:
+
free(filename);
free(modname);
diff --git a/plugins/pychrysalide/glibext/configuration.c b/plugins/pychrysalide/glibext/configuration.c
index b7d8f82..235662d 100644
--- a/plugins/pychrysalide/glibext/configuration.c
+++ b/plugins/pychrysalide/glibext/configuration.c
@@ -515,28 +515,27 @@ static PyObject *py_config_param_get_value(PyObject *self, void *closure)
)
param = G_CFG_PARAM(pygobject_get(self));
+
type = g_config_param_get_ptype(param);
+ g_config_param_get_value(param, &value);
+
switch (type)
{
case CPT_BOOLEAN:
- g_config_param_get_value(param, &value.boolean);
result = (value.boolean ? Py_True : Py_False);
Py_INCREF(result);
break;
case CPT_INTEGER:
- g_config_param_get_value(param, &value.integer);
result = PyLong_FromLong(value.integer);
break;
case CPT_ULONG:
- g_config_param_get_value(param, &value.ulong);
result = PyLong_FromUnsignedLong(value.ulong);
break;
case CPT_STRING:
- g_config_param_get_value(param, &value.string);
if (value.string != NULL)
result = PyUnicode_FromString(value.string);
else
@@ -547,7 +546,6 @@ static PyObject *py_config_param_get_value(PyObject *self, void *closure)
break;
case CPT_COLOR:
- g_config_param_get_value(param, &value.color);
result = create_gdk_rgba(&value.color);
break;
@@ -602,7 +600,8 @@ static int py_config_param_set_value(PyObject *self, PyObject *value, void *clos
case CPT_BOOLEAN:
if (PyBool_Check(value))
{
- pvalue.boolean = (value == Py_True);
+ pvalue.integer = (value == Py_True);
+ g_config_param_set_value(param, pvalue.integer);
result = 0;
}
break;
@@ -611,6 +610,7 @@ static int py_config_param_set_value(PyObject *self, PyObject *value, void *clos
if (PyLong_Check(value))
{
pvalue.integer = PyLong_AsLong(value);
+ g_config_param_set_value(param, pvalue.integer);
result = 0;
}
break;
@@ -619,6 +619,7 @@ static int py_config_param_set_value(PyObject *self, PyObject *value, void *clos
if (PyLong_Check(value))
{
pvalue.ulong = PyLong_AsUnsignedLong(value);
+ g_config_param_set_value(param, pvalue.ulong);
result = 0;
}
break;
@@ -627,13 +628,17 @@ static int py_config_param_set_value(PyObject *self, PyObject *value, void *clos
if (PyUnicode_Check(value))
{
pvalue.string = PyUnicode_DATA(value);
+ g_config_param_set_value(param, pvalue.string);
result = 0;
}
break;
case CPT_COLOR:
if (convert_to_gdk_rgba(value, &pvalue.color) == 1)
+ {
+ g_config_param_set_value(param, &pvalue.color);
result = 0;
+ }
break;
default:
@@ -642,9 +647,6 @@ static int py_config_param_set_value(PyObject *self, PyObject *value, void *clos
}
- if (result == 0)
- g_config_param_set_value(param, &pvalue);
-
}
return result;
@@ -1303,7 +1305,7 @@ static PyObject *py_generic_config_search(PyObject *self, PyObject *args)
else
{
result = pygobject_new(G_OBJECT(param));
- g_object_unref(G_OBJECT(param));
+ //g_object_unref(G_OBJECT(param));
}
return result;
@@ -1359,6 +1361,7 @@ static PyObject *py_generic_config_add(PyObject *self, PyObject *args)
config = G_GEN_CONFIG(pygobject_get(self));
+ g_object_ref(G_OBJECT(param));
added = _g_generic_config_add_param(config, param, lock);
if (added == NULL)
@@ -1369,7 +1372,7 @@ static PyObject *py_generic_config_add(PyObject *self, PyObject *args)
else
{
result = pygobject_new(G_OBJECT(added));
- g_object_unref(G_OBJECT(added));
+ //g_object_unref(G_OBJECT(added));
}
return result;
diff --git a/plugins/pychrysalide/plugin.c b/plugins/pychrysalide/plugin.c
index 495cecf..aa91fb8 100644
--- a/plugins/pychrysalide/plugin.c
+++ b/plugins/pychrysalide/plugin.c
@@ -57,6 +57,9 @@ static void py_plugin_module_init_gclass(GPluginModuleClass *, gpointer);
/* Initialise une instance sur la base du dérivé de GObject. */
static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds);
+/* Encadre une étape de la vie d'un greffon. */
+static bool py_plugin_module_manage_wrapper(GPluginModule *);
+
/* Accompagne la fin du chargement des modules natifs. */
static void py_plugin_module_notify_plugins_loaded_wrapper(GPluginModule *, PluginAction);
@@ -229,6 +232,7 @@ static PyObject *py_plugin_module_new(PyTypeObject *type, PyObject *args, PyObje
static void py_plugin_module_init_gclass(GPluginModuleClass *class, gpointer unused)
{
class->init = NULL;
+ class->manage = py_plugin_module_manage_wrapper;
class->exit = NULL;
class->plugins_loaded = py_plugin_module_notify_plugins_loaded_wrapper;
@@ -293,6 +297,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._init_config();\n" \
"* pychrysalide.PluginModule._notify_plugins_loaded();\n" \
"* pychrysalide.PluginModule._include_theme();\n" \
"* pychrysalide.PluginModule._on_panel_creation;\n" \
@@ -395,8 +400,71 @@ static int py_plugin_module_init(PyObject *self, PyObject *args, PyObject *kwds)
/******************************************************************************
* *
* Paramètres : plugin = greffon à manipuler. *
+* *
+* Description : Encadre une étape de la vie d'un greffon. *
+* *
+* Retour : Bilan de l'opération. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static bool py_plugin_module_manage_wrapper(GPluginModule *plugin)
+{
+ bool result; /* Bilan à faire remonter */
+ 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_MANAGE_WRAPPER PYTHON_WRAPPER_DEF \
+( \
+ _manage, "$self, action, /", \
+ METH_VARARGS, \
+ "Abstract method called to react to several steps of the plugin" \
+ " life.\n" \
+ "\n" \
+ "The expected action is a pychrysalide.PluginModule.PluginAction" \
+ " value.\n" \
+ "\n" \
+ "This method has to be defined in order to handle actions such as" \
+ " *PLUGIN_LOADED*." \
+)
+
+ result = true;
+
+ gstate = PyGILState_Ensure();
+
+ pyobj = pygobject_new(G_OBJECT(plugin));
+
+ if (has_python_method(pyobj, "_manage"))
+ {
+ args = PyTuple_New(1);
+
+ PyTuple_SetItem(args, 0, PyLong_FromUnsignedLong(PGA_PLUGIN_LOADED));
+
+ pyret = run_python_method(pyobj, "_manage", args);
+
+ result = (pyret == Py_True);
+
+ Py_XDECREF(pyret);
+ Py_DECREF(args);
+
+ }
+
+ Py_DECREF(pyobj);
+
+ PyGILState_Release(gstate);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : plugin = greffon à manipuler. *
* action = type d'action attendue. *
-* unused = variable non utilisé pour l'usage de __VA_ARGS__. *
* *
* Description : Accompagne la fin du chargement des modules natifs. *
* *
@@ -1629,6 +1697,61 @@ static PyObject *py_plugin_module_get_filename(PyObject *self, void *closure)
/******************************************************************************
* *
+* Paramètres : self = objet Python concerné par l'appel. *
+* closure = non utilisé ici. *
+* *
+* Description : Fournit la configuration mise en place pour le greffon. *
+* *
+* Retour : Configuration dédiée à l'extension. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static PyObject *py_plugin_module_get_config(PyObject *self, void *closure)
+{
+ PyObject *result; /* Valeur à retourner */
+ GPluginModule *plugin; /* Version native du greffon */
+ GGenConfig *config; /* Configuration associée */
+
+#define PLUGIN_MODULE_CONFIG_ATTRIB PYTHON_GET_DEF_FULL \
+( \
+ config, py_plugin_module, \
+ "Dedicated configuration for the plugin." \
+ "\n" \
+ "The value is a pychrysalide.glibext.GenConfig instance" \
+ " or None if the configuration is not yet created.\n" \
+ "\n" \
+ "As configuration storage path depends on the plugin name," \
+ " all plugin properties have to get fully loaded by the" \
+ " core before the configuration can be setup." \
+ "automatically" \
+)
+
+ plugin = G_PLUGIN_MODULE(pygobject_get(self));
+ config = g_plugin_module_get_config(plugin);
+
+ if (config == NULL)
+ {
+ result = Py_None;
+ Py_INCREF(result);
+ }
+
+ else
+ {
+ result = pygobject_new(G_OBJECT(config));
+
+ g_object_unref(G_OBJECT(config));
+
+ }
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
* Paramètres : - *
* *
* Description : Fournit un accès à une définition de type à diffuser. *
@@ -1642,6 +1765,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_MANAGE_WRAPPER,
PLUGIN_MODULE_NOTIFY_PLUGINS_LOADED_WRAPPER,
PLUGIN_MODULE_INCLUDE_THEME_WRAPPER,
PLUGIN_MODULE_ON_PANEL_CREATION_WRAPPER,
@@ -1661,6 +1785,7 @@ PyTypeObject *get_python_plugin_module_type(void)
static PyGetSetDef py_plugin_module_getseters[] = {
PLUGIN_MODULE_MODNAME_ATTRIB,
PLUGIN_MODULE_FILENAME_ATTRIB,
+ PLUGIN_MODULE_CONFIG_ATTRIB,
{ NULL }
};
diff --git a/plugins/python/scripting/core.py b/plugins/python/scripting/core.py
index c46ef07..1b91688 100644
--- a/plugins/python/scripting/core.py
+++ b/plugins/python/scripting/core.py
@@ -19,7 +19,7 @@ class ScriptingEngine(PluginModule):
_version = '0.1'
_url = 'https://www.chrysalide.re/'
- _actions = ( PluginModule.PluginAction.PLUGINS_LOADED, PluginModule.PluginAction.PANEL_CREATION )
+ _actions = ( PluginModule.PluginAction.PLUGIN_LOADED, PluginModule.PluginAction.PANEL_CREATION )
_manager = None
@@ -64,15 +64,17 @@ class ScriptingEngine(PluginModule):
file_menu.insert(item, index)
- def _notify_plugins_loaded(self, action):
+ def _manage(self, action):
"""Ack the full loading of all plugins."""
- if action == PluginModule.PluginAction.PLUGINS_LOADED:
+ if action == PluginModule.PluginAction.PLUGIN_LOADED:
xbel = self.build_config_filename('recents.xbel', True)
ScriptingEngine._manager = Gtk.RecentManager(filename=xbel)
+ return True
+
def _on_panel_creation(self, action, item):
"""Get notified of a new panel creation."""