Commit 4a28f7f1 authored by Jon Kåre Hellan's avatar Jon Kåre Hellan

Add test for Pygtk.

* configure.in (have_pygtk): Add test for Pygtk.

* acconfig.h: Add WITH_PYGTK

* plugins/python/python-loader.c: Include pygobject.h if Pygtk is
installed.
(initialize_python_if_needed): Add init_pygobject if Pygtk is
installed.
(gnumeric_plugin_loader_python_func_file_probe): Replace file name
argument with GsfInput. Try to wrap GsfInput in Python object if
Pygtk is installed. Otherwise give up with warning.
(gnumeric_plugin_loader_python_func_file_open): Ditto.

* plugins/python/Makefile.am: Add PYGTK_CFLAGS to includes.
parent 7f25d885
2002-06-20 Jon K Hellan <hellan@acm.org>
* configure.in (have_pygtk): Add test for Pygtk.
* acconfig.h: Add WITH_PYGTK
2002-06-19 Jody Goldberg <jody@gnome.org>
* src/application.c (application_clipboard_cut_copy) : Use sv_weak_ref.
......
2002-06-20 Jon K Hellan <hellan@acm.org>
* configure.in (have_pygtk): Add test for Pygtk.
* acconfig.h: Add WITH_PYGTK
2002-06-19 Jody Goldberg <jody@gnome.org>
* src/application.c (application_clipboard_cut_copy) : Use sv_weak_ref.
......
2002-06-20 Jon K Hellan <hellan@acm.org>
* configure.in (have_pygtk): Add test for Pygtk.
* acconfig.h: Add WITH_PYGTK
2002-06-19 Jody Goldberg <jody@gnome.org>
* src/application.c (application_clipboard_cut_copy) : Use sv_weak_ref.
......
......@@ -8,6 +8,7 @@
#undef HAVE_LC_MESSAGES
#undef WITH_BONOBO
#undef WITH_PYGTK
#undef ENABLE_EVOLUTION
#undef HAVE_FINITE
......
......@@ -445,6 +445,7 @@ dnl **************************************************
dnl * Check for Python
dnl **************************************************
try_python=true
try_pygtk=false
AC_ARG_WITH(python,
[--{with,without}-python Compile the Python plugin loader],
if test "x$withval" = xno; then
......@@ -508,9 +509,20 @@ EOF
rm -rf testpython
fi
AM_CONDITIONAL(WITH_PYTHON, $python_val)
try_pygtk=$python_val
else
AM_CONDITIONAL(WITH_PYTHON, false)
fi
pygtk_msg="no"
if test "x$try_pygtk" = "xtrue"; then
PKG_CHECK_MODULES(PYGTK, pygtk-2.0 >= 1.99.10,
[pygtk_msg="yes"],
[pygtk_msg="NO. pygtk problem"])
AC_SUBST(PYGTK_CFLAGS)
fi
if test "x$pygtk_msg" = "xyes"; then
AC_DEFINE(WITH_PYGTK)
fi
try_bonobo=false
bonobo_msg="disabled"
......
2002-06-20 Jon K Hellan <hellan@acm.org>
* python-loader.c: Include pygobject.h if Pygtk is installed.
(initialize_python_if_needed): Add init_pygobject if Pygtk is
installed.
(gnumeric_plugin_loader_python_func_file_probe): Replace file name
argument with GsfInput. Try to wrap GsfInput in Python object if
Pygtk is installed. Otherwise give up with warning.
(gnumeric_plugin_loader_python_func_file_open): Ditto.
* Makefile.am: Add PYGTK_CFLAGS to includes.
2002-05-29 Jody Goldberg <jody@gnome.org>
* Release 1.1.4
......
......@@ -2,6 +2,7 @@ INCLUDES = \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-I$(top_srcdir)/src -I$(top_builddir)/src \
$(PY_CFLAGS) \
$(PYGTK_CFLAGS) \
$(GNUMERIC_CFLAGS)
gnumeric_plugin_python_loaderdir = $(gnumeric_plugindir)/python-loader
......
......@@ -7,6 +7,9 @@
#include <gnumeric-config.h>
#include <gnumeric.h>
#include <Python.h>
#ifdef WITH_PYGTK
#include "pygobject.h"
#endif
#include <glib.h>
#include <libgnome/libgnome.h>
#include <gal/util/e-xml-utils.h>
......@@ -90,11 +93,16 @@ initialize_python_if_needed (void)
/* Python's convertenviron has gotten into its head that it can
write to the strings in the environment. We have little choice
but to allocate a copy of everything. */
/* Fixed in Python 2.0. JK */
for (i = 0; environ[i]; i++)
environ[i] = g_strdup (environ[i]);
#endif
Py_Initialize ();
PyEval_InitThreads ();
#ifdef WITH_PYGTK
init_pygobject ();
#endif
python_initialized = TRUE;
}
}
......@@ -295,20 +303,37 @@ typedef struct {
} ServiceLoaderDataFileOpener;
static gboolean
gnumeric_plugin_loader_python_func_file_probe (GnumFileOpener const *fo, PluginService *service,
const gchar *file_name, FileProbeLevel pl)
gnumeric_plugin_loader_python_func_file_probe (GnumFileOpener const *fo,
PluginService *service,
GsfInput *input,
FileProbeLevel pl)
{
#ifndef WITH_PYGTK
g_warning ("Probing from Python plugins requires gnome-python "
"and Python bindings for libgsf");
return FALSE;
#else
ServiceLoaderDataFileOpener *loader_data;
PyObject *probe_result;
PyObject *probe_result = NULL;
PyObject *input_wrapper;
gboolean result;
g_return_val_if_fail (service != NULL, FALSE);
g_return_val_if_fail (file_name != NULL, FALSE);
g_return_val_if_fail (input != NULL, FALSE);
loader_data = (ServiceLoaderDataFileOpener *) plugin_service_get_loader_data (service);
switch_python_interpreter_if_needed (GNUMERIC_PLUGIN_LOADER_PYTHON (plugin_info_get_loader (service->plugin))->py_interpreter_info);
probe_result = PyObject_CallFunction
(loader_data->python_func_file_probe, (char *) "s", file_name);
input_wrapper = pygobject_new (G_OBJECT (input));
if (input_wrapper == NULL) {
g_warning (convert_python_exception_to_string ());
clear_python_error_if_needed ();
}
if (input_wrapper != NULL) {
probe_result = PyObject_CallFunction
(loader_data->python_func_file_probe,
(char *) "O", input_wrapper);
Py_DECREF (input_wrapper);
}
if (probe_result != NULL) {
result = PyObject_IsTrue (probe_result);
Py_DECREF (probe_result);
......@@ -318,26 +343,41 @@ gnumeric_plugin_loader_python_func_file_probe (GnumFileOpener const *fo, PluginS
}
return result;
#endif
}
static void
gnumeric_plugin_loader_python_func_file_open (GnumFileOpener const *fo, PluginService *service,
IOContext *io_context, WorkbookView *wb_view,
const gchar *file_name)
gnumeric_plugin_loader_python_func_file_open (GnumFileOpener const *fo,
PluginService *service,
IOContext *io_context,
WorkbookView *wb_view,
GsfInput *input)
{
#ifndef WITH_PYGTK
gnumeric_io_error_string
(io_context,
"File opening from python plugins requires gnome-python "
"and Python bindings for libgsf");
#else
ServiceLoaderDataFileOpener *loader_data;
Sheet *sheet;
PyObject *open_result;
PyObject *open_result = NULL;
PyObject *input_wrapper;
g_return_if_fail (service != NULL);
g_return_if_fail (file_name != NULL);
g_return_if_fail (input != NULL);
loader_data = (ServiceLoaderDataFileOpener *) plugin_service_get_loader_data (service);
switch_python_interpreter_if_needed (GNUMERIC_PLUGIN_LOADER_PYTHON (plugin_info_get_loader (service->plugin))->py_interpreter_info);
sheet = sheet_new (wb_view_workbook (wb_view), _("Some name"));
open_result = PyObject_CallFunction
(loader_data->python_func_file_open,
(char *) "Ns", py_new_Sheet_object (sheet), file_name);
input_wrapper = pygobject_new (G_OBJECT (input));
if (input_wrapper != NULL) {
open_result = PyObject_CallFunction
(loader_data->python_func_file_open,
(char *) "NO",
py_new_Sheet_object (sheet), input_wrapper);
Py_DECREF (input_wrapper);
}
if (open_result != NULL) {
Py_DECREF (open_result);
workbook_sheet_attach (wb_view_workbook (wb_view), sheet, NULL);
......@@ -346,6 +386,7 @@ gnumeric_plugin_loader_python_func_file_open (GnumFileOpener const *fo, PluginSe
clear_python_error_if_needed ();
sheet_destroy (sheet);
}
#endif
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment