Back to index

gcompris  8.2.2
Defines | Functions | Variables
py-mod-anim.c File Reference
#include <Python.h>
#include <pygobject.h>
#include "gcompris/gcompris.h"
#include "py-gcompris-board.h"
#include "py-mod-anim.h"

Go to the source code of this file.

Defines

#define THROW_INACTIVE_ANIMATION
#define PyMODINIT_FUNC   void

Functions

static int Animation_init (py_GcomprisAnimation *self, PyObject *, PyObject *)
static void Animation_free (py_GcomprisAnimation *self)
static int AnimCanvas_init (py_GcomprisAnimCanvas *, PyObject *, PyObject *)
static void AnimCanvas_free (py_GcomprisAnimCanvas *)
static PyObject * AnimCanvas_getattr (py_GcomprisAnimCanvas *, char *)
static PyObject * py_gcompris_animcanvas_setstate (PyObject *, PyObject *)
static PyObject * py_gcompris_animcanvas_swapanim (PyObject *, PyObject *)
static PyObject * py_gcompris_animcanvas_destroy (PyObject *, PyObject *)
PyMODINIT_FUNC python_gcompris_anim_module_init (void)

Variables

static PyMethodDef AnimCanvasMethods []
static PyMethodDef AnimationMethods []
static PyTypeObject py_GcomprisAnimationType
static PyTypeObject py_GcomprisAnimCanvasType
static PyMethodDef PythonGcomprisAnimModule []

Define Documentation

#define PyMODINIT_FUNC   void

Definition at line 291 of file py-mod-anim.c.

Value:
{                                                                       \
    PyErr_SetString(PyExc_RuntimeError, "Tried to access an inactive "  \
                                        "AnimCanvas");                  \
    return NULL;                                                        \
}

Definition at line 7 of file py-mod-anim.c.


Function Documentation

static void Animation_free ( py_GcomprisAnimation self) [static]

Definition at line 169 of file py-mod-anim.c.

{
  g_warning("*** Garbage collecting Animation ***\n");
  if( self->a)
      gc_anim_free(self->a);
  PyObject_DEL(self);
}

Here is the call graph for this function:

static int Animation_init ( py_GcomprisAnimation self,
PyObject *  args,
PyObject *  key 
) [static]

Definition at line 140 of file py-mod-anim.c.

{
  static char *kwlist[] =
  {
    "filename", NULL
  };

  char *file=NULL;

  if(!PyArg_ParseTupleAndKeywords(args, key, "|s", kwlist,
                                   &file))
    {
      PyErr_SetString(PyExc_RuntimeError, "Invalid arguments to Animation()");
      return -1;
    }

  if(file)
    {
      self->a = gc_anim_load(file);
    }

  if(!self->a)
    {
      PyErr_SetString(PyExc_RuntimeError, "Failed to load Animation");
      return -1;
    }
  return 0;
}

Here is the call graph for this function:

static void AnimCanvas_free ( py_GcomprisAnimCanvas self) [static]

Definition at line 211 of file py-mod-anim.c.

{
  g_warning("*** garbage collecting AnimCanvas ***\n");
  if(self->item)
    {
      g_warning("You should really call destroy() on an AnimCanvas "
                "instead of relying on the refcounter\n");
      gc_anim_deactivate(self->item);
      self->item = NULL;
      Py_DECREF(self->anim);
    }
  PyObject_DEL(self);
}

Here is the call graph for this function:

static PyObject * AnimCanvas_getattr ( py_GcomprisAnimCanvas self,
char *  name 
) [static]

Definition at line 225 of file py-mod-anim.c.

{
  if(!strcmp(name, "gnomecanvas"))
    return (PyObject*) pygobject_new( (GObject*) self->item->canvas );
  else if(!strcmp(name, "num_states"))
    return Py_BuildValue("i", self->item->anim->numstates);

  return Py_FindMethod(AnimCanvasMethods, (PyObject *)self, name);
}
static int AnimCanvas_init ( py_GcomprisAnimCanvas self,
PyObject *  args,
PyObject *  key 
) [static]

Definition at line 182 of file py-mod-anim.c.

{
  GcomprisAnimCanvasItem *item;
  GcomprisAnimation *anim;
  GnomeCanvasGroup *parent;
  PyObject *py_p, *py_a;

  if(!PyArg_ParseTuple(args, "OO:AnimCanvas_init", &py_a, &py_p)) {
      PyErr_SetString(PyExc_RuntimeError, "Invalid arguments to AnimCanvas()");
      return -1;
  }
  if(!PyObject_TypeCheck(py_a, &py_GcomprisAnimationType) ||
     !PyObject_TypeCheck(py_p,pygobject_lookup_class(GNOME_TYPE_CANVAS_GROUP))){

      PyErr_SetString(PyExc_TypeError, "AnimCanvas() needs an Animation");
      return -1;
  }

  parent = (GnomeCanvasGroup*) pygobject_get(py_p);
  anim = ( (py_GcomprisAnimation*)py_a )->a;
  item = (GcomprisAnimCanvasItem*) gc_anim_activate(parent, anim);
  self->item = item;
  self->anim = py_a;

  Py_INCREF(self->anim);
  return 0;
}

