[gnumeric] Port to Python3. [#419]
- From: Jean Bréfort <jbrefort src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Port to Python3. [#419]
- Date: Mon, 29 Jun 2020 08:20:17 +0000 (UTC)
commit 8e2f442e88a82f3a639f7b0ee5cd8760db20b172
Author: Jean Brefort <jean brefort normalesup org>
Date: Mon Jun 29 10:19:45 2020 +0200
Port to Python3. [#419]
ChangeLog | 4 +
NEWS | 1 +
configure.ac | 10 +-
plugins/py-func/ChangeLog | 4 +
plugins/py-func/py_func.py | 2 +-
plugins/python-loader/ChangeLog | 4 +
plugins/python-loader/gnm-py-interpreter.c | 37 +-
plugins/python-loader/gnm-python.c | 1 +
plugins/python-loader/py-console.c | 15 +
plugins/python-loader/py-gnumeric.c | 1825 +++-------------------------
plugins/python-loader/py-gnumeric.h | 9 +-
plugins/python-loader/python-loader.c | 26 +-
12 files changed, 244 insertions(+), 1694 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d27a61b7f..960ff2e74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2020-06-29 Jean Brefort <jean brefort normalesup org>
+
+ * configure.ac: port to Python3. [#419]
+
2020-06-27 Morten Welinder <terra gnome org>
* src/dependent.c (link_unlink_cellrange_dep): Take a GnmRange,
diff --git a/NEWS b/NEWS
index 9b0168d2f..1f313ee4a 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ Andreas:
Jean:
* Fix xlsx object non-import crash.
* Fix in-place graph data problem. [#492]
+ * Port to Python3. [#419]
Morten:
* Fix performance issue with sample_datasource. [#491]
diff --git a/configure.ac b/configure.ac
index 636f4f306..3bb56b369 100644
--- a/configure.ac
+++ b/configure.ac
@@ -900,21 +900,17 @@ AM_CONDITIONAL(HAVE_PYTHON_GI, test "x$have_python_gi" = "xyes")
if test "x$python_msg" = xyes; then
- # We're checking for python2 here, but we are likely to find python3.
- # That's by design.
- # Python2 is dead (or at least dying).
- BIG_CHECKING([for python = 2.x])
+ BIG_CHECKING([for python = 3.x])
[PY_VERSION=`$PYTHON -c 'import sys ; sys.stdout.write(sys.version[0:3])'`
major_ver=`$PYTHON -c 'import sys ; sys.stdout.write(sys.version[0:1])'`]
- if test "x$major_ver" = "x2"; then
+ if test "x$major_ver" = "x3"; then
AC_MSG_RESULT(yes)
if test "x$with_native_win32" = xyes ; then
- # 2.x on linux, 2x on win32
+ # 3.x on linux, 3x on win32
PY_VERSION=`echo $PY_VERSION | sed -e 's/\\.//'`
fi
else
AC_MSG_RESULT([no. $PYTHON is version $PY_VERSION])
- python_msg="No. This doesn't work with python3+ yet. No ETA."
fi
fi
diff --git a/plugins/py-func/ChangeLog b/plugins/py-func/ChangeLog
index 1b0772bde..48818e768 100644
--- a/plugins/py-func/ChangeLog
+++ b/plugins/py-func/ChangeLog
@@ -1,3 +1,7 @@
+2020-06-29 Jean Brefort <jean brefort normalesup org>
+
+ * py_func.py: port to Python3. [#419]
+
2020-05-09 Morten Welinder <terra gnome org>
* Release 1.12.47
diff --git a/plugins/py-func/py_func.py b/plugins/py-func/py_func.py
index 8b56fce49..681d1c045 100644
--- a/plugins/py-func/py_func.py
+++ b/plugins/py-func/py_func.py
@@ -15,7 +15,7 @@ def func_printf(format, *args):
try:
val = format % args
except TypeError:
- raise GnumericError, GnumericErrorVALUE
+ raise GnumericError(GnumericErrorVALUE)
else:
return val
diff --git a/plugins/python-loader/ChangeLog b/plugins/python-loader/ChangeLog
index 421287019..b121786c0 100644
--- a/plugins/python-loader/ChangeLog
+++ b/plugins/python-loader/ChangeLog
@@ -1,3 +1,7 @@
+2020-06-29 Jean Brefort <jean brefort normalesup org>
+
+ * all: port to Python3. [#419]
+
2020-05-09 Morten Welinder <terra gnome org>
* Release 1.12.47
diff --git a/plugins/python-loader/gnm-py-interpreter.c b/plugins/python-loader/gnm-py-interpreter.c
index 2d0969736..0f9ff3fa0 100644
--- a/plugins/python-loader/gnm-py-interpreter.c
+++ b/plugins/python-loader/gnm-py-interpreter.c
@@ -21,7 +21,7 @@ struct _GnmPyInterpreter {
GObject parent_instance;
PyThreadState *py_thread_state;
- PyObject *stringio_class;
+ PyTypeObject *stringio_class;
GOPlugin *plugin;
};
@@ -77,7 +77,7 @@ gnm_py_interpreter_class_init (GObjectClass *gobject_class)
G_TYPE_NONE, 0);
}
-static char *plugin_argv[] = {(char *) "/dev/null/python/is/buggy/gnumeric", NULL};
+static wchar_t *plugin_argv[] = {(wchar_t *) L"/dev/null/python/is/buggy/gnumeric", NULL};
GnmPyInterpreter *
gnm_py_interpreter_new (GOPlugin *plugin)
@@ -99,7 +99,9 @@ gnm_py_interpreter_new (GOPlugin *plugin)
interpreter->plugin = plugin;
PySys_SetArgv (G_N_ELEMENTS (plugin_argv) - 1, plugin_argv);
- py_initgnumeric (interpreter);
+ gnm_py_interpreter_switch_to (interpreter);
+ if (plugin != NULL)
+ py_gnumeric_add_plugin (py_initgnumeric (), interpreter);
return interpreter;
}
@@ -140,7 +142,7 @@ run_print_string (const char *cmd, PyObject *stdout_obj)
v = PyRun_String ((char *) cmd, Py_single_input, d, d);
if (!v)
PyErr_Print ();
- if (Py_FlushLine () != 0)
+ if (PyFile_WriteString ("\n", stdout_obj) != 0)
PyErr_Clear ();
if (v && v != Py_None && stdout_obj) {
if (PyFile_WriteObject (v, stdout_obj, Py_PRINT_RAW) != 0)
@@ -171,26 +173,30 @@ gnm_py_interpreter_run_string (GnmPyInterpreter *interpreter, const char *cmd,
sys_module_dict = PyModule_GetDict (sys_module);
g_return_if_fail (sys_module_dict != NULL);
if (interpreter->stringio_class == NULL) {
- PyObject *stringio_module, *stringio_module_dict;
+ PyObject *stringio_module, *stringio_module_dict, *sublist;
- stringio_module = PyImport_ImportModule ((char *) "StringIO");
+ sublist = PyList_New (0);
+ PyList_Insert (sublist, 0, PyUnicode_FromString ((char const *) "StringIO"));
+ stringio_module = PyImport_ImportModule ((char const *) "io");
+ Py_DECREF (sublist);
if (stringio_module == NULL)
PyErr_Print ();
g_return_if_fail (stringio_module != NULL);
stringio_module_dict = PyModule_GetDict (stringio_module);
g_return_if_fail (stringio_module_dict != NULL);
- interpreter->stringio_class
- = PyDict_GetItemString (stringio_module_dict,
- (char *) "StringIO");
+ interpreter->stringio_class =
+ (PyTypeObject *) PyDict_GetItemString (stringio_module_dict,
+
(char *) "StringIO");
g_return_if_fail (interpreter->stringio_class != NULL);
Py_INCREF (interpreter->stringio_class);
}
if (opt_stdout != NULL) {
- stdout_obj = PyInstance_New(interpreter->stringio_class,
+ stdout_obj = PyType_GenericNew(interpreter->stringio_class,
NULL, NULL);
if (stdout_obj == NULL)
PyErr_Print ();
g_return_if_fail (stdout_obj != NULL);
+ PyObject_CallMethod (stdout_obj, (char *) "__init__", NULL);
saved_stdout_obj = PyDict_GetItemString (sys_module_dict,
(char *) "stdout");
g_return_if_fail (saved_stdout_obj != NULL);
@@ -199,11 +205,12 @@ gnm_py_interpreter_run_string (GnmPyInterpreter *interpreter, const char *cmd,
stdout_obj);
}
if (opt_stderr != NULL) {
- stderr_obj = PyInstance_New(interpreter->stringio_class,
+ stderr_obj = PyType_GenericNew(interpreter->stringio_class,
NULL, NULL);
if (stderr_obj == NULL)
PyErr_Print ();
g_return_if_fail (stderr_obj != NULL);
+ PyObject_CallMethod (stderr_obj, (char *) "__init__", NULL);
saved_stderr_obj = PyDict_GetItemString (sys_module_dict,
(char *) "stderr");
g_return_if_fail (saved_stderr_obj != NULL);
@@ -218,8 +225,8 @@ gnm_py_interpreter_run_string (GnmPyInterpreter *interpreter, const char *cmd,
Py_DECREF (saved_stdout_obj);
py_str = PyObject_CallMethod (stdout_obj, (char *) "getvalue",
NULL);
- if (py_str && PyString_Check (py_str))
- *opt_stdout = g_strdup (PyString_AsString (py_str));
+ if (py_str && PyUnicode_Check (py_str))
+ *opt_stdout = g_strdup (PyUnicode_AsUTF8 (py_str));
else
*opt_stdout = NULL;
if (py_str == NULL)
@@ -232,8 +239,8 @@ gnm_py_interpreter_run_string (GnmPyInterpreter *interpreter, const char *cmd,
Py_DECREF (saved_stderr_obj);
py_str = PyObject_CallMethod (stderr_obj, (char *) "getvalue",
NULL);
- if (py_str && PyString_Check (py_str))
- *opt_stderr = g_strdup (PyString_AsString (py_str));
+ if (py_str && PyUnicode_Check (py_str))
+ *opt_stderr = g_strdup (PyUnicode_AsUTF8 (py_str));
else
*opt_stderr = NULL;
if (py_str == NULL)
diff --git a/plugins/python-loader/gnm-python.c b/plugins/python-loader/gnm-python.c
index 7a8a99bb4..d49319114 100644
--- a/plugins/python-loader/gnm-python.c
+++ b/plugins/python-loader/gnm-python.c
@@ -121,6 +121,7 @@ gnm_python_object_get (GOErrorInfo **err)
{
GO_INIT_RET_ERROR_INFO (err);
if (!Py_IsInitialized ()) {
+ PyImport_AppendInittab ("Gnumeric", py_initgnumeric);
Py_Initialize ();
#ifdef WITH_THREAD
PyEval_InitThreads ();
diff --git a/plugins/python-loader/py-console.c b/plugins/python-loader/py-console.c
index 6dea03080..dd1ad3bb6 100644
--- a/plugins/python-loader/py-console.c
+++ b/plugins/python-loader/py-console.c
@@ -1,3 +1,4 @@
+
/*
* py-console.c: Python console.
*
@@ -120,6 +121,20 @@ app_cline_entered (GnmPyCommandLine *cline)
g_return_if_fail (app != NULL);
cmd = g_strstrip (g_strdup (gtk_entry_get_text (GTK_ENTRY (cline))));
+ while (*cmd == ' ')
+ cmd++;
+ if (!strncmp (cmd, "quit", 4)) {
+ /* check if the non space character is a left bracket */
+ char *cur = cmd + 4;
+ while (*cur && g_unichar_isspace (g_utf8_get_char (cur)))
+ cur = g_utf8_next_char (cur);
+ if (*cur == '(') {
+ /* don't close gnumeric, just the console */
+ gtk_widget_destroy (app->win);
+ app = NULL;
+ return;
+ }
+ }
msg = g_strdup_printf (">>> %s\n", cmd);
app_text_print (msg, FORMAT_COMMAND, FALSE);
g_free (msg);
diff --git a/plugins/python-loader/py-gnumeric.c b/plugins/python-loader/py-gnumeric.c
index b09df5a54..9b3e9509e 100644
--- a/plugins/python-loader/py-gnumeric.c
+++ b/plugins/python-loader/py-gnumeric.c
@@ -29,17 +29,13 @@
#define NO_IMPORT_PYGOBJECT
#include <pygobject.h>
+static PyObject *GnmModule = NULL;
+
static PyTypeObject py_Boolean_object_type;
typedef struct _py_Boolean_object py_Boolean_object;
static PyObject *py_new_Boolean_object (gboolean value);
static gboolean py_Boolean_as_gboolean (py_Boolean_object *self);
-static PyTypeObject py_CellPos_object_type;
-typedef struct _py_CellPos_object py_CellPos_object;
-
-static PyTypeObject py_Range_object_type;
-typedef struct _py_Range_object py_Range_object;
-
static PyTypeObject py_CellRef_object_type;
typedef struct _py_CellRef_object py_CellRef_object;
@@ -48,110 +44,19 @@ typedef struct _py_RangeRef_object py_RangeRef_object;
static PyObject *py_new_RangeRef_object (GnmRangeRef const *range_ref);
static GnmRangeRef *py_RangeRef_as_RangeRef (py_RangeRef_object *self);
-static PyTypeObject py_Style_object_type;
-typedef struct _py_Style_object py_Style_object;
-
-static PyTypeObject py_Cell_object_type;
-typedef struct _py_Cell_object py_Cell_object;
-
-static PyTypeObject py_Sheet_object_type;
-typedef struct _py_Sheet_object py_Sheet_object;
-
-static PyTypeObject py_Workbook_object_type;
-typedef struct _py_Workbook_object py_Workbook_object;
-
-static PyTypeObject py_Gui_object_type;
-typedef struct _py_Gui_object py_Gui_object;
-
-static PyTypeObject py_GnmPlugin_object_type;
-typedef struct _py_GnmPlugin_object py_GnmPlugin_object;
-
typedef struct _py_GnumericFunc_object py_GnumericFunc_object;
static PyTypeObject py_GnumericFunc_object_type;
typedef struct _py_GnumericFuncDict_object py_GnumericFuncDict_object;
static PyTypeObject py_GnumericFuncDict_object_type;
+static PyTypeObject py_GnmPlugin_object_type;
+typedef struct _py_GnmPlugin_object py_GnmPlugin_object;
+
/*
Available types, attributes, methods, etc.:
(please update this list after adding/removing anything)
-Boolean:
-
-GnmCellPos:
- Attributes (read-only):
- - col
- - row
- Methods:
- - get_tuple
- str
-
-Range:
- Attributes (read-only):
- - start
- - end
- Methods:
- - get_tuple
-
-CellRef:
- Attributes (read-only):
- - col
- - row
- - sheet
- - col_relative
- - row_relative
-
-RangeRef:
- Attributes (read-only):
- - start
- - end
- Methods:
- - get_tuple
-
-GnmStyle:
- Methods:
- - set_font_bold
- - get_font_bold
- - set_font_italic
- - get_font_italic
- - set_font_strike
- - get_font_strike
- - set_font_size
- - get_font_size
- - set_wrap_text
- - get_wrap_text
-
-Cell:
- Methods:
- - set_text
- - get_style
- - get_value
- - get_rendered_text
- - get_entered_text
-
-Sheet:
- Methods:
- - cell_fetch
- - style_get
- - style_apply_range
- - style_set_range
- - style_set_pos
- - get_extent
- - rename
- - get_name_unquoted
- subscript ([col,row] == cell_fetch)
-
-Workbook:
- Methods:
- - sheets
- - sheet_add ([name, insert_after_position])
- - gui_add
-
-Gui:
- Methods:
- - get_workbook
- - get_window
-
GnumericFunc:
call
@@ -170,13 +75,6 @@ Module Gnumeric:
- TRUE/FALSE (values of type Boolean)
- GnumericError (exception), GnumericError* (std exception values)
- functions (dictionary containing all Gnumeric functions)
- - plugin_info (value of type GOPlugin)
- Methods:
- - GnmStyle (creates GnmStyle object with default style, uses gnm_style_new_default())
- - GnmCellPos (creates GnmCellPos object)
- - Range (creates Range Object)
- - workbooks
- - workbook_new
*/
@@ -187,7 +85,9 @@ Module Gnumeric:
#define GNUMERIC_MODULE_SET(key, val) \
PyDict_SetItemString (PyModule_GetDict (GNUMERIC_MODULE), (char *) (key), val)
#define SET_EVAL_POS(val) \
- GNUMERIC_MODULE_SET ("Gnumeric_eval_pos", PyCObject_FromVoidPtr (val, NULL))
+ GNUMERIC_MODULE_SET ("Gnumeric_eval_pos", PyCapsule_New (val, "eval_pos", NULL))
+#define UNSET_EVAL_POS \
+ PyDict_DelItemString (PyModule_GetDict (GNUMERIC_MODULE), "Gnumeric_eval_pos")
static GnmValue *
py_obj_to_gnm_value (const GnmEvalPos *eval_pos, PyObject *py_val)
@@ -206,12 +106,12 @@ py_obj_to_gnm_value (const GnmEvalPos *eval_pos, PyObject *py_val)
ret_val = value_new_empty ();
} else if (py_val_type == (PyObject *) &py_Boolean_object_type) {
ret_val = value_new_bool (py_Boolean_as_gboolean ((py_Boolean_object *) py_val));
- } else if (PyInt_Check (py_val)) {
- ret_val = value_new_int ((gint) PyInt_AsLong (py_val));
+ } else if (PyLong_Check (py_val)) {
+ ret_val = value_new_int ((gint) PyLong_AsLong (py_val));
} else if (PyFloat_Check (py_val)) {
ret_val = value_new_float ((gnm_float) PyFloat_AsDouble (py_val));
- } else if (PyString_Check (py_val)) {
- ret_val = value_new_string (PyString_AsString (py_val));
+ } else if (PyUnicode_Check (py_val)) {
+ ret_val = value_new_string (PyUnicode_AsUTF8 (py_val));
} else if (py_val_type == (PyObject *) &py_RangeRef_object_type) {
GnmRangeRef *range_ref;
@@ -256,7 +156,7 @@ py_obj_to_gnm_value (const GnmEvalPos *eval_pos, PyObject *py_val)
py_val_type_str = PyObject_Str (py_val_type);
msg = g_strdup_printf (_("Unsupported Python type: %s"),
- PyString_AsString (py_val_type_str));
+ PyUnicode_AsUTF8 (py_val_type_str));
ret_val = value_new_error (eval_pos, msg);
g_free (msg);
Py_DECREF (py_val_type_str);
@@ -280,7 +180,7 @@ py_exc_to_string (void)
if (exc_value != NULL) {
exc_value_str = PyObject_Str (exc_value);
g_assert (exc_value_str != NULL);
- error_str = g_strdup (PyString_AsString (exc_value_str));
+ error_str = g_strdup (PyUnicode_AsUTF8 (exc_value_str));
} else {
error_str = g_strdup (_("Unknown error"));
}
@@ -289,11 +189,11 @@ py_exc_to_string (void)
if (exc_value != NULL) {
exc_value_str = PyObject_Str (exc_value);
error_str = g_strdup_printf (_("Python exception (%s: %s)"),
- PyString_AsString (exc_type_str),
- PyString_AsString (exc_value_str));
+ PyUnicode_AsUTF8 (exc_type_str),
+ PyUnicode_AsUTF8 (exc_value_str));
} else {
error_str = g_strdup_printf (_("Python exception (%s)"),
- PyString_AsString (exc_type_str));
+ PyUnicode_AsUTF8 (exc_type_str));
}
}
@@ -332,7 +232,7 @@ gnm_value_to_py_obj (const GnmEvalPos *eval_pos, const GnmValue *val)
py_val = PyFloat_FromDouble (value_get_as_float (val));
break;
case VALUE_STRING:
- py_val = PyString_FromString (value_peek_string (val));
+ py_val = PyUnicode_FromString (value_peek_string (val));
break;
case VALUE_CELLRANGE:
py_val = py_new_RangeRef_object (&val->v_range.cell);
@@ -371,9 +271,9 @@ gnm_value_to_py_obj (const GnmEvalPos *eval_pos, const GnmValue *val)
static const GnmEvalPos *
get_eval_pos (void)
{
- PyObject *gep = GNUMERIC_MODULE_GET ("Gnumeric_eval_pos");
+ PyObject *gep = GNUMERIC_MODULE_GET ("Gnumeric_eval_pos");
- return gep ? PyCObject_AsVoidPtr (gep) : NULL;
+ return gep ? PyCapsule_GetPointer (gep, "eval_pos") : NULL;
}
static PyObject *
@@ -430,7 +330,7 @@ call_python_function (PyObject *python_fn, GnmEvalPos const *eval_pos, gint n_ar
gboolean eval_pos_set;
g_return_val_if_fail (python_fn != NULL && PyCallable_Check (python_fn), NULL);
-
+
python_args = PyTuple_New (n_args);
g_return_val_if_fail (python_args != NULL, NULL);
for (i = 0; i < n_args; i++) {
@@ -453,7 +353,7 @@ call_python_function (PyObject *python_fn, GnmEvalPos const *eval_pos, gint n_ar
PyErr_Clear ();
}
if (eval_pos_set) {
- SET_EVAL_POS (NULL);
+ UNSET_EVAL_POS;
}
return ret_value;
@@ -478,7 +378,7 @@ py_Boolean_as_gboolean (py_Boolean_object *self)
static PyObject *
py_Boolean_object_str (py_Boolean_object *self)
{
- return PyString_FromString (self->value ? "True" : "False");
+ return PyUnicode_FromString (self->value ? "True" : "False");
}
static void
@@ -502,245 +402,11 @@ py_new_Boolean_object (gboolean value)
}
static PyTypeObject py_Boolean_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "Boolean", /* tp_name */
- sizeof (py_Boolean_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_Boolean_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- (reprfunc) py_Boolean_object_str, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
-};
-
-/*
- * GnmCellPos
- */
-
-struct _py_CellPos_object {
- PyObject_HEAD
- GnmCellPos cell_pos;
-};
-
-static PyObject *
-py_CellPos_get_tuple_method (py_CellPos_object *self, PyObject *args);
-
-static struct PyMethodDef py_CellPos_object_methods[] = {
- {(char *) "get_tuple", (PyCFunction) py_CellPos_get_tuple_method,
- METH_VARARGS},
- {NULL, NULL}
-};
-
-#if 0
-static GnmCellPos *
-py_CellPos_as_CellPos (py_CellPos_object *self)
-{
- return &self->cell_pos;
-}
-#endif
-
-static PyObject *
-py_CellPos_get_tuple_method (py_CellPos_object *self, PyObject *args)
-{
- if (!PyArg_ParseTuple (args, (char *) ":get_tuple")) {
- return NULL;
- }
-
- return Py_BuildValue ((char *) "(ii)", self->cell_pos.col, self->cell_pos.row);
-}
-
-static PyObject *
-py_CellPos_object_getattr (py_CellPos_object *self, gchar *name)
-{
- if (strcmp (name, "col") == 0) {
- return Py_BuildValue ((char *) "i", self->cell_pos.col);
- } else if (strcmp (name, "row") == 0) {
- return Py_BuildValue ((char *) "i", self->cell_pos.row);
- } else {
- return Py_FindMethod (py_CellPos_object_methods, (PyObject *) self, name);
- }
-}
-
-static void
-py_CellPos_object_dealloc (py_CellPos_object *self)
-{
- PyObject_Del (self);
-}
-
-static PyObject *
-py_CellPos_object_str (py_CellPos_object *self)
-{
- return PyString_FromString
- ((char *) cellpos_as_string (&self->cell_pos));
-}
-
-static PyObject *
-py_new_CellPos_object (const GnmCellPos *cell_pos)
-{
- py_CellPos_object *self;
-
- self = PyObject_NEW (py_CellPos_object, &py_CellPos_object_type);
- if (self == NULL) {
- return NULL;
- }
- self->cell_pos = *cell_pos;
-
- return (PyObject *) self;
-}
-
-static PyObject *
-py_new_CellPos_object_from_col_row (gint col, gint row)
-{
- GnmCellPos cell_pos;
-
- cell_pos.col = col;
- cell_pos.row = row;
-
- return py_new_CellPos_object (&cell_pos);
-}
-
-static PyTypeObject py_CellPos_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char * ) "CellPos", /* tp_name */
- sizeof (py_CellPos_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_CellPos_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_CellPos_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- (reprfunc) &py_CellPos_object_str, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
-};
-
-/*
- * Range
- */
-
-struct _py_Range_object {
- PyObject_HEAD
- GnmRange range;
-};
-
-static PyObject *
-py_Range_get_tuple_method (py_Range_object *self, PyObject *args);
-
-static struct PyMethodDef py_Range_object_methods[] = {
- {(char *) "get_tuple", (PyCFunction) py_Range_get_tuple_method,
- METH_VARARGS},
- {NULL, NULL}
-};
-
-#if 0
-static GnmRange *
-py_Range_as_Range (py_Range_object *self)
-{
- return &self->range;
-}
-#endif
-
-static PyObject *
-py_Range_get_tuple_method (py_Range_object *self, PyObject *args)
-{
- if (!PyArg_ParseTuple (args, (char *) ":get_tuple")) {
- return NULL;
- }
-
- return Py_BuildValue ((char *) "(iiii)",
- self->range.start.col, self->range.start.row,
- self->range.end.col, self->range.end.row);
-}
-
-static PyObject *
-py_Range_object_getattr (py_Range_object *self, gchar *name)
-{
- if (strcmp (name, "start") == 0) {
- return py_new_CellPos_object (&self->range.start);
- } else if (strcmp (name, "end") == 0) {
- return py_new_CellPos_object (&self->range.end);
- } else {
- return Py_FindMethod (py_Range_object_methods, (PyObject *) self, name);
- }
-}
-
-static void
-py_Range_object_dealloc (py_Range_object *self)
-{
- PyObject_Del (self);
-}
-
-static PyObject *
-py_new_Range_object (GnmRange const *range)
-{
- py_Range_object *self;
-
- self = PyObject_NEW (py_Range_object, &py_Range_object_type);
- if (self == NULL) {
- return NULL;
- }
- self->range = *range;
-
- return (PyObject *) self;
-}
-
-static PyObject *
-py_new_Range_object_from_start_end (const GnmCellPos *start, const GnmCellPos *end)
-{
- GnmRange range;
-
- range.start = *start;
- range.end = *end;
-
- return py_new_Range_object (&range);
-}
-
-static PyTypeObject py_Range_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "Range", /* tp_name */
- sizeof (py_Range_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_Range_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_Range_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = (char *) "Boolean",
+ .tp_basicsize = sizeof (py_Boolean_object),
+ .tp_dealloc = (destructor) &py_Boolean_object_dealloc,
+ .tp_str = (reprfunc) py_Boolean_object_str
};
/*
@@ -781,7 +447,7 @@ py_CellRef_object_getattr (py_CellRef_object *self, gchar *name)
result = Py_BuildValue ((char *) "i", self->cell_ref.row);
} else if (strcmp (name, "sheet") == 0) {
if (self->cell_ref.sheet)
- result = py_new_Sheet_object (self->cell_ref.sheet);
+ result = pygobject_new (G_OBJECT (self->cell_ref.sheet));
else {
Py_INCREF (Py_None);
result = Py_None;
@@ -793,8 +459,7 @@ py_CellRef_object_getattr (py_CellRef_object *self, gchar *name)
result = Py_BuildValue ((char *) "i",
self->cell_ref.row_relative ? 1 : 0);
} else {
- result = Py_FindMethod (py_CellRef_object_methods,
- (PyObject *) self, name);
+ result = PyObject_CallMethod ((PyObject *) self, name, NULL);
}
return result;
@@ -821,28 +486,12 @@ py_new_CellRef_object (GnmCellRef const *cell_ref)
}
static PyTypeObject py_CellRef_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "CellRef", /* tp_name */
- sizeof (py_CellRef_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_CellRef_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_CellRef_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = (char *) "CellRef",
+ .tp_basicsize = sizeof (py_CellRef_object),
+ .tp_dealloc = (destructor) &py_CellRef_object_dealloc,
+ .tp_getattr = (getattrfunc) &py_CellRef_object_getattr,
+ .tp_methods = py_CellRef_object_methods
};
/*
@@ -894,8 +543,7 @@ py_RangeRef_object_getattr (py_RangeRef_object *self, gchar *name)
} else if (strcmp (name, "end") == 0) {
return py_new_CellRef_object (&self->range_ref.b);
} else {
- return Py_FindMethod (py_RangeRef_object_methods,
- (PyObject *) self, name);
+ return PyObject_CallMethod ((PyObject *) self, name, NULL);
}
}
@@ -920,28 +568,12 @@ py_new_RangeRef_object (const GnmRangeRef *range_ref)
}
static PyTypeObject py_RangeRef_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "RangeRef", /* tp_name */
- sizeof (py_RangeRef_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_RangeRef_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_RangeRef_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = (char *) "RangeRef",
+ .tp_basicsize = sizeof (py_RangeRef_object),
+ .tp_dealloc = (destructor) &py_RangeRef_object_dealloc,
+ .tp_getattr = (getattrfunc) &py_RangeRef_object_getattr,
+ .tp_methods = py_RangeRef_object_methods /* */
};
/*
@@ -957,1132 +589,129 @@ struct _py_Style_object {
} u;
};
-static PyObject *
-py_gnm_style_set_font_bold_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_get_font_bold_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_set_font_italic_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_get_font_italic_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_set_font_strike_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_get_font_strike_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_set_font_size_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_get_font_size_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_set_wrap_text_method (py_Style_object *self, PyObject *args);
-static PyObject *
-py_gnm_style_get_wrap_text_method (py_Style_object *self, PyObject *args);
-
-static struct PyMethodDef py_Style_object_methods[] = {
- {(char *) "set_font_bold",
- (PyCFunction) py_gnm_style_set_font_bold_method, METH_VARARGS},
- {(char *) "get_font_bold",
- (PyCFunction) py_gnm_style_get_font_bold_method, METH_VARARGS},
- {(char *) "set_font_italic",
- (PyCFunction) py_gnm_style_set_font_italic_method, METH_VARARGS},
- {(char *) "get_font_italic",
- (PyCFunction) py_gnm_style_get_font_italic_method, METH_VARARGS},
- {(char *) "set_font_strike",
- (PyCFunction) py_gnm_style_set_font_strike_method, METH_VARARGS},
- {(char *) "get_font_strike",
- (PyCFunction) py_gnm_style_get_font_strike_method, METH_VARARGS},
- {(char *) "set_font_size",
- (PyCFunction) py_gnm_style_set_font_size_method, METH_VARARGS},
- {(char *) "get_font_size",
- (PyCFunction) py_gnm_style_get_font_size_method, METH_VARARGS},
- {(char *) "set_wrap_text",
- (PyCFunction) py_gnm_style_set_wrap_text_method, METH_VARARGS},
- {(char *) "get_wrap_text",
- (PyCFunction) py_gnm_style_get_wrap_text_method, METH_VARARGS},
- {NULL, NULL}
-};
+/*
+ * GnumericFunc
+ */
-static GnmStyle *
-get_rw_style (py_Style_object *self)
-{
- if (self->ro) {
- GnmStyle *tmp = gnm_style_dup (self->u.ro_style);
- gnm_style_unref (self->u.ro_style);
- self->ro = FALSE;
- self->u.rw_style = tmp;
- }
- return self->u.rw_style;
-}
+struct _py_GnumericFunc_object {
+ PyObject_HEAD
+ GnmFunc *fn_def;
+ GnmEvalPos *eval_pos;
+};
static PyObject *
-py_gnm_style_set_font_bold_method (py_Style_object *self, PyObject *args)
+py_GnumericFunc_call (py_GnumericFunc_object *self, PyObject *args, PyObject *keywords)
{
- gint bold;
-
- if (!PyArg_ParseTuple (args, (char *) "i:set_font_bold", &bold)) {
- return NULL;
- }
-
- gnm_style_set_font_bold (get_rw_style (self), bold);
-
- Py_INCREF (Py_None);
- return Py_None;
+ return python_call_gnumeric_function (self->fn_def, self->eval_pos, args);
}
-static PyObject *
-py_gnm_style_get_font_bold_method (py_Style_object *self, PyObject *args)
+static void
+py_GnumericFunc_object_dealloc (py_GnumericFunc_object *self)
{
- if (!PyArg_ParseTuple (args, (char *) ":get_font_bold")) {
- return NULL;
- }
+ g_return_if_fail (self != NULL);
- return Py_BuildValue ((char *) "i",
- gnm_style_get_font_bold (self->u.ro_style));
+ gnm_func_dec_usage (self->fn_def);
+ g_free (self->eval_pos);
+ PyObject_Del (self);
}
static PyObject *
-py_gnm_style_set_font_italic_method (py_Style_object *self, PyObject *args)
+py_new_GnumericFunc_object (GnmFunc *fn_def, const GnmEvalPos *opt_eval_pos)
{
- gint italic;
+ py_GnumericFunc_object *self;
- if (!PyArg_ParseTuple (args, (char *) "i:set_font_italic", &italic)) {
+ self = PyObject_NEW (py_GnumericFunc_object, &py_GnumericFunc_object_type);
+ if (self == NULL) {
return NULL;
}
- gnm_style_set_font_italic (get_rw_style (self), italic);
-
- Py_INCREF (Py_None);
- return Py_None;
-}
-
-static PyObject *
-py_gnm_style_get_font_italic_method (py_Style_object *self, PyObject *args)
-{
- if (!PyArg_ParseTuple (args, (char *) ":get_font_italic")) {
- return NULL;
+ gnm_func_inc_usage (fn_def);
+ self->fn_def = fn_def;
+ if (opt_eval_pos != NULL) {
+ self->eval_pos = g_new (GnmEvalPos, 1);
+ *self->eval_pos = *opt_eval_pos;
+ } else {
+ self->eval_pos = NULL;
}
- return Py_BuildValue ((char *) "i",
- gnm_style_get_font_italic (self->u.ro_style));
+ return (PyObject *) self;
}
-static PyObject *
-py_gnm_style_set_font_strike_method (py_Style_object *self, PyObject *args)
-{
- gint strike;
+static PyTypeObject py_GnumericFunc_object_type = {
+ PyVarObject_HEAD_INIT(NULL,0)
+ .tp_name = (char *) "GnumericFunc",
+ .tp_basicsize = sizeof (py_GnumericFunc_object),
+ .tp_dealloc = (destructor) &py_GnumericFunc_object_dealloc,
+ .tp_call = (ternaryfunc) py_GnumericFunc_call
+};
- if (!PyArg_ParseTuple (args, (char *) "i:set_font_strike", &strike)) {
- return NULL;
- }
+/*
+ * GnumericFuncDict
+ */
- gnm_style_set_font_strike (get_rw_style (self), strike);
+struct _py_GnumericFuncDict_object {
+ PyObject_HEAD
+ PyObject *module_dict;
+};
- Py_INCREF (Py_None);
- return Py_None;
-}
static PyObject *
-py_gnm_style_get_font_strike_method (py_Style_object *self, PyObject *args)
+py_GnumericFuncDict_subscript (py_GnumericFuncDict_object *self, PyObject *key)
{
- if (!PyArg_ParseTuple (args, (char *) ":get_font_strike")) {
+ gchar *fn_name;
+ GnmFunc *fn_def;
+
+ if (!PyArg_Parse(key, (char *) "s", &fn_name)) {
return NULL;
}
- return Py_BuildValue ((char *) "i",
- gnm_style_get_font_strike (self->u.ro_style));
-}
-
-static PyObject *
-py_gnm_style_set_font_size_method (py_Style_object *self, PyObject *args)
-{
- gdouble size;
-
- if (!PyArg_ParseTuple (args, (char *) "d:set_font_size", &size)) {
+ fn_def = gnm_func_lookup (fn_name, NULL);
+ if (fn_def == NULL) {
+ /* Py_INCREF (key); FIXME?? */
+ PyErr_SetObject (PyExc_KeyError, key);
return NULL;
}
- gnm_style_set_font_size (get_rw_style (self), size);
-
- Py_INCREF (Py_None);
- return Py_None;
+ return py_new_GnumericFunc_object (fn_def, NULL);
}
-static PyObject *
-py_gnm_style_get_font_size_method (py_Style_object *self, PyObject *args)
+static void
+py_GnumericFuncDict_object_dealloc (py_GnumericFuncDict_object *self)
{
- if (!PyArg_ParseTuple (args, (char *) ":set_font_size")) {
- return NULL;
- }
-
- return Py_BuildValue ((char *) "d",
- gnm_style_get_font_size (self->u.ro_style));
+ PyObject_Del (self);
}
static PyObject *
-py_gnm_style_set_wrap_text_method (py_Style_object *self, PyObject *args)
+py_new_GnumericFuncDict_object (PyObject *module_dict)
{
- gint wrap_text;
+ py_GnumericFuncDict_object *self;
- if (!PyArg_ParseTuple (args, (char * )"i:set_wrap_text",
- &wrap_text)) {
+ self = PyObject_NEW (py_GnumericFuncDict_object, &py_GnumericFuncDict_object_type);
+ if (self == NULL) {
return NULL;
}
- gnm_style_set_wrap_text (get_rw_style (self), wrap_text);
+ self->module_dict = module_dict;
- Py_INCREF (Py_None);
- return Py_None;
+ return (PyObject *) self;
}
-static PyObject *
-py_gnm_style_get_wrap_text_method (py_Style_object *self, PyObject *args)
-{
- if (!PyArg_ParseTuple (args, (char *) ":get_wrap_text")) {
- return NULL;
- }
-
- return Py_BuildValue ((char *) "i",
- gnm_style_get_wrap_text (self->u.ro_style));
-}
-
-static PyObject *
-py_Style_object_getattr (py_Style_object *self, gchar *name)
-{
- return Py_FindMethod (py_Style_object_methods, (PyObject *) self, name);
-}
-
-static void
-py_Style_object_dealloc (py_Style_object *self)
-{
- g_return_if_fail (self != NULL);
-
- gnm_style_unref (self->u.ro_style);
- PyObject_Del (self);
-}
-
-static PyObject *
-py_new_Style_object (GnmStyle *style)
-{
- py_Style_object *self;
-
- self = PyObject_NEW (py_Style_object, &py_Style_object_type);
- if (self == NULL) {
- return NULL;
- }
- self->u.rw_style = style;
- self->ro = FALSE;
-
- return (PyObject *) self;
-}
-static PyObject *
-py_new_Style_const_object (GnmStyle const *style)
-{
- py_Style_object *self;
-
- self = PyObject_NEW (py_Style_object, &py_Style_object_type);
- if (self == NULL) {
- return NULL;
- }
- gnm_style_ref (style);
- self->u.ro_style = style;
- self->ro = TRUE;
-
- return (PyObject *) self;
-}
-
-static PyTypeObject py_Style_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "GnmStyle", /* tp_name */
- sizeof (py_Style_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_Style_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_Style_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
-};
-
-/*
- * Cell
- */
-
-/*
- * FIXME: The GnmCell may be deleted behind our backs.
- */
-struct _py_Cell_object {
- PyObject_HEAD
- GnmCell *cell;
-};
-
-static PyObject *
-py_Cell_set_text_method (py_Cell_object *self, PyObject *args);
-static PyObject *
-py_Cell_get_gnm_style_method (py_Cell_object *self, PyObject *args);
-static PyObject *
-py_Cell_get_value_method (py_Cell_object *self, PyObject *args);
-static PyObject *
-py_Cell_get_value_as_string_method (py_Cell_object *self, PyObject *args);
-static PyObject *
-py_Cell_get_rendered_text_method (py_Cell_object *self, PyObject *args);
-static PyObject *
-py_Cell_get_entered_text_method (py_Cell_object *self, PyObject *args);
-
-static struct PyMethodDef py_Cell_object_methods[] = {
- {(char *) "set_text",
- (PyCFunction) py_Cell_set_text_method, METH_VARARGS},
- {(char *) "get_style",
- (PyCFunction) py_Cell_get_gnm_style_method, METH_VARARGS},
- {(char *) "get_value",
- (PyCFunction) py_Cell_get_value_method, METH_VARARGS},
- {(char *) "get_value_as_string",
- (PyCFunction) py_Cell_get_value_as_string_method, METH_VARARGS},
- {(char *) "get_rendered_text",
- (PyCFunction) py_Cell_get_rendered_text_method, METH_VARARGS},
- {(char *) "get_entered_text",
- (PyCFunction) py_Cell_get_entered_text_method, METH_VARARGS},
- {NULL, NULL}
-};
-
-#if 0
-static GnmCell *
-py_Cell_as_Cell (py_Cell_object *self)
-{
- return self->cell;
-}
-#endif
-
-static PyObject *
-py_Cell_set_text_method (py_Cell_object *self, PyObject *args)
-{
- gchar *text;
-
- if (!PyArg_ParseTuple (args, (char *) "s:set_text", &text)) {
- return NULL;
- }
-
- sheet_cell_set_text (self->cell, text, NULL);
-
- Py_INCREF (Py_None);
- return Py_None;
-}
-
-static PyObject *
-py_Cell_get_gnm_style_method (py_Cell_object *self, PyObject *args)
-{
- if (!PyArg_ParseTuple (args, (char *) ":get_style")) {
- return NULL;
- }
-
- return py_new_Style_const_object (gnm_cell_get_style (self->cell));
-}
-
-static PyObject *
-py_Cell_get_value_method (py_Cell_object *self, PyObject *args)
-{
- GnmEvalPos eval_pos;
-
- if (!PyArg_ParseTuple (args, (char *) ":get_value")) {
- return NULL;
- }
-
- (void) eval_pos_init_cell (&eval_pos, self->cell);
- return gnm_value_to_py_obj (&eval_pos, self->cell->value);
-}
-
-static PyObject *
-py_Cell_get_value_as_string_method (py_Cell_object *self, PyObject *args)
-{
- PyObject *py_ret_val;
- gchar *str;
-
- if (!PyArg_ParseTuple (args, (char *) ":get_value_as_string")) {
- return NULL;
- }
-
- str = value_get_as_string (self->cell->value);
- py_ret_val = PyString_FromString (str);
- g_free (str);
-
- return py_ret_val;
-}
-
-static PyObject *
-py_Cell_get_rendered_text_method (py_Cell_object *self, PyObject *args)
-{
- gchar *text;
- PyObject *py_text;
-
- if (!PyArg_ParseTuple (args, (char *) ":get_rendered_text")) {
- return NULL;
- }
-
- text = gnm_cell_get_rendered_text (self->cell);
- py_text = PyString_FromString (text);
- g_free (text);
-
- return py_text;
-}
-
-static PyObject *
-py_Cell_get_entered_text_method (py_Cell_object *self, PyObject *args)
-{
- gchar *text;
- PyObject *py_text;
-
- if (!PyArg_ParseTuple (args, (char *) ":get_entered_text")) {
- return NULL;
- }
-
- text = gnm_cell_get_entered_text (self->cell);
- py_text = PyString_FromString (text);
- g_free (text);
-
- return py_text;
-}
-
-static PyObject *
-py_Cell_object_getattr (py_Cell_object *self, gchar *name)
-{
- return Py_FindMethod (py_Cell_object_methods, (PyObject *) self, name);
-}
-
-static void
-py_Cell_object_dealloc (py_Cell_object *self)
-{
- PyObject_Del (self);
-}
-
-static PyObject *
-py_new_Cell_object (GnmCell *cell)
-{
- py_Cell_object *self;
-
- self = PyObject_NEW (py_Cell_object, &py_Cell_object_type);
- if (self == NULL) {
- return NULL;
- }
- self->cell = cell;
-
- return (PyObject *) self;
-}
-
-static PyTypeObject py_Cell_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "Cell", /* tp_name */
- sizeof (py_Cell_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_Cell_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_Cell_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
-};
-
-/*
- * Sheet
- */
-
-struct _py_Sheet_object {
- PyObject_HEAD
- Sheet *sheet;
-};
-
-static PyObject *
-py_sheet_cell_fetch_method (py_Sheet_object *self, PyObject *args);
-static PyObject *
-py_sheet_style_get_method (py_Sheet_object *self, PyObject *args);
-static PyObject *
-py_sheet_style_apply_range_method (py_Sheet_object *self, PyObject *args);
-static PyObject *
-py_sheet_style_set_range_method (py_Sheet_object *self, PyObject *args);
-static PyObject *
-py_sheet_style_set_pos_method (py_Sheet_object *self, PyObject *args);
-static PyObject *
-py_sheet_get_extent_method (py_Sheet_object *self, PyObject *args);
-static PyObject *
-py_sheet_rename_method (py_Sheet_object *self, PyObject *args);
-static PyObject *
-py_sheet_get_name_unquoted_method (py_Sheet_object *self, PyObject *args);
-
-static struct PyMethodDef py_Sheet_object_methods[] = {
- {(char *) "cell_fetch",
- (PyCFunction) py_sheet_cell_fetch_method, METH_VARARGS},
- {(char *) "style_get",
- (PyCFunction) py_sheet_style_get_method, METH_VARARGS},
- {(char *) "style_apply_range",
- (PyCFunction) py_sheet_style_apply_range_method, METH_VARARGS},
- {(char *) "style_set_range",
- (PyCFunction) py_sheet_style_set_range_method, METH_VARARGS},
- {(char *) "style_set_pos",
- (PyCFunction) py_sheet_style_set_pos_method, METH_VARARGS},
- {(char *) "get_extent",
- (PyCFunction) py_sheet_get_extent_method, METH_VARARGS},
- {(char *) "rename",
- (PyCFunction) py_sheet_rename_method, METH_VARARGS},
- {(char *) "get_name_unquoted",
- (PyCFunction) py_sheet_get_name_unquoted_method, METH_VARARGS},
- {NULL, NULL}
-};
-
-#if 0
-static Sheet *
-py_sheet_as_Sheet (py_Sheet_object *self)
-{
- return self->sheet;
-}
-#endif
-
-static PyObject *
-py_sheet_cell_fetch_method (py_Sheet_object *self, PyObject *args)
-{
- gint col, row;
- GnmCell *cell;
-
- if (!PyArg_ParseTuple (args, (char *) "ii:cell_fetch", &col, &row)) {
- return NULL;
- }
-
- cell = sheet_cell_fetch (self->sheet, col, row);
-
- return py_new_Cell_object (cell);
-}
-
-static PyObject *
-py_sheet_style_get_method (py_Sheet_object *self, PyObject *args)
-{
- gint c, r;
- py_CellPos_object *py_cell_pos;
-
- if (PyArg_ParseTuple (args, (char *) "ii:style_get", &c, &r)) {
- ;
- } else {
- PyErr_Clear ();
- if (!PyArg_ParseTuple (args, (char *) "O!:style_get",
- &py_CellPos_object_type, &py_cell_pos)) {
- return NULL;
- }
- c = py_cell_pos->cell_pos.col;
- r = py_cell_pos->cell_pos.row;
- }
-
- return py_new_Style_const_object (sheet_style_get (self->sheet, c, r));
-}
-
-static PyObject *
-py_sheet_style_apply_range_method (py_Sheet_object *self, PyObject *args)
-{
- py_Range_object *py_range;
- py_Style_object *py_style;
-
- if (!PyArg_ParseTuple (args, (char *) "O!O!:style_apply_range",
- &py_Range_object_type, &py_range,
- &py_Style_object_type, &py_style)) {
- return NULL;
- }
-
- sheet_style_apply_range (self->sheet, &py_range->range,
- gnm_style_dup (py_style->u.ro_style));
-
- Py_INCREF (Py_None);
- return Py_None;
-}
-
-static PyObject *
-py_sheet_style_set_range_method (py_Sheet_object *self, PyObject *args)
-{
- py_Range_object *py_range;
- py_Style_object *py_style;
-
- if (!PyArg_ParseTuple (args, (char *) "O!O!:style_set_range",
- &py_Range_object_type, &py_range,
- &py_Style_object_type, &py_style)) {
- return NULL;
- }
-
- sheet_style_set_range (self->sheet, &py_range->range,
- gnm_style_dup (py_style->u.ro_style));
-
- Py_INCREF (Py_None);
- return Py_None;
-}
-
-static PyObject *
-py_sheet_style_set_pos_method (py_Sheet_object *self, PyObject *args)
-{
- gint col, row;
- py_CellPos_object *py_cell_pos;
- py_Style_object *py_style;
-
- if (PyArg_ParseTuple (args, (char *) "iiO!:style_set_pos",
- &col, &row, &py_Style_object_type, &py_style)) {
- ;
- } else {
- PyErr_Clear ();
- if (!PyArg_ParseTuple (args, (char *) "O!O!:style_set_pos",
- &py_CellPos_object_type, &py_cell_pos,
- &py_Style_object_type, &py_style)) {
- return NULL;
- }
- }
- sheet_style_set_pos (self->sheet, col, row,
- gnm_style_dup (py_style->u.ro_style));
-
- Py_INCREF (Py_None);
- return Py_None;
-}
-
-static PyObject *
-py_sheet_get_extent_method (py_Sheet_object *self, PyObject *args)
-{
- GnmRange range;
-
- if (!PyArg_ParseTuple (args, (char *) ":get_extent")) {
- return NULL;
- }
-
- range = sheet_get_extent (self->sheet, FALSE, TRUE);
- return py_new_Range_object (&range);
-}
-
-static PyObject *
-py_sheet_rename_method (py_Sheet_object *self, PyObject *args)
-{
- gchar *new_name;
-
- if (!PyArg_ParseTuple (args, (char *) "s:rename", &new_name)) {
- return NULL;
- }
-
- g_object_set (self->sheet, "name", new_name, NULL);
-
- Py_INCREF (Py_None);
- return Py_None;
-}
-
-static PyObject *
-py_sheet_get_name_unquoted_method (py_Sheet_object *self, PyObject *args)
-{
- if (!PyArg_ParseTuple (args, (char *) ":get_name_unquoted")) {
- return NULL;
- }
-
- return PyString_FromString (self->sheet->name_unquoted);
-}
-
-static PyObject *
-py_sheet_subscript (py_Sheet_object *self, PyObject *key)
-{
- gint col, row;
- GnmCell *cell;
-
- if (!PyArg_ParseTuple (key, (char *) "ii", &col, &row)) {
- return NULL;
- }
-
- cell = sheet_cell_fetch (self->sheet, col, row);
-
- return py_new_Cell_object (cell);
-}
-
-static PyObject *
-py_Sheet_object_getattr (py_Sheet_object *self, gchar *name)
-{
- return Py_FindMethod (py_Sheet_object_methods, (PyObject *) self, name);
-}
-
-static void
-py_Sheet_object_dealloc (py_Sheet_object *self)
-{
- g_return_if_fail (self != NULL);
-
- g_object_unref (self->sheet);
- PyObject_Del (self);
-}
-
-PyObject *
-py_new_Sheet_object (Sheet *sheet)
-{
- py_Sheet_object *self;
-
- self = PyObject_NEW (py_Sheet_object, &py_Sheet_object_type);
- if (self == NULL) {
- return NULL;
- }
- self->sheet = sheet;
- g_object_ref (self->sheet);
-
- return (PyObject *) self;
-}
-
-static PyMappingMethods py_sheet_as_mapping = {
- 0, /* mp_length */
- (binaryfunc) &py_sheet_subscript, /* mp_subscript */
- 0 /* mp_ass_subscript */
-};
-
-static PyTypeObject py_Sheet_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "Sheet", /* tp_name */
- sizeof (py_Sheet_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_Sheet_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_Sheet_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- &py_sheet_as_mapping, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- NULL /* tp_doc */
-};
-
-/*
- * Workbook
- */
-
-struct _py_Workbook_object {
- PyObject_HEAD
- Workbook *wb;
-};
-
-#if 0
-static Workbook *
-py_Workbook_as_Workbook (py_Workbook_object *self)
-{
- return self->wb;
-}
-#endif
-
-static PyObject *
-py_Workbook_sheets (py_Workbook_object *self, PyObject *args)
-{
- GSList *sheets, *l;
- gint i;
- PyObject *py_sheets;
-
- if (!PyArg_ParseTuple (args, (char *) ":sheets")) {
- return NULL;
- }
-
- sheets = workbook_sheets (self->wb);
- py_sheets = PyTuple_New (g_slist_length (sheets));
- if (py_sheets == NULL) {
- return NULL;
- }
- for (l = sheets, i = 0; l != NULL; l = l->next, i++) {
- PyObject *py_sheet;
-
- py_sheet = py_new_Sheet_object ((Sheet *) l->data);
- g_assert (py_sheet);
- (void) PyTuple_SetItem (py_sheets, i, py_sheet);
- }
- g_slist_free (sheets);
-
- return py_sheets;
-}
-
-static PyObject *
-py_Workbook_sheet_add (py_Workbook_object *self, PyObject *args)
-{
- Sheet *sheet;
- char *name = NULL;
- int insert_before = -1;
-
- if (!PyArg_ParseTuple (args, (char *) "|zi:sheet_add"))
- return NULL;
-
- sheet = workbook_sheet_add (self->wb, insert_before, GNM_DEFAULT_COLS, GNM_DEFAULT_ROWS);
- if (sheet != NULL && name != NULL)
- g_object_set (sheet, "name", name, NULL);
- return py_new_Sheet_object (sheet);
-}
-
-static PyObject *
-py_Workbook_gui_add (py_Workbook_object *self, PyObject *args)
-{
- WBCGtk *wbcg;
- PyObject *result;
-
- if (!PyArg_ParseTuple (args, (char *) ":gui_add"))
- return NULL;
-
- if (workbook_sheet_count (self->wb) == 0)
- (void)workbook_sheet_add (self->wb, -1, GNM_DEFAULT_COLS, GNM_DEFAULT_ROWS);
-
- wbcg = wbc_gtk_new (NULL, self->wb, NULL, NULL);
- result = py_new_Gui_object (wbcg);
- g_object_unref (wbcg); /* py_new_Gui_object added a reference */
- return result;
-}
-
-static PyObject *
-py_Workbook_recalc (py_Workbook_object *self, PyObject *args)
-{
- workbook_recalc(self->wb);
- Py_RETURN_NONE;
-}
-
-static PyObject *
-py_Workbook_object_getattr (py_Workbook_object *self, gchar *name)
-{
- static struct PyMethodDef methods [] = {
- { (char *) "sheets", (PyCFunction) py_Workbook_sheets,
- METH_VARARGS},
- { (char *) "sheet_add", (PyCFunction) py_Workbook_sheet_add,
- METH_VARARGS},
- { (char *) "gui_add", (PyCFunction) py_Workbook_gui_add,
- METH_VARARGS},
- { (char *) "recalc", (PyCFunction) py_Workbook_recalc,
- METH_VARARGS},
- {NULL, NULL}
- };
- return Py_FindMethod (methods, (PyObject *) self, name);
-}
-
-static void
-py_Workbook_object_dealloc (py_Workbook_object *self)
-{
- g_return_if_fail (self != NULL);
-
- g_object_unref (self->wb);
- PyObject_Del (self);
-}
-
-PyObject *
-py_new_Workbook_object (Workbook *wb)
-{
- py_Workbook_object *self;
-
- self = PyObject_NEW (py_Workbook_object, &py_Workbook_object_type);
- if (self == NULL) {
- return NULL;
- }
- self->wb = wb;
- g_object_ref (wb);
-
- return (PyObject *) self;
-}
-
-static PyTypeObject py_Workbook_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "Workbook", /* tp_name */
- sizeof (py_Workbook_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_Workbook_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_Workbook_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
-};
-
-/*
- * Gui
- */
-
-struct _py_Gui_object {
- PyObject_HEAD
- WBCGtk *wbcg;
-};
-
-static PyObject *
-py_Gui_get_workbook (py_Gui_object *self, PyObject *args)
-{
- Workbook *workbook;
-
- if (!PyArg_ParseTuple (args, (char *) ":get_workbook")) {
- return NULL;
- }
-
- workbook = wb_control_get_workbook (GNM_WBC (self->wbcg));
-
- return py_new_Workbook_object (workbook);
-}
-
-static PyObject *
-py_Gui_get_window (py_Gui_object *self, PyObject *args)
-{
- GtkWindow *toplevel;
-
- if (!PyArg_ParseTuple (args, (char *) ":get_window")) {
- return NULL;
- }
-
- g_return_val_if_fail (_PyGObject_API != NULL, NULL);
-
- toplevel = wbcg_toplevel (self->wbcg);
-
- return pygobject_new (G_OBJECT(toplevel));
-}
-
-static PyObject *
-py_Gui_object_getattr (py_Gui_object *self, gchar *name)
-{
- static struct PyMethodDef methods [] = {
- { (char *) "get_workbook", (PyCFunction) py_Gui_get_workbook,
- METH_VARARGS},
- { (char *) "get_window", (PyCFunction) py_Gui_get_window,
- METH_VARARGS},
-
- {NULL, NULL}
- };
- return Py_FindMethod (methods, (PyObject *) self, name);
-}
-
-static void
-py_Gui_object_dealloc (py_Gui_object *self)
-{
- g_return_if_fail (self != NULL);
-
- g_object_unref (self->wbcg);
- PyObject_Del (self);
-}
-
-PyObject *
-py_new_Gui_object (WBCGtk *wbcg)
-{
- py_Gui_object *self;
-
- self = PyObject_NEW (py_Gui_object, &py_Gui_object_type);
- if (self == NULL) {
- return NULL;
- }
- self->wbcg = wbcg;
- g_object_ref (self->wbcg);
-
- return (PyObject *) self;
-}
-
-static PyTypeObject py_Gui_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "Gui", /* tp_name */
- sizeof (py_Gui_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_Gui_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_Gui_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
-};
-
-/*
- * GnumericFunc
- */
-
-struct _py_GnumericFunc_object {
- PyObject_HEAD
- GnmFunc *fn_def;
- GnmEvalPos *eval_pos;
-};
-
-
-static PyObject *
-py_GnumericFunc_call (py_GnumericFunc_object *self, PyObject *args, PyObject *keywords)
-{
- return python_call_gnumeric_function (self->fn_def, self->eval_pos, args);
-}
-
-static void
-py_GnumericFunc_object_dealloc (py_GnumericFunc_object *self)
-{
- g_return_if_fail (self != NULL);
-
- gnm_func_dec_usage (self->fn_def);
- g_free (self->eval_pos);
- PyObject_Del (self);
-}
-
-static PyObject *
-py_new_GnumericFunc_object (GnmFunc *fn_def, const GnmEvalPos *opt_eval_pos)
-{
- py_GnumericFunc_object *self;
-
- self = PyObject_NEW (py_GnumericFunc_object, &py_GnumericFunc_object_type);
- if (self == NULL) {
- return NULL;
- }
-
- gnm_func_inc_usage (fn_def);
- self->fn_def = fn_def;
- if (opt_eval_pos != NULL) {
- self->eval_pos = g_new (GnmEvalPos, 1);
- *self->eval_pos = *opt_eval_pos;
- } else {
- self->eval_pos = NULL;
- }
-
- return (PyObject *) self;
-}
-
-static PyTypeObject py_GnumericFunc_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "GnumericFunc", /* tp_name */
- sizeof (py_GnumericFunc_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_GnumericFunc_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- (ternaryfunc) py_GnumericFunc_call, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
-};
-
-/*
- * GnumericFuncDict
- */
-
-struct _py_GnumericFuncDict_object {
- PyObject_HEAD
- PyObject *module_dict;
-};
-
-
-static PyObject *
-py_GnumericFuncDict_subscript (py_GnumericFuncDict_object *self, PyObject *key)
-{
- gchar *fn_name;
- GnmFunc *fn_def;
-
- if (!PyArg_Parse(key, (char *) "s", &fn_name)) {
- return NULL;
- }
-
- fn_def = gnm_func_lookup (fn_name, NULL);
- if (fn_def == NULL) {
- /* Py_INCREF (key); FIXME?? */
- PyErr_SetObject (PyExc_KeyError, key);
- return NULL;
- }
-
- return py_new_GnumericFunc_object (fn_def, NULL);
-}
-
-static void
-py_GnumericFuncDict_object_dealloc (py_GnumericFuncDict_object *self)
-{
- PyObject_Del (self);
-}
-
-static PyObject *
-py_new_GnumericFuncDict_object (PyObject *module_dict)
-{
- py_GnumericFuncDict_object *self;
-
- self = PyObject_NEW (py_GnumericFuncDict_object, &py_GnumericFuncDict_object_type);
- if (self == NULL) {
- return NULL;
- }
-
- self->module_dict = module_dict;
-
- return (PyObject *) self;
-}
-
-PyMappingMethods py_GnumericFuncDict_mapping_methods = {
- 0, /* mp_length */
- (binaryfunc) py_GnumericFuncDict_subscript, /* mp_subscript */
- 0 /* mp_ass_subscript */
-};
+PyMappingMethods py_GnumericFuncDict_mapping_methods = {
+ 0, /* mp_length */
+ (binaryfunc) py_GnumericFuncDict_subscript, /* mp_subscript */
+ 0 /* mp_ass_subscript */
+};
static PyTypeObject py_GnumericFuncDict_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "GnumericFuncDict", /* tp_name */
- sizeof (py_GnumericFuncDict_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_GnumericFuncDict_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- 0, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- &py_GnumericFuncDict_mapping_methods, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = (char *) "GnumericFuncDict",
+ .tp_basicsize = sizeof (py_GnumericFuncDict_object),
+ .tp_dealloc = (destructor) &py_GnumericFuncDict_object_dealloc,
+ .tp_as_mapping = &py_GnumericFuncDict_mapping_methods
};
/*
- * GOPlugin
+- * GOPlugin
*/
struct _py_GnmPlugin_object {
@@ -2118,7 +747,7 @@ py_GnmPlugin_get_dir_name_method (py_GnmPlugin_object *self, PyObject *args)
return NULL;
}
- return PyString_FromString (go_plugin_get_dir_name (self->pinfo));
+ return PyUnicode_FromString (go_plugin_get_dir_name (self->pinfo));
}
static PyObject *
@@ -2128,7 +757,7 @@ py_GnmPlugin_get_id_method (py_GnmPlugin_object *self, PyObject *args)
return NULL;
}
- return PyString_FromString (go_plugin_get_id (self->pinfo));
+ return PyUnicode_FromString (go_plugin_get_id (self->pinfo));
}
static PyObject *
@@ -2138,7 +767,7 @@ py_GnmPlugin_get_name_method (py_GnmPlugin_object *self, PyObject *args)
return NULL;
}
- return PyString_FromString (go_plugin_get_name (self->pinfo));
+ return PyUnicode_FromString (go_plugin_get_name (self->pinfo));
}
static PyObject *
@@ -2148,7 +777,7 @@ py_GnmPlugin_get_description_method (py_GnmPlugin_object *self, PyObject *args)
return NULL;
}
- return PyString_FromString (go_plugin_get_description (self->pinfo));
+ return PyUnicode_FromString (go_plugin_get_description (self->pinfo));
}
#if 0
@@ -2162,7 +791,7 @@ py_GnmPlugin_as_GnmPlugin (py_GnmPlugin_object *self)
static PyObject *
py_GnmPlugin_object_getattr (py_GnmPlugin_object *self, gchar *name)
{
- return Py_FindMethod (py_GnmPlugin_object_methods, (PyObject *) self, name);
+ return PyUnicode_FromString (go_plugin_get_description (self->pinfo));
}
static void
@@ -2190,140 +819,12 @@ py_new_GnmPlugin_object (GOPlugin *pinfo)
}
static PyTypeObject py_GnmPlugin_object_type = {
- PyObject_HEAD_INIT(0)
- 0, /* ob_size */
- (char *) "GOPlugin", /* tp_name */
- sizeof (py_GnmPlugin_object), /* tp_size */
- 0, /* tp_itemsize */
- (destructor) &py_GnmPlugin_object_dealloc, /* tp_dealloc */
- 0, /* tp_print */
- (getattrfunc) &py_GnmPlugin_object_getattr, /* tp_getattr */
- 0, /* tp_setattr */
- 0, /* tp_compare */
- 0, /* tp_repr */
- 0, /* tp_as_number */
- 0, /* tp_as_sequence */
- 0, /* tp_as_mapping */
- 0, /* tp_hash */
- 0, /* tp_call */
- 0, /* tp_str */
- 0, /* tp_getattro */
- 0, /* tp_setattro */
- 0, /* tp_as_buffer */
- 0, /* tp_flags */
- 0 /* tp_doc */
-};
-
-
-/*
- * Gnumeric module
- */
-
-static PyObject *
-py_gnumeric_Boolean_method (PyObject *self, PyObject *args)
-{
- PyObject *src_obj;
-
- if (!PyArg_ParseTuple (args, (char *) "O:Boolean", &src_obj)) {
- return NULL;
- }
-
- return py_new_Boolean_object (PyObject_IsTrue (src_obj));
-}
-
-static PyObject *
-py_gnumeric_CellPos_method (PyObject *self, PyObject *args)
-{
- gint col, row;
-
- if (!PyArg_ParseTuple (args, (char *) "ii:CellPos", &col, &row)) {
- return NULL;
- }
-
- return py_new_CellPos_object_from_col_row (col, row);
-}
-
-static PyObject *
-py_gnumeric_Range_method (PyObject *self, PyObject *args)
-{
- PyObject *result = NULL;
- gint start_col, start_row, end_col, end_row;
- py_CellPos_object *py_start, *py_end;
-
- if (PyArg_ParseTuple (args, (char *) "iiii:Range",
- &start_col, &start_row, &end_col, &end_row)) {
- GnmCellPos start, end;
- start.col = start_col; start.row = start_row;
- end.col = end_col; end.row = end_row;
- result = py_new_Range_object_from_start_end (&start, &end);
- } else {
- PyErr_Clear ();
- if (PyArg_ParseTuple (args, (char *) "O!O!:Range",
- &py_CellPos_object_type, &py_start,
- &py_CellPos_object_type, &py_end)) {
- result = py_new_Range_object_from_start_end (&py_start->cell_pos,
- &py_end->cell_pos);
- } else {
- return NULL;
- }
- }
-
- return result;
-}
-
-static PyObject *
-py_gnumeric_Style_method (PyObject *self, PyObject *args)
-{
- if (!PyArg_ParseTuple (args, (char *) ":GnmStyle")) {
- return NULL;
- }
- return py_new_Style_object (gnm_style_new_default ());
-}
-
-static PyObject *
-py_gnumeric_workbooks_method (PyObject *self, PyObject *args)
-{
- GList *workbooks, *l;
- int len, i;
- PyObject *result;
-
- if (!PyArg_ParseTuple (args, (char *) ":workbooks"))
- return NULL;
-
- workbooks = gnm_app_workbook_list ();
- len = g_list_length (workbooks);
- result = PyTuple_New (len);
- for (l = workbooks, i = 0; i < len; l = l->next, i++) {
- PyTuple_SetItem (result, i, py_new_Workbook_object (l->data));
- }
-
- return result;
-}
-
-static PyObject *
-py_gnumeric_workbook_new (PyObject *self, PyObject *args)
-{
- Workbook *workbook = NULL;
- PyObject *result;
-
- if (!PyArg_ParseTuple (args, (char *) "|O:workbook_new"))
- return NULL;
-
- workbook = workbook_new ();
- result = py_new_Workbook_object (workbook);
- g_object_unref (workbook); /* py_new_Workbook_object
- added a reference */
- return result;
-}
-
-static PyMethodDef GnumericMethods[] = {
- { (char *) "Boolean", py_gnumeric_Boolean_method, METH_VARARGS },
- { (char *) "CellPos", py_gnumeric_CellPos_method, METH_VARARGS },
- { (char *) "Range", py_gnumeric_Range_method, METH_VARARGS },
- { (char *) "GnmStyle", py_gnumeric_Style_method, METH_VARARGS },
- { (char *) "workbooks", py_gnumeric_workbooks_method, METH_VARARGS },
- { (char *) "workbook_new", py_gnumeric_workbook_new, METH_VARARGS},
- { NULL, NULL },
+ PyVarObject_HEAD_INIT(&PyType_Type, 0)
+ .tp_name = (char *) "GOPlugin",
+ .tp_basicsize = sizeof (py_GnmPlugin_object),
+ .tp_dealloc = (destructor) &py_GnmPlugin_object_dealloc,
+ .tp_getattr = (getattrfunc) &py_GnmPlugin_object_getattr,
+ .tp_methods = py_GnmPlugin_object_methods
};
static void
@@ -2333,34 +834,33 @@ init_err (PyObject *module_dict, const char *name, GnmStdError e)
PyDict_SetItemString
(module_dict, (char *)name,
- PyString_FromString (v->v_err.mesg->str));
+ PyUnicode_FromString (v->v_err.mesg->str));
value_release (v);
}
-void
-py_initgnumeric (GnmPyInterpreter *interpreter)
+PyObject *
+py_initgnumeric ()
{
- PyObject *module, *module_dict, *py_pinfo;
- GOPlugin *pinfo;
+ PyObject *module_dict;
- py_Boolean_object_type.ob_type =
- py_CellPos_object_type.ob_type =
- py_Range_object_type.ob_type =
- py_CellRef_object_type.ob_type =
- py_RangeRef_object_type.ob_type =
- py_Style_object_type.ob_type =
- py_Cell_object_type.ob_type =
- py_Sheet_object_type.ob_type =
- py_Workbook_object_type.ob_type =
- py_Gui_object_type.ob_type =
- py_GnumericFunc_object_type.ob_type =
- py_GnumericFuncDict_object_type.ob_type =
- py_GnmPlugin_object_type.ob_type = &PyType_Type;
-
- module = Py_InitModule ((char *) "Gnumeric", GnumericMethods);
- module_dict = PyModule_GetDict (module);
+ static struct PyModuleDef GnmModuleDef = {
+ PyModuleDef_HEAD_INIT, /* m_base */
+ (char *) "Gnumeric", /* m_name */
+ 0, /* m_doc */
+ 0, /* m_ size */
+ 0, /* m_methods */
+ 0, /* m_reload */
+ 0, /* m_traverse */
+ 0, /* m_clear */
+ 0, /* m_free */
+ };
+
+ if (GnmModule)
+ return GnmModule;
+ GnmModule = PyModule_Create (&GnmModuleDef);
+ module_dict = PyModule_GetDict (GnmModule);
(void) PyDict_SetItemString
(module_dict, (char *) "TRUE", py_new_Boolean_object (TRUE));
@@ -2384,13 +884,28 @@ py_initgnumeric (GnmPyInterpreter *interpreter)
(module_dict, (char *) "functions",
py_new_GnumericFuncDict_object (module_dict));
- pinfo = gnm_py_interpreter_get_plugin (interpreter);
- if (pinfo) {
- py_pinfo = py_new_GnmPlugin_object (pinfo);
- } else {
- py_pinfo = Py_None;
- Py_INCREF (Py_None);
- }
- (void) PyDict_SetItemString (module_dict,
- (char *) "plugin_info", py_pinfo);
+ return GnmModule;
+}
+
+void
+py_gnumeric_add_plugin (PyObject *module, GnmPyInterpreter *interpreter)
+{
+ PyObject *module_dict, *py_pinfo;
+ GOPlugin *pinfo;
+ char *key, *name;
+ int i;
+
+ module_dict = PyModule_GetDict (module);
+ pinfo = gnm_py_interpreter_get_plugin (interpreter);
+ g_return_if_fail (pinfo);
+ name = g_strdup (go_plugin_get_name (pinfo));
+ i = strlen (name);
+ while (i > 0)
+ if (name[--i] == ' ')
+ name[i] = '_';
+ key = g_strconcat ("plugin_", name, "_info", NULL);
+ py_pinfo = py_new_GnmPlugin_object (pinfo);
+ (void) PyDict_SetItemString (module_dict, key, py_pinfo);
+ g_free (name);
+ g_free (key);
}
diff --git a/plugins/python-loader/py-gnumeric.h b/plugins/python-loader/py-gnumeric.h
index a4e1843d4..9ea35919f 100644
--- a/plugins/python-loader/py-gnumeric.h
+++ b/plugins/python-loader/py-gnumeric.h
@@ -7,14 +7,11 @@
#include "gnm-py-interpreter.h"
#include <gnumeric-fwd.h>
-void py_initgnumeric (GnmPyInterpreter *interpreter);
+PyObject *py_initgnumeric (void);
+void py_gnumeric_add_plugin (PyObject *module, GnmPyInterpreter *interpreter);
GnmValue *call_python_function (PyObject *python_fn,
GnmEvalPos const *eval_pos,
gint n_args, GnmValue const * const *args);
gchar *py_exc_to_string (void);
-PyObject *py_new_Sheet_object (Sheet *sheet);
-PyObject *py_new_Workbook_object (Workbook *wb);
-PyObject *py_new_Gui_object (WBCGtk *wbcg);
-
-#endif /* PLUGIN_PY_GNUMERIC_H */
+#endif /* PLUGIN_PY_GNUMERIC_H */
\ No newline at end of file
diff --git a/plugins/python-loader/python-loader.c b/plugins/python-loader/python-loader.c
index 62ba39aaf..f91917c4d 100644
--- a/plugins/python-loader/python-loader.c
+++ b/plugins/python-loader/python-loader.c
@@ -29,6 +29,7 @@
#include <gsf/gsf-impl-utils.h>
#include <glib/gi18n-lib.h>
+
#include <glib/gstdio.h>
#include <stdlib.h>
@@ -287,7 +288,7 @@ gplp_func_file_open (G_GNUC_UNUSED GOFileOpener const *fo,
open_result = PyObject_CallFunction
(loader_data->python_func_file_open,
(char *) "NO",
- py_new_Sheet_object (sheet), input_wrapper);
+ pygobject_new (G_OBJECT (sheet)), input_wrapper);
Py_DECREF (input_wrapper);
}
if (open_result != NULL) {
@@ -388,7 +389,7 @@ gplp_func_file_save (G_GNUC_UNUSED GOFileSaver const *fs, GOPluginService *servi
saver_data = g_object_get_data (G_OBJECT (service), "loader_data");
SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service));
- py_workbook = py_new_Workbook_object (wb_view_get_workbook (wb_view));
+ py_workbook = pygobject_new (G_OBJECT (wb_view_get_workbook (wb_view)));
output_wrapper = pygobject_new (G_OBJECT (output));
if (output_wrapper != NULL) {
/* wrapping adds a reference */
@@ -533,6 +534,11 @@ call_python_function_nodes (GnmFuncEvalInfo *ei,
return ret_value;
}
+static void FuncHelpDestructor (PyObject *object)
+{
+ g_free (PyCapsule_GetPointer (object, "FuncHelp"));
+}
+
static GnmFuncHelp const *
python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *python_fn,
const gchar *fn_name)
@@ -552,11 +558,11 @@ python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *pyth
PyFunction_Check (python_fn)
? ((PyFunctionObject *) python_fn)->func_doc
: NULL;
- if (python_fn_help != NULL && PyString_Check (python_fn_help)) {
+ if (python_fn_help != NULL && PyUnicode_Check (python_fn_help)) {
guint n = 0;
GnmFuncHelp *new_help = NULL;
gboolean arg_names_written = FALSE;
- char const *help_text = PyString_AsString (python_fn_help);
+ char const *help_text = PyUnicode_AsUTF8 (python_fn_help);
if (g_str_has_prefix (help_text, "@GNM_FUNC_HELP_NAME@")) {
/* New-style documentation */
@@ -623,7 +629,7 @@ python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *pyth
if (python_arg_names != NULL && !arg_names_written) {
/* We only try this if we did not get argument */
/* descriptions via the new style documentation */
- char const *arg_names = PyString_AsString (python_arg_names);
+ char const *arg_names = PyUnicode_AsUTF8 (python_arg_names);
if (arg_names != NULL && arg_names[0] != '\0') {
gchar **args = g_strsplit (arg_names, ",", 0);
guint nitems = g_strv_length (args), nstart = n, i;
@@ -644,7 +650,7 @@ python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *pyth
new_help[n-1].type = GNM_FUNC_HELP_END;
new_help[n-1].text = NULL;
- cobject_help_value = PyCObject_FromVoidPtr (new_help, &g_free);
+ cobject_help_value = PyCapsule_New (new_help, "FuncHelp", FuncHelpDestructor);
PyDict_SetItemString (python_fn_info_dict, help_attr_name, cobject_help_value);
}
}
@@ -652,7 +658,7 @@ python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *pyth
if (cobject_help_value == NULL)
return NULL;
- return (GnmFuncHelp const *) PyCObject_AsVoidPtr (cobject_help_value);
+ return (GnmFuncHelp const *) PyCapsule_GetPointer (cobject_help_value, "FuncHelp");
}
static void
@@ -682,12 +688,12 @@ gplp_func_load_stub (GOPluginService *service,
if (PyTuple_Size (fn_info_obj) == 3 &&
(python_args = PyTuple_GetItem (fn_info_obj, 0)) != NULL &&
- PyString_Check (python_args) &&
+ PyUnicode_Check (python_args) &&
(python_fn = PyTuple_GetItem (fn_info_obj, 2)) != NULL &&
PyCallable_Check (python_fn)) {
GnmFuncHelp const *help = python_function_get_gnumeric_help
(loader_data->python_fn_info_dict, python_fn, name);
- gnm_func_set_fixargs (func, call_python_function_args, PyString_AsString
(python_args));
+ gnm_func_set_fixargs (func, call_python_function_args, PyUnicode_AsUTF8
(python_args));
gnm_func_set_help (func, help, -1);
gnm_func_set_impl_status (func, GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC);
g_object_set_data (G_OBJECT (func), SERVICE_KEY, service);
@@ -817,7 +823,7 @@ gplp_func_exec_action (GOPluginService *service,
return;
}
ret = PyObject_CallFunction (fn, (char *) "N",
- py_new_Gui_object (WBC_GTK (wbc)));
+ pygobject_new (G_OBJECT (WBC_GTK (wbc))));
if (ret == NULL) {
*ret_error = go_error_info_new_str (py_exc_to_string ());
PyErr_Clear ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]