Back to index

gcompris  8.2.2
Defines | Functions | Variables
canvasmodule.c File Reference
#include <pygobject.h>
#include <pygtk/pygtk.h>
#include <libgnomecanvas/libgnomecanvas.h>

Go to the source code of this file.

Defines

#define add_item(short)   PyModule_AddIntConstant (m, #short, ART_##short)

Functions

static PyObject * gnomecanvaspoints_from_value (const GValue *value)
static int gnomecanvaspoints_to_value (GValue *value, PyObject *object)
void pycanvas_register_classes (PyObject *d)
 initgnomecanvas (void)

Variables

PyMethodDef pycanvas_functions []

Define Documentation

#define add_item (   short)    PyModule_AddIntConstant (m, #short, ART_##short)

Function Documentation

static PyObject* gnomecanvaspoints_from_value ( const GValue *  value) [static]

Definition at line 13 of file canvasmodule.c.

{
    GnomeCanvasPoints *points = (GnomeCanvasPoints *)g_value_get_boxed(value);
    PyObject *list;
    gint i;

    list = PyList_New(0);
    if (points)
       for (i = 0; i < points->num_points * 2; i++) {
           PyObject *item = PyFloat_FromDouble(points->coords[i]);

           PyList_Append(list, item);
           Py_DECREF(item);
       }
    return list;
}

Here is the caller graph for this function:

static int gnomecanvaspoints_to_value ( GValue *  value,
PyObject *  object 
) [static]

Definition at line 31 of file canvasmodule.c.

{
    GnomeCanvasPoints *points;
    gint i, len;

    if (!PySequence_Check(object))
       return -1;
    len = PySequence_Length(object);
    if (len % 2 != 0)
       return -1;

    points = gnome_canvas_points_new(len / 2);
    for (i = 0; i < len; i++) {
       PyObject *item = PySequence_GetItem(object, i);

       points->coords[i] = PyFloat_AsDouble(item);
       if (PyErr_Occurred()) {
           gnome_canvas_points_unref(points);
           PyErr_Clear();
           Py_DECREF(item);
           return -1;
       }
       Py_DECREF(item);
    }
    g_value_set_boxed(value, points);
    gnome_canvas_points_unref(points);
    return 0;
}

Here is the caller graph for this function:

initgnomecanvas ( void  )

Definition at line 67 of file canvasmodule.c.