Here is the call graph for this function:

static PyObject * py_gcompris_animcanvas_destroy ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 275 of file py-mod-anim.c.

{
  py_GcomprisAnimCanvas *s = (py_GcomprisAnimCanvas*)self;

  if(!s->item) THROW_INACTIVE_ANIMATION;

  gc_anim_deactivate(s->item);
  Py_DECREF(s->anim);
  s->item = NULL;
  s->anim = NULL;

  Py_INCREF(Py_None);
  return Py_None;
}

Here is the call graph for this function:

static PyObject * py_gcompris_animcanvas_setstate ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 236 of file py-mod-anim.c.

{
  int state;
  GcomprisAnimCanvasItem *item = ( (py_GcomprisAnimCanvas*)self )->item;

  if(!item) THROW_INACTIVE_ANIMATION;

  if(!PyArg_ParseTuple(args, "i:gcompris_animcanvas_setstate", &state))
    return NULL;

  gc_anim_set_state( item, state );

  Py_INCREF(Py_None);
  return Py_None;
}

Here is the call graph for this function:

static PyObject * py_gcompris_animcanvas_swapanim ( PyObject *  self,
PyObject *  args 
) [static]

Definition at line 253 of file py-mod-anim.c.

{
  py_GcomprisAnimCanvas *s = (py_GcomprisAnimCanvas*)self;
  py_GcomprisAnimation *new_anim;
  py_GcomprisAnimation *old_anim = (py_GcomprisAnimation*)s->anim;
  GcomprisAnimCanvasItem *item = s->item;

  if(!item) THROW_INACTIVE_ANIMATION;

  if(!PyArg_ParseTuple(args, "O:AnimCanvas_swapAnim", (PyObject**)&new_anim))
    return NULL;

  gc_anim_swap(item, new_anim->a);
  Py_INCREF(new_anim);
  s->anim = (PyObject*)new_anim;
  Py_DECREF(old_anim);

  Py_INCREF(Py_None);
  return Py_None;
}

Here is the call graph for this function:

Definition at line 294 of file py-mod-anim.c.

{
  PyObject* m;

  py_GcomprisAnimationType.tp_new = PyType_GenericNew;
  py_GcomprisAnimationType.ob_type = &PyType_Type;
  py_GcomprisAnimCanvasType.tp_new = PyType_GenericNew;
  py_GcomprisAnimCanvasType.ob_type = &PyType_Type;
  if (PyType_Ready(&py_GcomprisAnimationType) < 0)
      return;
  if (PyType_Ready(&py_GcomprisAnimCanvasType) < 0)
      return;

  m = Py_InitModule("_gcompris_anim", PythonGcomprisAnimModule);

  Py_INCREF(&py_GcomprisAnimationType);
  Py_INCREF(&py_GcomprisAnimCanvasType);
  PyModule_AddObject(m, "Animation", (PyObject *)&py_GcomprisAnimationType);
  PyModule_AddObject(m, "CanvasItem", (PyObject *)&py_GcomprisAnimCanvasType);
}

Here is the caller graph for this function:


Variable Documentation

PyMethodDef AnimationMethods[] [static]
Initial value:
 {
  {NULL, NULL, 0, NULL}
}

Definition at line 36 of file py-mod-anim.c.

PyMethodDef AnimCanvasMethods[] [static]
Initial value:
 {
  {"setState", py_gcompris_animcanvas_setstate, METH_VARARGS,
    "gcompris_animcanvas_setstate"},
  {"swapAnimation", py_gcompris_animcanvas_swapanim, METH_VARARGS,
    "gcompris_animcanvas_swapanim"},
  {"destroy", py_gcompris_animcanvas_destroy, METH_VARARGS,
    "gcompris_animcanvas_destroy"},
  {NULL, NULL, 0, NULL}
}

Definition at line 26 of file py-mod-anim.c.

PyTypeObject py_GcomprisAnimationType [static]

Definition at line 40 of file py-mod-anim.c.

PyTypeObject py_GcomprisAnimCanvasType [static]

Definition at line 86 of file py-mod-anim.c.

PyMethodDef PythonGcomprisAnimModule[] [static]
Initial value:
 {
  {NULL, NULL, 0, NULL}
}

Definition at line 132 of file py-mod-anim.c.