Exemplo n.º 1
0
int
gtk_module_init(gint argc, char *argv[])
{
#ifdef ENABLE_PYTHON
    parasite_python_init();
#endif

    gtkparasite_window_create();
    return FALSE;

    return 0;
}
Exemplo n.º 2
0
gint plugin_init(gchar **error)
{
  PyObject *inst_StringIO = NULL;

  /* Version check */
  if(!check_plugin_version(MAKE_NUMERIC_VERSION(3,7,6,9), VERSION_NUMERIC, _("Python"), error))
    return -1;

  /* load hooks */
  hook_compose_create = hooks_register_hook(COMPOSE_CREATED_HOOKLIST, my_compose_create_hook, NULL);
  if(hook_compose_create == (guint)-1) {
    *error = g_strdup(_("Failed to register \"compose create hook\" in the Python plugin"));
    return -1;
  }

  /* script directories */
  if(!make_sure_directories_exist(error))
    goto err;

  /* initialize python interpreter */
  Py_Initialize();

  /* 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. */
  inst_StringIO = get_StringIO_instance();

  /* initialize Claws Mail Python module */
  initclawsmail();
  if(PyErr_Occurred()) {
    *error = get_exception_information(inst_StringIO);
    goto err;
  }

  if(PyRun_SimpleString("import clawsmail") == -1) {
    *error = g_strdup("Error importing the clawsmail module");
    goto err;
  }

  /* initialize python interactive shell */
  if(!parasite_python_init(error)) {
    goto err;
  }

  /* load menu options */
  if(!python_menu_init(error)) {
    goto err;
  }

  /* problems here are not fatal */
  run_auto_script_file_if_it_exists(PYTHON_SCRIPTS_AUTO_STARTUP, NULL);

  debug_print("Python plugin loaded\n");

  return 0;

err:
  hooks_unregister_hook(COMPOSE_CREATED_HOOKLIST, hook_compose_create);
  Py_XDECREF(inst_StringIO);
  return -1;
}