{
    PyObject *m, *d;
       
    init_pygobject ();
    init_pygtk ();

    pyg_register_boxed_custom(GNOME_TYPE_CANVAS_POINTS,
                           gnomecanvaspoints_from_value,
                           gnomecanvaspoints_to_value);

    m = Py_InitModule ("gnomecanvas", pycanvas_functions);
    d = PyModule_GetDict (m);

      /* ArtPathcode */
#define add_item(short)\
    PyModule_AddIntConstant (m, #short, ART_##short)
    add_item(MOVETO);
    add_item(MOVETO_OPEN);
    add_item(CURVETO);
    add_item(LINETO);
#undef add_item
       
    pycanvas_register_classes (d);
    /* pycanvas_add_constants (d, "GNOME_CANVAS_"); */
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pycanvas_register_classes ( PyObject *  d)

Definition at line 1796 of file canvas.c.

{
    PyObject *module;

    if ((module = PyImport_ImportModule("gobject")) != NULL) {
        PyObject *moddict = PyModule_GetDict(module);

        _PyGObject_Type = (PyTypeObject *)PyDict_GetItemString(moddict, "GObject");
        if (_PyGObject_Type == NULL) {
            PyErr_SetString(PyExc_ImportError,
                "cannot import name GObject from gobject");
            return;
        }
    } else {
        PyErr_SetString(PyExc_ImportError,
            "could not import gobject");
        return;
    }
    if ((module = PyImport_ImportModule("gtk._gtk")) != NULL) {
        PyObject *moddict = PyModule_GetDict(module);

        _PyGtkLayout_Type = (PyTypeObject *)PyDict_GetItemString(moddict, "Layout");
        if (_PyGtkLayout_Type == NULL) {
            PyErr_SetString(PyExc_ImportError,
                "cannot import name Layout from gtk._gtk");
            return;
        }
        _PyGtkObject_Type = (PyTypeObject *)PyDict_GetItemString(moddict, "Object");
        if (_PyGtkObject_Type == NULL) {
            PyErr_SetString(PyExc_ImportError,
                "cannot import name Object from gtk._gtk");
            return;
        }
    } else {
        PyErr_SetString(PyExc_ImportError,
            "could not import gtk._gtk");
        return;
    }


#line 1837 "canvas.c"
    pyg_register_boxed(d, "CanvasPathDef", GNOME_TYPE_CANVAS_PATH_DEF, &PyGnomeCanvasPathDef_Type);
    pygobject_register_class(d, "GnomeCanvas", GNOME_TYPE_CANVAS, &PyGnomeCanvas_Type, Py_BuildValue("(O)", &PyGtkLayout_Type));
    pygobject_register_class(d, "GnomeCanvasItem", GNOME_TYPE_CANVAS_ITEM, &PyGnomeCanvasItem_Type, Py_BuildValue("(O)", &PyGtkObject_Type));
    pygobject_register_class(d, "GnomeCanvasGroup", GNOME_TYPE_CANVAS_GROUP, &PyGnomeCanvasGroup_Type, Py_BuildValue("(O)", &PyGnomeCanvasItem_Type));
    pygobject_register_class(d, "GnomeCanvasClipgroup", GNOME_TYPE_CANVAS_CLIPGROUP, &PyGnomeCanvasClipgroup_Type, Py_BuildValue("(O)", &PyGnomeCanvasGroup_Type));
    pygobject_register_class(d, "GnomeCanvasLine", GNOME_TYPE_CANVAS_LINE, &PyGnomeCanvasLine_Type, Py_BuildValue("(O)", &PyGnomeCanvasItem_Type));
    pygobject_register_class(d, "GnomeCanvasPixbuf", GNOME_TYPE_CANVAS_PIXBUF, &PyGnomeCanvasPixbuf_Type, Py_BuildValue("(O)", &PyGnomeCanvasItem_Type));
    pygobject_register_class(d, "GnomeCanvasRichText", GNOME_TYPE_CANVAS_RICH_TEXT, &PyGnomeCanvasRichText_Type, Py_BuildValue("(O)", &PyGnomeCanvasItem_Type));
    pygobject_register_class(d, "GnomeCanvasShape", GNOME_TYPE_CANVAS_SHAPE, &PyGnomeCanvasShape_Type, Py_BuildValue("(O)", &PyGnomeCanvasItem_Type));
    pygobject_register_class(d, "GnomeCanvasRE", GNOME_TYPE_CANVAS_RE, &PyGnomeCanvasRE_Type, Py_BuildValue("(O)", &PyGnomeCanvasShape_Type));
    pygobject_register_class(d, "GnomeCanvasRect", GNOME_TYPE_CANVAS_RECT, &PyGnomeCanvasRect_Type, Py_BuildValue("(O)", &PyGnomeCanvasRE_Type));
    pygobject_register_class(d, "GnomeCanvasEllipse", GNOME_TYPE_CANVAS_ELLIPSE, &PyGnomeCanvasEllipse_Type, Py_BuildValue("(O)", &PyGnomeCanvasRE_Type));
    pygobject_register_class(d, "GnomeCanvasPolygon", GNOME_TYPE_CANVAS_POLYGON, &PyGnomeCanvasPolygon_Type, Py_BuildValue("(O)", &PyGnomeCanvasShape_Type));
    pygobject_register_class(d, "GnomeCanvasBpath", GNOME_TYPE_CANVAS_BPATH, &PyGnomeCanvasBpath_Type, Py_BuildValue("(O)", &PyGnomeCanvasShape_Type));
    pygobject_register_class(d, "GnomeCanvasText", GNOME_TYPE_CANVAS_TEXT, &PyGnomeCanvasText_Type, Py_BuildValue("(O)", &PyGnomeCanvasItem_Type));
    pygobject_register_class(d, "GnomeCanvasWidget", GNOME_TYPE_CANVAS_WIDGET, &PyGnomeCanvasWidget_Type, Py_BuildValue("(O)", &PyGnomeCanvasItem_Type));
}

Here is the caller graph for this function:


Variable Documentation

PyMethodDef pycanvas_functions[]

Definition at line 1789 of file canvas.c.