[gnumeric] Python: allow all types of callables.



commit feafe1174e26a649c813416913392cff8151390b
Author: Morten Welinder <terra gnome org>
Date:   Mon Apr 21 21:44:36 2014 -0400

    Python: allow all types of callables.
    
    ...such as lambdas and types in addition to actual functions.

 NEWS                                  |    1 +
 plugins/python-loader/ChangeLog       |    8 ++++++++
 plugins/python-loader/py-gnumeric.c   |   14 ++++++++++++++
 plugins/python-loader/python-loader.c |   11 +++++++----
 4 files changed, 30 insertions(+), 4 deletions(-)
---
diff --git a/NEWS b/NEWS
index a4ccd4b..b0fea25 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ Morten:
        * For xlsx, don't complain over "ext" elements.
        * xlsx graph import improvements.
        * Attempt a fix for tabs appearance with gtk+ 3.12.  [#728465]
+       * Make it possible to have all callables as python functions. [#728611]
 
 --------------------------------------------------------------------------
 Gnumeric 1.12.14
diff --git a/plugins/python-loader/ChangeLog b/plugins/python-loader/ChangeLog
index bb472b5..54a4dd5 100644
--- a/plugins/python-loader/ChangeLog
+++ b/plugins/python-loader/ChangeLog
@@ -1,3 +1,11 @@
+2014-04-21  Morten Welinder  <terra gnome org>
+
+       * python-loader.c (gplp_func_desc_load): Accept any callable, not
+       just functions.
+       (gplp_func_exec_action): Ditto.
+       (python_function_get_gnumeric_help): Evidently we only know how to
+       provide help for callables that are functions.
+
 2014-04-13  Morten Welinder <terra gnome org>
 
        * Release 1.12.14
diff --git a/plugins/python-loader/py-gnumeric.c b/plugins/python-loader/py-gnumeric.c
index 23c0d9f..add1e21 100644
--- a/plugins/python-loader/py-gnumeric.c
+++ b/plugins/python-loader/py-gnumeric.c
@@ -545,11 +545,13 @@ static struct PyMethodDef py_CellPos_object_methods[] = {
        {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)
@@ -654,11 +656,13 @@ static struct PyMethodDef py_Range_object_methods[] = {
        {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)
@@ -759,11 +763,13 @@ static struct PyMethodDef py_CellRef_object_methods[] = {
        {NULL, NULL}
 };
 
+#if 0
 static GnmCellRef *
 py_CellRef_as_CellRef (py_CellRef_object *self)
 {
        return &self->cell_ref;
 }
+#endif
 
 static PyObject *
 py_CellRef_object_getattr (py_CellRef_object *self, gchar *name)
@@ -1251,11 +1257,13 @@ static struct PyMethodDef py_Cell_object_methods[] = {
        {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)
@@ -1443,11 +1451,13 @@ static struct PyMethodDef py_Sheet_object_methods[] = {
        {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)
@@ -1671,11 +1681,13 @@ struct _py_Workbook_object {
        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)
@@ -2131,11 +2143,13 @@ py_GnmPlugin_get_description_method (py_GnmPlugin_object *self, PyObject *args)
        return PyString_FromString (go_plugin_get_description (self->pinfo));
 }
 
+#if 0
 static GOPlugin *
 py_GnmPlugin_as_GnmPlugin (py_GnmPlugin_object *self)
 {
        return self->pinfo;
 }
+#endif
 
 static PyObject *
 py_GnmPlugin_object_getattr (py_GnmPlugin_object *self, gchar *name)
diff --git a/plugins/python-loader/python-loader.c b/plugins/python-loader/python-loader.c
index d90bd17..870c5f6 100644
--- a/plugins/python-loader/python-loader.c
+++ b/plugins/python-loader/python-loader.c
@@ -537,7 +537,10 @@ python_function_get_gnumeric_help (PyObject *python_fn_info_dict, PyObject *pyth
        help_attr_name = g_strdup_printf ("_CGnumericHelp_%s", fn_name);
        cobject_help_value = PyDict_GetItemString (python_fn_info_dict, help_attr_name);
        if (cobject_help_value == NULL) {
-               PyObject *python_fn_help = ((PyFunctionObject *) python_fn)->func_doc;
+               PyObject *python_fn_help =
+                       PyFunction_Check (python_fn)
+                       ? ((PyFunctionObject *) python_fn)->func_doc
+                       : NULL;
                if (python_fn_help != NULL && PyString_Check (python_fn_help)) {
                        guint n = 0;
                        GnmFuncHelp *new_help = NULL;
@@ -669,7 +672,7 @@ gplp_func_desc_load (GOPluginService *service,
                    (python_args = PyTuple_GetItem (fn_info_obj, 0)) != NULL &&
                        PyString_Check (python_args) &&
                    (python_fn = PyTuple_GetItem (fn_info_obj, 2)) != NULL &&
-                   PyFunction_Check (python_fn)) {
+                   PyCallable_Check (python_fn)) {
                        res->arg_spec   = PyString_AsString (python_args);
                        res->help       = python_function_get_gnumeric_help (
                                loader_data->python_fn_info_dict, python_fn, name);
@@ -685,7 +688,7 @@ gplp_func_desc_load (GOPluginService *service,
                return FALSE;
        }
 
-       if (PyFunction_Check (fn_info_obj)) {
+       if (PyCallable_Check (fn_info_obj)) {
                res->arg_spec   = "";
                res->help       = python_function_get_gnumeric_help (
                        loader_data->python_fn_info_dict, fn_info_obj, name);
@@ -797,7 +800,7 @@ gplp_func_exec_action (GOPluginService *service,
                *ret_error = go_error_info_new_printf (_("Unknown action: %s"),
                                                    action->id);
                return;
-       } else if (!PyFunction_Check (fn)) {
+       } else if (!PyCallable_Check (fn)) {
                *ret_error = go_error_info_new_printf (
                        _("Not a valid function for action: %s"), action->id);
                return;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]