]> git.sesse.net Git - vlc/commitdiff
python bindings: allow to pass values in the vlc.Position constructor:
authorOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Sun, 20 May 2007 15:08:53 +0000 (15:08 +0000)
committerOlivier Aubert <olivier.aubert@liris.cnrs.fr>
Sun, 20 May 2007 15:08:53 +0000 (15:08 +0000)
 p = vlc.Position(value=16, origin=vlc.RelativePosition)
Defaults to value=0, origin=AbsolutePosition, key=MediaTime

bindings/python/vlc_module.c
bindings/python/vlc_position.c

index ffccabf432024ed450fa46319c5eb85249951c21..9f7fe6256909bb1995080639932912ae78ecd98c 100644 (file)
@@ -47,9 +47,6 @@ initvlc( void )
 {
     PyObject* p_module;
 
-    PyPosition_Type.tp_new = PyType_GenericNew;
-    PyPosition_Type.tp_alloc = PyType_GenericAlloc;
-
     vlcInput_Type.tp_new = PyType_GenericNew;
     vlcInput_Type.tp_alloc = PyType_GenericAlloc;
 
index 1a42be7bbdf99c3f88ac5db9188819182c3fc0a4..4e330c8d6dbfcbbb84b391320c96b23908398dff 100644 (file)
  * Position
  ***********************************************************************/
 
-static int
-PyPosition_init( PyPosition *self, PyObject *args, PyObject *kwds )
+static PyObject *
+PyPosition_new( PyTypeObject *type, PyObject *args, PyObject *kwds )
 {
-    self->origin = mediacontrol_AbsolutePosition;
-    self->key    = mediacontrol_MediaTime;
-    self->value  = 0;
-    return 0;
+    PyPosition *self;
+    static char *kwlist[] = { "value", "origin", "key", NULL};
+    
+    self = PyObject_New( PyPosition, &PyPosition_Type );
+
+    self->value=0;
+    self->origin=mediacontrol_AbsolutePosition;
+    self->key=mediacontrol_MediaTime;
+
+    /* We do not care about the return value, since it will leave the fields
+       with their default value. */
+    if(! PyArg_ParseTupleAndKeywords( args, kwds, "|lii", kwlist,
+                                      &(self->value),
+                                      &(self->origin),
+                                      &(self->key) ) )
+    {
+        return NULL;        
+    }
+       
+    Py_INCREF( self );
+    return ( PyObject * )self;    
 }
 
 mediacontrol_PositionKey
@@ -167,7 +184,7 @@ static PyTypeObject PyPosition_Type =
     0,                         /*tp_setattro*/
     0,                         /*tp_as_buffer*/
     Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
-    "Represent a Position with origin, key and value",  /* tp_doc */
+    "Represent a Position with value, origin and key",  /* tp_doc */
     0,                        /* tp_traverse */
     0,                        /* tp_clear */
     0,                         /* tp_richcompare */
@@ -182,7 +199,7 @@ static PyTypeObject PyPosition_Type =
     0,                         /* tp_descr_get */
     0,                         /* tp_descr_set */
     0,                         /* tp_dictoffset */
-    ( initproc )PyPosition_init, /* tp_init */
+    0,                         /* tp_init */
     0,                         /* tp_alloc */
-    0,                         /* tp_new */
+    PyPosition_new,            /* tp_new */
 };