Exemplo n.º 1
0
/*
 * pygtkextra_sheet_destroy_cb
 */
void
pygtkextra_sheet_destroy_cb(GtkSheet *sheet, gpointer user_data)
{
    PyGtk_BlockThreads();
    pygtkextra_sheet_unref_links(sheet, NULL);
    PyGtk_UnblockThreads();
}
Exemplo n.º 2
0
static void frame_done_cb_destroy_notify (gpointer func_args_tuple)
{
	/* data == the arg tuple */
	/*FIXME handle threads ? */
	//PyGTK_BLOCK_THREADS
	PyGtk_BlockThreads ();
	dbg();
	Py_DECREF ((PyObject *) func_args_tuple);
	PyGtk_UnblockThreads ();
	//PyGTK_UNBLOCK_THREADS
}
Exemplo n.º 3
0
void
pygtkextra_plot_data_call_plot_iterator(GtkPlot *plot, GtkPlotData *data,
                                        gint iter,
                                        gdouble *out_x,
                                        gdouble *out_y,
                                        gdouble *out_z,
                                        gdouble *out_a,
                                        gdouble *out_dx,
                                        gdouble *out_dy,
                                        gdouble *out_dz,
                                        gdouble *out_da,
                                        gchar **out_label,
                                        gboolean *out_error)
{
    PyObject **vector, *function, *args, *value, *result;

    PyGtk_BlockThreads();

    *out_error = TRUE;

    /* Get the Python function and the argument tuple that belong to
       the given GtkPlotData instance. */
    vector = (PyObject **) gtk_object_get_data(GTK_OBJECT(data),
             plot_function_key);
    if (!vector) {
        PyErr_SetString(PyExc_RuntimeError, "cannot find plot function");
        goto cleanup;
    }
    function = vector[0];
    args = vector[1];

    /* Put the index into the first item of the argument tuple. */
    value = PyInt_FromLong(iter);
    if (!value)
        goto cleanup;
    PyTuple_SetItem(args, 0, value);

    /* Call the Python function. */
    result = PyEval_CallObject(function, args);
    if (!result)
        goto cleanup;

    if (PySequence_Check(result)) {
        int n = PySequence_Length(result);
        if (n < 8 || n > 9) {
            PyErr_SetString(PyExc_TypeError,
                            "plot iterator must return 9-sequence or None");
        } else {
            int i;
            gdouble *v[8];
            PyObject *item;

            v[0] = out_x;
            v[1] = out_y;
            v[2] = out_z;
            v[3] = out_a;
            v[4] = out_dx;
            v[5] = out_dy;
            v[6] = out_dz;
            v[7] = out_da;
            *out_error = FALSE;
            for (i = 0; i < 8; ++i) {
                item = PySequence_GetItem(result, i);
                if (item == Py_None) {
                    *v[i] = 0.0;
                } else if (PyFloat_Check(item)) {
                    *v[i] = PyFloat_AS_DOUBLE(item);
                } else if (PyNumber_Check(item)
                           && (value = PyNumber_Float(item))) {
                    *v[i] = PyFloat_AS_DOUBLE(value);
                    Py_DECREF(value);
                } else {
                    gchar buf[256];

                    *out_error = TRUE;
                    g_snprintf(buf, sizeof(buf),
                               "%d%s item must be number or None",
                               i + 1, get_ordinal_suffix(i + 1));
                    PyErr_SetString(PyExc_TypeError, buf);
                    Py_XDECREF(item);
                    Py_DECREF(result);
                    goto cleanup;
                }
                Py_XDECREF(item);
            }
            *out_label = NULL;
            if (n >= 9) {
                item = PySequence_GetItem(result, 8);
                if (PyString_Check(item)) {
                    *out_label = PyString_AS_STRING(item);
                } else if (item != Py_None) {
                    *out_error = TRUE;
                    PyErr_SetString(PyExc_TypeError,
                                    "last item must be string or None");
                }
                Py_XDECREF(item);
            }
        }
    } else if (result != Py_None) {
        PyErr_SetString(PyExc_TypeError,
                        "plot iterator must return sequence or None");
    }

    Py_DECREF(result);

cleanup:

    if (PyErr_Occurred()) {
        PyErr_Print();
        PyErr_Clear();
    }

    PyGtk_UnblockThreads();
}
Exemplo n.º 4
0
gdouble
pygtkextra_plot_data_call_plot3d_function(GtkPlot *plot, GtkPlotData *data,
        gdouble x, gdouble y,
        gboolean *out_error)
{
    gdouble z;
    PyObject **vector, *function, *args, *value, *result;

    z = 0.0;

    PyGtk_BlockThreads();

    *out_error = TRUE;

    /* Get the Python function and the argument tuple that belong to
       the given GtkPlotData instance. */
    vector = (PyObject **) gtk_object_get_data(GTK_OBJECT(data),
             plot_function_key);
    if (!vector) {
        PyErr_SetString(PyExc_RuntimeError, "cannot find plot function");
        goto cleanup;
    }
    function = vector[0];
    args = vector[1];

    /* Put the X and Y value into the first two items of the argument tuple. */
    value = PyFloat_FromDouble(x);
    if (!value)
        goto cleanup;
    PyTuple_SetItem(args, 0, value);
    value = PyFloat_FromDouble(y);
    if (!value)
        goto cleanup;
    PyTuple_SetItem(args, 1, value);

    /* Call the Python function. */
    result = PyEval_CallObject(function, args);
    if (!result)
        goto cleanup;

    /* Get the Z value. */
    if (PyFloat_Check(result)) {
        z = PyFloat_AS_DOUBLE(result);
        *out_error = FALSE;
    } else if (PyNumber_Check(result) && (value = PyNumber_Float(result))) {
        z = PyFloat_AS_DOUBLE(value);
        Py_DECREF(value);
        *out_error = FALSE;
    } else if (result != Py_None) {
        PyErr_SetString(PyExc_TypeError,
                        "plot function must return number or None");
    }

    Py_DECREF(result);

cleanup:

    if (PyErr_Occurred()) {
        PyErr_Print();
        PyErr_Clear();
    }

    PyGtk_UnblockThreads();

    return z;
}
Exemplo n.º 5
0
/* Can't simply connect "frame_done" signal like the others.  The handler
   is of type:  gint func (GdkPixbufLoader *loader,
			   GdkPixbufFrame  *frame,
			   gpointer         data)
   If you simply connect it from python it will pass in 'frame' as a
   CObject, and since it wasn't created with a 'destroy' handler you can't
   manipulate 'frame' within python code (program will silently exit).
   We need to get a hold of 'frame' first, convert it to a GtkObject and
   then pass it on to the user function in python.
*/
static void marshal_frame_done_cb (GtkObject *loader_ptr, 
				   gpointer func_args_tuple_ptr, 
				   guint nargs, GtkArg *args)
{
	/*FIXME I'm probably f*****g this up */
	PyObject *loader_python, *func_args_tuple_orig, *frame_python, *func;
	PyObject *func_args_tuple;
	PyObject *new_args, *result;
	GdkPixbufFrame *frame;
	int check;
		
	PyGtk_BlockThreads ();
	dbg ();

	frame = (GdkPixbufFrame *) GTK_VALUE_POINTER(args[0]);
	func_args_tuple = (PyObject *) func_args_tuple_ptr;
	Py_XINCREF (func_args_tuple);

	
	//loader_python = PyGdkPixbuf_LoaderNew ((GdkPixbufLoader *) loader_ptr);
	loader_python = PyGtk_New (loader_ptr);
	if (loader_python == NULL)
	{	dprint ("couldn't make loader_python\n");
		goto error;
	}

	frame_python = PyGdkPixbuf_FrameNew (frame);
	if (frame_python == NULL)
	{	dprint ("couldn't make frame_python\n");
		goto error;
	}

	func = PyTuple_GetItem (func_args_tuple, 0);
	if (func == NULL)
	{	dprint ("couldn't get func from tuple\n");
		goto error;
	}

	check = PyTuple_SetItem (func_args_tuple, 1, loader_python);
	if (check != 0)
	{	dprint ("func_args_tuple[1] = loader_python failed\n");
		goto error;
	}

	check = PyTuple_SetItem (func_args_tuple, 2, frame_python);
	if (check != 0)
	{	dprint ("func_args_tuple[2] = frame_python failed\n");
		goto error;
	}

	/*FIXME are the tuple items "stolen" references??? */
	new_args = PyTuple_GetSlice (func_args_tuple, 1, 
			 	PyTuple_Size(func_args_tuple));
	if (new_args == NULL)
	{	dprint ("new_args = func_args_tuple[1:] failed\n");
		goto error;
	}

	result = PyObject_CallObject (func, new_args);
	if (result == NULL)
	{	Py_XDECREF (new_args);
		dprint ("func(new_args) returned NULL\n");
		goto error;
	}

	GtkRet_FromPyObject (&args[nargs], result);
	Py_DECREF (result);
	PyGtk_UnblockThreads ();
	return;
	
error:
	Py_XDECREF (func_args_tuple);
	if (PyGtk_FatalExceptions)
		gtk_main_quit ();
	else
	  {	PyErr_Print ();
		PyErr_Clear ();
	  }
	PyGtk_UnblockThreads ();
	return;
}