X-Git-Url: http://git.claws-mail.org/?p=claws.git;a=blobdiff_plain;f=src%2Fplugins%2Fpython%2Fpython_plugin.c;h=03c2ea4e888800a54ca96150937ee8df40ec06bd;hp=4cdba316faeafb48e98453dbb778736a506012a9;hb=ea3fde42caa59cfab29bffedcbf37471487cdc7e;hpb=b5b69753f875f9515fc61216899dbc8a51660b7a diff --git a/src/plugins/python/python_plugin.c b/src/plugins/python/python_plugin.c index 4cdba316f..03c2ea4e8 100644 --- a/src/plugins/python/python_plugin.c +++ b/src/plugins/python/python_plugin.c @@ -20,11 +20,11 @@ #include "claws-features.h" #endif +#include + #include #include -#include - #include #include "common/hooks.h" @@ -56,7 +56,7 @@ static GSList *python_compose_scripts_names = NULL; static GtkWidget *python_console = NULL; -static guint hook_compose_create; +static gulong hook_compose_create = 0; static gboolean python_console_delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) { @@ -355,7 +355,7 @@ static void create_compose_menus_and_items(GSList *filenames) } static GtkActionEntry compose_tools_python_actions[] = { - {"Tools/PythonScripts", NULL, N_("Python scripts") }, + {"Tools/PythonScripts", NULL, N_("Python scripts"), NULL, NULL, NULL }, }; static void ComposeActionData_destroy_cb(gpointer data) @@ -499,12 +499,12 @@ static GtkToggleActionEntry mainwindow_tools_python_toggle[] = { }; static GtkActionEntry mainwindow_tools_python_actions[] = { - {"Tools/PythonScripts", NULL, N_("Python scripts") }, + {"Tools/PythonScripts", NULL, N_("Python scripts"), NULL, NULL, NULL }, {"Tools/PythonScripts/Refresh", NULL, N_("Refresh"), NULL, NULL, G_CALLBACK(refresh_python_scripts_menus) }, {"Tools/PythonScripts/Browse", NULL, N_("Browse"), NULL, NULL, G_CALLBACK(browse_python_scripts_dir) }, - {"Tools/PythonScripts/---", NULL, "---" }, + {"Tools/PythonScripts/---", NULL, "---", NULL, NULL, NULL }, }; static int python_menu_init(char **error) @@ -634,12 +634,17 @@ done: Py_XDECREF(meth_getvalue); Py_XDECREF(result_getvalue); - return retval ? retval : g_strdup("Unspecified error occured"); + return retval ? retval : g_strdup("Unspecified error occurred"); } +static void log_func(const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data) +{ +} gint plugin_init(gchar **error) { + guint log_handler; + int parasite_retval; PyObject *inst_StringIO = NULL; /* Version check */ @@ -648,7 +653,7 @@ gint plugin_init(gchar **error) /* load hooks */ hook_compose_create = hooks_register_hook(COMPOSE_CREATED_HOOKLIST, my_compose_create_hook, NULL); - if(hook_compose_create == (guint)-1) { + if(hook_compose_create == 0) { *error = g_strdup(_("Failed to register \"compose create hook\" in the Python plugin")); return -1; } @@ -662,7 +667,7 @@ gint plugin_init(gchar **error) /* The Python C API only offers to print an exception to sys.stderr. In order to catch it * in a string, a StringIO object is created, to which sys.stderr can be redirected in case - * an error occured. */ + * an error occurred. */ inst_StringIO = get_StringIO_instance(); /* initialize Claws Mail Python module */ @@ -678,7 +683,10 @@ gint plugin_init(gchar **error) } /* initialize python interactive shell */ - if(!parasite_python_init(error)) { + log_handler = g_log_set_handler(NULL, G_LOG_LEVEL_WARNING | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_INFO, log_func, NULL); + parasite_retval = parasite_python_init(error); + g_log_remove_handler(NULL, log_handler); + if(!parasite_retval) { goto err; } @@ -716,6 +724,8 @@ gboolean plugin_done(void) /* finialize python interpreter */ Py_Finalize(); + parasite_python_done(); + debug_print("Python plugin done and unloaded.\n"); return FALSE; } @@ -728,14 +738,36 @@ const gchar *plugin_name(void) const gchar *plugin_desc(void) { return _("This plugin provides Python integration features.\n" - "\nFor the most up-to-date API documentation, type\n" - "\n help(clawsmail)\n" - "\nin the interactive Python console under Tools -> Show Python console.\n" - "\nThe source distribution of this plugin comes with various example scripts " - "in the \"examples\" subdirectory. If you wrote a script that you would be " - "interested in sharing, feel free to send it to me to have it considered " - "for inclusion in the examples.\n" - "\nFeedback to is welcome."); + "Python code can be entered interactively into an embedded Python console, " + "under Tools -> Show Python console, or stored in scripts.\n\n" + "These scripts are then available via the menu. You can assign " + "keyboard shortcuts to them just like it is done with other menu items. " + "You can also put buttons for script invocation into the toolbars " + "using Claws Mail's builtin toolbar editor.\n\n" + "You can provide scripts working on the main window by placing files " + "into ~/.claws-mail/python-scripts/main.\n\n" + "You can also provide scripts working on an open compose window " + "by placing files into ~/.claws-mail/python-scripts/compose.\n\n" + "The folder ~/.claws-mail/python-scripts/auto/ may contain some " + "scripts that are automatically executed when certain events " + "occur. Currently, the following files in this directory " + "are recognised:\n\n" + "compose_any\n" + "Gets executed whenever a compose window is opened, no matter " + "if that opening happened as a result of composing a new message, " + "replying or forwarding a message.\n\n" + "startup\n" + "Executed at plugin load\n\n" + "shutdown\n" + "Executed at plugin unload\n\n" + "\nFor the most up-to-date API documentation, type\n" + "\n help(clawsmail)\n" + "\nin the interactive Python console.\n" + "\nThe source distribution of this plugin comes with various example scripts " + "in the \"examples\" subdirectory. If you wrote a script that you would be " + "interested in sharing, feel free to send it to me to have it considered " + "for inclusion in the examples.\n" + "\nFeedback to is welcome."); } const gchar *plugin_type(void)