X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Fpython%2FSWF.c;h=2a5b903b539a1ac96bab99ac690494c30304ca8d;hb=ffcc9b8c02b74d7f6fb9f0c56ba50fb4e44e227a;hp=ca82f2431c7da90e864dc3ef2cb329017dbfc2af;hpb=3d9bf5d5a8781a0ae46d2e39c61f21cf8c1b2e6f;p=swftools.git diff --git a/lib/python/SWF.c b/lib/python/SWF.c index ca82f24..2a5b903 100644 --- a/lib/python/SWF.c +++ b/lib/python/SWF.c @@ -151,6 +151,8 @@ static PyObject* f_load(PyObject* self, PyObject* args) swf->taglist->firstTag = swf->swf.firstTag; swf->taglist->searchTag = swf->swf.firstTag; swf->taglist->lastTag = swf->swf.firstTag; + while(swf->taglist->lastTag->next) + swf->taglist->lastTag = swf->taglist->lastTag->next; swf->taglist->currentID = 1; swf->taglist->char2id = (PyDictObject*)PyDict_New(); swf->taglist->id2char = (PyDictObject*)PyDict_New(); @@ -285,13 +287,6 @@ static PyMethodDef swf_functions[] = {NULL, NULL, 0, NULL} }; -static PyMethodDef taglist_functions[] = -{{"foldAll", taglist_foldAll, METH_VARARGS, "fold all sprites (movieclips) in the list"}, - {"unfoldAll", taglist_unfoldAll, METH_VARARGS, "unfold (expand) all sprites (movieclips) in the list"}, - {"optimizeOrder", taglist_optimizeOrder, METH_VARARGS, "Reorder the Tag structure"}, - {NULL, NULL, 0, NULL} -}; - //---------------------------------------------------------------------------- static void swf_dealloc(PyObject* self) { @@ -423,6 +418,13 @@ err: } //---------------------------------------------------------------------------- +static PyMethodDef taglist_functions[] = +{{"foldAll", taglist_foldAll, METH_VARARGS, "fold all sprites (movieclips) in the list"}, + {"unfoldAll", taglist_unfoldAll, METH_VARARGS, "unfold (expand) all sprites (movieclips) in the list"}, + {"optimizeOrder", taglist_optimizeOrder, METH_VARARGS, "Reorder the Tag structure"}, + {NULL, NULL, 0, NULL} +}; + static PyObject* taglist_getattr(PyObject * self, char* a) { PyObject* ret = Py_FindMethod(taglist_functions, self, a); @@ -496,9 +498,9 @@ static PyObject * taglist_item(PyObject * self, int index) TAG*tag; TagObject*tagobject; int i = 0; - mylog("taglist_item %08x(%d) [%d]", (int)self, self->ob_refcnt, i); + mylog("taglist_item %08x(%d) [%d]", (int)self, self->ob_refcnt, index); - if(i<0) { + if(index<0) { PyErr_SetString(PyExc_Exception, setError("Negative Indices not supported.")); return NULL; } @@ -506,9 +508,18 @@ static PyObject * taglist_item(PyObject * self, int index) tag = taglist->firstTag; while(tag && inext; + i++; } if(!tag || i != index) { - PyErr_SetString(PyExc_Exception, setError("No Tag at position %d", index)); + if(index> i+10) { + PyErr_SetString(PyExc_Exception, setError("No Tag at position %d", index)); + return NULL; + } + + mylog("taglist_item %08x(%d)->IndexError (%d)", (int)self, self->ob_refcnt, index); + + Py_INCREF(PyExc_IndexError); + PyErr_SetObject(PyExc_IndexError, Py_None); return NULL; } @@ -581,16 +592,18 @@ static PyObject* tag_getattr(PyObject * self, char* a) for(t=0;tob_refcnt, a, ret); + return ret; } } + + ret = Py_FindMethod(common_tagfunctions, self, a); - /* search in the functions common to all tags */ - FindMethodMore(ret, common_tagfunctions, self, a); - - mylog("taglist_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret); + mylog("tag_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret); return ret; } //---------------------------------------------------------------------------- @@ -656,6 +669,24 @@ static PyObject* f_DefineFont(PyObject* self, PyObject* args, PyObject* kwargs) return (PyObject*)tag; } //---------------------------------------------------------------------------- +static PyObject* f_Protect(PyObject* self, PyObject* args, PyObject* kwargs) +{ + static char *kwlist[] = {"password", NULL}; + char*password = 0; + TagObject*tag; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &password)) + return NULL; + + tag = TagObject_New(); + tag->tag = swf_InsertTag(0, ST_PROTECT); + if(password) { + swf_SetPassword(tag->tag, password); + } + mylog("f_Protect %08x -> %08x\n", (int)self, (int)tag); + return (PyObject*)tag; +} +//---------------------------------------------------------------------------- static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs) { static char *kwlist[] = {"font", "text", "size", "color", NULL}; @@ -692,7 +723,7 @@ static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs) //---------------------------------------------------------------------------- static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs) { - static char *kwlist[] = {"character", "depth", "matrix", "colortransform", "ratio", "name", "clipdepth", "action"}; + static char *kwlist[] = {"character", "depth", "matrix", "colortransform", "ratio", "name", "clipdepth", "action", NULL}; TagObject*tag; TagObject*character = 0; @@ -791,8 +822,19 @@ static PyTypeObject TagClass = }; //---------------------------------------------------------------------------- +static PyObject* module_verbose(PyObject* self, PyObject* args) +{ + if (!PyArg_ParseTuple(args,"i", &verbose)) + return NULL; + return Py_BuildValue("s", 0); +} + + static PyMethodDef SWFMethods[] = { + /* Module functions */ + {"verbose", module_verbose, METH_VARARGS, "Set the module verbosity"}, + /* SWF creation*/ {"load", f_load, METH_VARARGS, "Load a SWF from disc."}, {"create", (PyCFunction)f_create, METH_KEYWORDS, "Create a new SWF from scratch."}, @@ -806,6 +848,7 @@ static PyMethodDef SWFMethods[] = /* TAGS */ {"SetBackgroundColor", (PyCFunction)f_SetBackgroundColor, METH_KEYWORDS, "Create a SetBackGroundColor Tag."}, + {"Protect", (PyCFunction)f_Protect, METH_KEYWORDS, "Create a Protect Tag."}, {"DefineFont", (PyCFunction)f_DefineFont, METH_KEYWORDS, "Create a DefineFont Tag."}, {"DefineText", (PyCFunction)f_DefineText, METH_KEYWORDS, "Create a DefineText Tag."}, {"PlaceObject", (PyCFunction)f_PlaceObject, METH_KEYWORDS, "Create a PlaceObject Tag."},