Exemplo n.º 1
0
static gboolean
gplp_func_desc_load (GOPluginService *service,
		     char const *name,
		     GnmFuncDescriptor *res)
{
	ServiceLoaderDataFunctionGroup *loader_data;
	PyObject *fn_info_obj;

	g_return_val_if_fail (GNM_IS_PLUGIN_SERVICE_FUNCTION_GROUP (service), FALSE);
	g_return_val_if_fail (name != NULL, FALSE);

	loader_data = g_object_get_data (G_OBJECT (service), "loader_data");
	SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service));
	fn_info_obj = PyDict_GetItemString (loader_data->python_fn_info_dict,
					    (gchar *) name);
	if (fn_info_obj == NULL) {
		gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object);
		return FALSE;
	}

	if (PyTuple_Check (fn_info_obj)) {
		PyObject *python_args;
		PyObject *python_fn;

		if (PyTuple_Size (fn_info_obj) == 3 &&
		    (python_args = PyTuple_GetItem (fn_info_obj, 0)) != NULL &&
			PyString_Check (python_args) &&
		    (python_fn = PyTuple_GetItem (fn_info_obj, 2)) != NULL &&
		    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);
			res->fn_args	= &call_python_function_args;
			res->fn_nodes	= NULL;
			res->linker	= NULL;
			res->impl_status = GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC;
			res->test_status = GNM_FUNC_TEST_STATUS_UNKNOWN;
			return TRUE;
		}

		gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object);
		return FALSE;
	}

	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);
		res->fn_args	= NULL;
		res->fn_nodes	= &call_python_function_nodes;
		res->linker	= NULL;
		res->impl_status = GNM_FUNC_IMPL_STATUS_UNIQUE_TO_GNUMERIC;
		res->test_status = GNM_FUNC_TEST_STATUS_UNKNOWN;
		return TRUE;
	}

	gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object);
	return FALSE;
}
Exemplo n.º 2
0
static void
gplp_func_file_save (G_GNUC_UNUSED GOFileSaver const *fs, GOPluginService *service,
		     GOIOContext *io_context, gconstpointer wb_view,
		     GsfOutput *output)
{
	ServiceLoaderDataFileSaver *saver_data;
	PyObject *py_workbook;
	PyObject *save_result = NULL;
	PyObject *output_wrapper;

	g_return_if_fail (GO_IS_PLUGIN_SERVICE_FILE_SAVER (service));
	g_return_if_fail (output != NULL);
	g_return_if_fail (_PyGObject_API != NULL);

	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));
	output_wrapper = pygobject_new (G_OBJECT (output));
	if (output_wrapper != NULL) {
		/* wrapping adds a reference */
		g_object_unref (output);
		save_result = PyObject_CallFunction
			(saver_data->python_func_file_save,
			 (char *) "NO", py_workbook, output_wrapper);
		Py_DECREF (output_wrapper);
	}
	if (save_result != NULL) {
		Py_DECREF (save_result);
	} else {
		go_io_error_string (io_context, py_exc_to_string ());
		gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object);
	}
}
Exemplo n.º 3
0
static void
gplp_func_file_open (GOFileOpener const *fo,
		     GOPluginService *service,
		     GOIOContext *io_context,
		     gpointer wb_view,
		     GsfInput *input)
{
	ServiceLoaderDataFileOpener *loader_data;
	Sheet *sheet, *old_sheet;
	PyObject *open_result = NULL;
	PyObject *input_wrapper;

	printf("gplp_func_file_open(start)\n");

	g_return_if_fail (GO_IS_PLUGIN_SERVICE_FILE_OPENER (service));
	g_return_if_fail (input != NULL);
	g_return_if_fail (_PyGObject_API != NULL);

	old_sheet = wb_view_cur_sheet (wb_view);

	loader_data = g_object_get_data (G_OBJECT (service), "loader_data");
	SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service));
	sheet = sheet_new (wb_view_get_workbook (wb_view), _("Some name"),
			   gnm_sheet_get_max_cols (old_sheet),
			   gnm_sheet_get_max_rows (old_sheet));
	input_wrapper = pygobject_new (G_OBJECT (input));
	if (input_wrapper != NULL) {
		 /* wrapping adds a reference */
		g_object_unref (G_OBJECT (input));
		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_get_workbook (wb_view), sheet);
	} else {
		go_io_error_string (io_context, py_exc_to_string ());
		gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object);
		g_object_unref (sheet);
	}

	printf("gplp_func_file_open(end)\n");
}
Exemplo n.º 4
0
static gboolean
gplp_func_file_probe (GOFileOpener const *fo, GOPluginService *service,
		      GsfInput *input, GOFileProbeLevel pl)
{
	ServiceLoaderDataFileOpener *loader_data;
	PyObject *probe_result = NULL;
	PyObject *input_wrapper;
	gboolean result;

	printf("gplp_func_file_probe(start)\n");

	g_return_val_if_fail (GO_IS_PLUGIN_SERVICE_FILE_OPENER (service), FALSE);
	g_return_val_if_fail (input != NULL, FALSE);
	g_return_val_if_fail (_PyGObject_API != NULL, FALSE);

	loader_data = g_object_get_data (G_OBJECT (service), "loader_data");
	SWITCH_TO_PLUGIN (go_plugin_service_get_plugin (service));
	input_wrapper = pygobject_new (G_OBJECT (input));
	if (input_wrapper == NULL) {
		g_warning ("%s", py_exc_to_string ());
		gnm_python_clear_error_if_needed (SERVICE_GET_LOADER (service)->py_object);
	}
	if (input_wrapper != NULL &&
	    loader_data->python_func_file_probe != NULL) {
		/* wrapping adds a reference */
		g_object_unref (G_OBJECT (input));
		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);
	} else {
		PyErr_Clear ();
		result = FALSE;
	}

	printf("gplp_func_file_probe(end)\n");

	return result;
}