3 Python wrapper for librfxswf- module core.
5 Part of the swftools package.
7 Copyright (c) 2003 Matthias Kramm <kramm@quiss.org>
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
25 #include "../rfxswf.h"
27 #include "./pyutils.h"
28 #include "primitives.h"
33 1) taglist is rfxswflib's linked list. It should maybe implemented as Python
34 list, which would, however, mean that we would have to convert the list
35 back and forth for the following functions:
36 load, save, writeCGI, unfoldAll, foldAll, optimizeOrder
37 2) taglist should have an ID handler. Every time a tag is inserted, it's ID
38 is stored in a lookup list.
42 //-------------------------- Types -------------------------------------------
44 staticforward PyTypeObject SWFClass;
45 staticforward PyTypeObject TagListClass;
46 staticforward PyTypeObject TagClass;
55 /* ST_PLACEOBJECT, ST_PLACEOBJECT2*/
56 SWFPLACEOBJECT* placeobject;
65 PyDictObject* char2id;
66 PyDictObject* id2char;
72 SWF swf; //swf.firstTag ist not used
73 TagListObject*taglist;
77 //----------------------------------------------------------------------------
78 static PyObject* f_create(PyObject* self, PyObject* args, PyObject* kwargs)
80 static char *kwlist[] = {"version", "fps", "bbox", "name", NULL};
83 double framerate = 25;
85 SRECT bbox = {0,0,0,0};
88 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|idOs",
89 kwlist, &version, &framerate,
93 if (!PyArg_Parse(obbox, "(iiii)", &bbox.xmin, &bbox.ymin, &bbox.xmax, &bbox.ymax))
96 swf = PyObject_New(SWFObject, &SWFClass);
97 memset(&swf->swf, 0, sizeof(SWF));
99 swf->filename = strdup(filename);
103 swf->swf.fileVersion = version;
104 swf->swf.frameRate = (int)(framerate*0x100);
105 swf->swf.movieSize = bbox;
106 swf->taglist = PyObject_New(TagListObject, &TagListClass);
107 swf->taglist->firstTag = 0;
108 swf->taglist->searchTag = 0;
109 swf->taglist->lastTag = 0;
110 swf->taglist->currentID = 1;
111 swf->taglist->char2id = (PyDictObject*)PyDict_New();
112 swf->taglist->id2char = (PyDictObject*)PyDict_New();
114 if(swf->swf.fileVersion>=6)
115 swf->swf.compressed = 1;
117 mylog("create %08x -> %08x\n", (int)self, (int)swf);
118 return (PyObject*)swf;
120 //----------------------------------------------------------------------------
121 static PyObject* f_load(PyObject* self, PyObject* args)
127 if (!PyArg_ParseTuple(args,"s:load", &filename))
130 swf = PyObject_New(SWFObject, &SWFClass);
131 memset(&swf->swf, 0, sizeof(SWF));
132 swf->filename = strdup(filename);
133 swf->taglist = PyObject_New(TagListObject, &TagListClass);
136 PyErr_SetString(PyExc_Exception, setError("Couldn't open file %s", filename));
139 fi = open(filename,O_RDONLY|O_BINARY);
141 PyErr_SetString(PyExc_Exception, setError("Couldn't open file %s", filename));
144 if(swf_ReadSWF(fi,&swf->swf)<0) {
146 PyErr_SetString(PyExc_Exception, setError("%s is not a valid SWF file or contains errors",filename));
151 swf->taglist->firstTag = swf->swf.firstTag;
152 swf->taglist->searchTag = swf->swf.firstTag;
153 swf->taglist->lastTag = swf->swf.firstTag;
154 swf->taglist->currentID = 1;
155 swf->taglist->char2id = (PyDictObject*)PyDict_New();
156 swf->taglist->id2char = (PyDictObject*)PyDict_New();
157 swf->swf.firstTag = 0;
159 mylog("load %08x -> %08x\n", (int)self, (int)swf);
160 return (PyObject*)swf;
162 //----------------------------------------------------------------------------
163 static PyObject * swf_save(PyObject* self, PyObject* args, PyObject* kwargs)
165 static char *kwlist[] = {"name", "compress", NULL};
175 swfo = (SWFObject*)self;
178 filename = swfo->filename;
180 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|si", kwlist, &filename, &compress))
183 // keyword arg compress (=1) forces compression
187 swf->firstTag = swfo->taglist->firstTag;
189 // fix the file, in case it is empty or not terminated properly
191 TAG*tag = swf->firstTag;
193 tag = swf->firstTag = swf_InsertTag(0,ST_END);
194 while(tag && tag->next)
196 if(tag->id != ST_END) {
197 tag = swf_InsertTag(tag,ST_END);
201 fi = open(filename, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0644);
203 PyErr_SetString(PyExc_Exception, setError("couldn't create output file %s", filename));
206 if(swf->compressed) {
207 if(swf_WriteSWC(fi, swf)<0) {
209 PyErr_SetString(PyExc_Exception, setError("WriteSWC() failed."));
213 if(swf_WriteSWF(fi, swf)<0) {
215 PyErr_SetString(PyExc_Exception, setError("WriteSWC() failed."));
225 //----------------------------------------------------------------------------
226 static PyObject * swf_writeCGI(PyObject* self, PyObject* args)
228 SWFObject*swf = (SWFObject*)self;
229 if(!self || !PyArg_ParseTuple(args,""))
231 swf->swf.firstTag = swf->taglist->firstTag;
232 swf_WriteCGI(&swf->swf);
233 swf->swf.firstTag = 0;
236 //----------------------------------------------------------------------------
237 static PyObject * taglist_foldAll(PyObject* self, PyObject* args)
240 TagListObject*taglist = (TagListObject*)self;
241 if(!self || !PyArg_ParseTuple(args,""))
243 swf.firstTag = taglist->firstTag;
245 taglist->firstTag = swf.firstTag;
246 taglist->lastTag = 0; // FIXME
247 taglist->searchTag = 0;
250 //----------------------------------------------------------------------------
251 static PyObject * taglist_unfoldAll(PyObject* self, PyObject* args)
254 TagListObject*taglist = (TagListObject*)self;
255 if(!self || !PyArg_ParseTuple(args,""))
257 swf.firstTag = taglist->firstTag;
259 taglist->firstTag = swf.firstTag;
260 taglist->lastTag = 0; // FIXME
261 taglist->searchTag = 0;
264 //----------------------------------------------------------------------------
265 static PyObject * taglist_optimizeOrder(PyObject* self, PyObject* args)
268 TagListObject*taglist = (TagListObject*)self;
269 if(!self || !PyArg_ParseTuple(args,""))
271 swf.firstTag = taglist->firstTag;
273 taglist->firstTag = swf.firstTag;
274 taglist->lastTag = 0; // FIXME
275 taglist->searchTag = 0;
278 //----------------------------------------------------------------------------
280 //TODO: void swf_Relocate(SWF*swf, char*bitmap); // bitmap is 65536 bytes, bitmap[a]==0 means id a is free
282 static PyMethodDef swf_functions[] =
283 {{"save", (PyCFunction)swf_save, METH_KEYWORDS, "Save SWF to disk"},
284 {"writeCGI", (PyCFunction)swf_writeCGI, METH_VARARGS, "print SWF as CGI to stdout"},
285 {NULL, NULL, 0, NULL}
288 //----------------------------------------------------------------------------
289 static void swf_dealloc(PyObject* self)
293 swfo = (SWFObject*)self;
295 mylog("swf_dealloc %08x(%d)\n", (int)self, self->ob_refcnt);
297 free(swfo->filename);
300 Py_DECREF(swfo->taglist);
304 //----------------------------------------------------------------------------
305 static void taglist_dealloc(PyObject* self)
307 TagListObject*taglist = (TagListObject*)self;
309 mylog("taglist_dealloc %08x(%d)\n", (int)self, self->ob_refcnt);
310 swf.firstTag = taglist->firstTag;
312 taglist->firstTag = 0;
313 taglist->lastTag = 0;
314 taglist->searchTag = 0;
317 //----------------------------------------------------------------------------
318 static int swf_print(PyObject * self, FILE *fi, int flags) //flags&Py_PRINT_RAW
320 SWFObject*swf = (SWFObject*)self;
321 swf_DumpHeader(fi, &swf->swf);
322 //void swf_DumpSWF(FILE * f,SWF*swf);
323 mylog("print %08x(%d)\n", (int)self, self->ob_refcnt);
326 //----------------------------------------------------------------------------
327 static PyObject* swf_getattr(PyObject * self, char* a)
329 SWFObject*swf = (SWFObject*)self;
332 if(!strcmp(a, "fps")) {
333 double fps = swf->swf.frameRate/256.0;
334 mylog("swf_getattr %08x(%d) %s = %f\n", (int)self, self->ob_refcnt, a, fps);
335 return Py_BuildValue("d", fps);
336 } else if(!strcmp(a, "version")) {
337 int version = swf->swf.fileVersion;;
338 mylog("swf_getattr %08x(%d) %s = %d\n", (int)self, self->ob_refcnt, a, version);
339 return Py_BuildValue("i", version);
340 } else if(!strcmp(a, "name")) {
341 char*filename = swf->filename;
342 mylog("swf_getattr %08x(%d) %s = %s\n", (int)self, self->ob_refcnt, a, filename);
343 return Py_BuildValue("s", filename);
344 } else if(!strcmp(a, "bbox")) {
345 int xmin,ymin,xmax,ymax;
346 xmin = swf->swf.movieSize.xmin;
347 ymin = swf->swf.movieSize.ymin;
348 xmax = swf->swf.movieSize.xmax;
349 ymax = swf->swf.movieSize.ymax;
350 mylog("swf_getattr %08x(%d) %s = (%d,%d,%d,%d)\n", (int)self, self->ob_refcnt, a, xmin,ymin,xmax,ymax);
351 return Py_BuildValue("(iiii)", xmin, ymin, xmax, ymax);
352 } else if(!strcmp(a, "tags")) {
353 PyObject*ret = (PyObject*)(swf->taglist);
355 mylog("swf_getattr %08x(%d) %s = %08x(%d)\n", (int)self, self->ob_refcnt, a, ret, ret->ob_refcnt);
359 ret = Py_FindMethod(swf_functions, self, a);
360 mylog("swf_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret);
363 //----------------------------------------------------------------------------
364 static int swf_setattr(PyObject * self, char* a, PyObject * o)
366 SWFObject*swf = (SWFObject*)self;
367 if(!strcmp(a, "fps")) {
369 if (!PyArg_Parse(o, "d", &fps))
371 swf->swf.frameRate = (int)(fps*0x100);
372 mylog("swf_setattr %08x(%d) %s = %f\n", (int)self, self->ob_refcnt, a, fps);
374 } else if(!strcmp(a, "version")) {
376 if (!PyArg_Parse(o, "i", &version))
378 swf->swf.fileVersion = version;
379 mylog("swf_setattr %08x(%d) %s = %d\n", (int)self, self->ob_refcnt, a, version);
381 } else if(!strcmp(a, "name")) {
383 if (!PyArg_Parse(o, "s", &filename))
386 free(swf->filename);swf->filename=0;
388 swf->filename = strdup(filename);
389 mylog("swf_setattr %08x(%d) %s = %s\n", (int)self, self->ob_refcnt, a, filename);
391 } else if(!strcmp(a, "bbox")) {
392 int xmin=0,ymin=0,xmax=0,ymax=0;
393 if (!PyArg_Parse(o, "(iiii)", &xmin, &ymin, &xmax, &ymax))
396 swf->swf.movieSize.xmin = xmin;
397 swf->swf.movieSize.ymin = ymin;
398 swf->swf.movieSize.xmax = xmax;
399 swf->swf.movieSize.ymax = ymax;
400 mylog("swf_setattr %08x(%d) %s = (%d,%d,%d,%d)\n", (int)self, self->ob_refcnt, a, xmin,ymin,xmax,ymax);
402 } else if(!strcmp(a, "tags")) {
403 TagListObject* taglist;
404 /*if (!PyArg_Parse(o, "O!", &TagListClass, &taglist));
406 taglist = (TagListObject*)o;
407 Py_DECREF(swf->taglist);
408 swf->taglist = taglist;
409 Py_INCREF(swf->taglist);
410 mylog("swf_setattr %08x(%d) %s = %08x\n", (int)self, self->ob_refcnt, a, swf->taglist);
414 mylog("swf_setattr %08x(%d) %s = ? (%08x)\n", (int)self, self->ob_refcnt, a, o);
418 //----------------------------------------------------------------------------
419 static PyMethodDef taglist_functions[] =
420 {{"foldAll", taglist_foldAll, METH_VARARGS, "fold all sprites (movieclips) in the list"},
421 {"unfoldAll", taglist_unfoldAll, METH_VARARGS, "unfold (expand) all sprites (movieclips) in the list"},
422 {"optimizeOrder", taglist_optimizeOrder, METH_VARARGS, "Reorder the Tag structure"},
423 {NULL, NULL, 0, NULL}
426 static PyObject* taglist_getattr(PyObject * self, char* a)
428 PyObject* ret = Py_FindMethod(taglist_functions, self, a);
429 mylog("taglist_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret);
432 //----------------------------------------------------------------------------
433 static int taglist_length(PyObject * self)
435 TagListObject*tags = (TagListObject*)self;
438 mylog("taglist_length %08x(%d)", (int)self, self->ob_refcnt);
439 tag = tags->firstTag;
446 //----------------------------------------------------------------------------
447 static PyObject * taglist_concat(PyObject * self, PyObject* list)
450 TagListObject*taglist = (TagListObject*)self;
451 mylog("taglist_concat %08x(%d) %08x", (int)self, self->ob_refcnt, list);
453 if (PyArg_Parse(list, "O!", &TagClass, &tag)) {
454 /* copy tag, so we don't have to do INCREF(tag) (and don't
455 get problems if the tag is appended to more than one
457 /* TODO: handle IDs */
458 mylog("taglist_concat: Tag", (int)self, self->ob_refcnt);
459 taglist->lastTag = swf_InsertTag(taglist->lastTag, tag->tag->id);
460 swf_SetBlock(taglist->lastTag, tag->tag->data, tag->tag->len);
461 if(!taglist->firstTag) {
462 taglist->firstTag = taglist->searchTag = taglist->lastTag;
464 if(swf_isDefiningTag(tag->tag)) {
465 PyObject*id = PyLong_FromLong(taglist->currentID);
466 PyDict_SetItem((PyObject*)(taglist->char2id), list, id);
468 PyDict_SetItem((PyObject*)(taglist->id2char), id, list);
475 if (PyList_Check(list)) {
476 int l = PyList_Size(list);
478 mylog("taglist_concat: PythonList", (int)self, self->ob_refcnt);
480 PyObject*item = PyList_GetItem(list, t);
481 self = taglist_concat(self, item);
488 PyErr_SetString(PyExc_Exception, setError("taglist concatenation only works with tags and lists (%08x).", list));
491 //----------------------------------------------------------------------------
492 staticforward TagObject* TagObject_New();
493 static PyObject * taglist_item(PyObject * self, int index)
495 TagListObject*taglist = (TagListObject*)self;
499 mylog("taglist_item %08x(%d) [%d]", (int)self, self->ob_refcnt, index);
502 PyErr_SetString(PyExc_Exception, setError("Negative Indices not supported."));
506 tag = taglist->firstTag;
507 while(tag && i<index) {
511 if(!tag || i != index) {
513 PyErr_SetString(PyExc_Exception, setError("No Tag at position %d", index));
517 mylog("taglist_item %08x(%d)->IndexError (%d)", (int)self, self->ob_refcnt, index);
519 Py_INCREF(PyExc_IndexError);
520 PyErr_SetObject(PyExc_IndexError, Py_None);
524 tagobject = TagObject_New();
525 tagobject->tag = tag;
527 return (PyObject*)tagobject;
529 //----------------------------------------------------------------------------
530 static void tag_dealloc(PyObject * self)
532 TagObject*tag = (TagObject*)self;
533 mylog("tag_dealoc %08x(%d)\n", (int)self, self->ob_refcnt);
534 if(tag->placeobject) {
535 swf_PlaceObjectFree(tag->placeobject);
536 tag->placeobject = 0;
539 swf_FontFree(tag->font);
543 Py_DECREF(tag->character);
548 //----------------------------------------------------------------------------
549 static PyObject* tag_setU8(PyObject * self, PyObject*other)
553 //----------------------------------------------------------------------------
554 static PyObject* tag_setbackgroundcolor_getrgb(PyObject * self, PyObject*other)
556 TagObject*tag = (TagObject*)self;
558 r = tag->tag->data[0];
559 g = tag->tag->data[1];
560 b = tag->tag->data[2];
561 return Py_BuildValue("(iii)", r,g,b);
563 //----------------------------------------------------------------------------
565 static struct tagfunctions {
571 ST_SETBACKGROUNDCOLOR,
572 {{"getRGB", tag_setbackgroundcolor_getrgb, METH_VARARGS, "get's the color set by this tag"},
573 {NULL, NULL, 0, NULL}
577 static PyMethodDef common_tagfunctions[] =
578 {{"setU8", tag_setU8, METH_VARARGS, "sets a byte to the tag data"},
579 {NULL, NULL, 0, NULL}
582 static PyObject* tag_getattr(PyObject * self, char* a)
584 TagObject*tag = (TagObject*)self;
585 PyObject* ret = NULL;
586 int id = tag->tag->id;
589 /* search for a tag specific function */
590 for(t=0;t<sizeof(tagfunctions)/sizeof(tagfunctions[0]);t++)
592 if(id==tagfunctions[t].id) {
593 mylog("tag_getattr: id %d found\n", id);
594 ret = Py_FindMethod(tagfunctions[t].f, self, a);
599 /* search in the functions common to all tags */
600 FindMethodMore(ret, common_tagfunctions, self, a);
602 mylog("tag_getattr %08x(%d) %s: %08x\n", (int)self, self->ob_refcnt, a, ret);
605 //----------------------------------------------------------------------------
607 //----------------------------------------------------------------------------
608 static TagObject* TagObject_New()
610 TagObject*tag = PyObject_New(TagObject, &TagClass);
613 tag->placeobject = 0;
618 static PyObject* f_SetBackgroundColor(PyObject* self, PyObject* args, PyObject* kwargs)
620 static char *kwlist[] = {"color", NULL};
625 /* 1st try- copy constructor */
626 if(!PyArg_ParseTupleAndKeywords(args, kwargs, "O!", kwlist, &ColorClass, &color)) {
627 /* 2nd try- color's contructor */
628 color = (ColorObject*)f_Color(NULL, args, kwargs);
633 tag = TagObject_New();
634 tag->tag = swf_InsertTag(0, ST_SETBACKGROUNDCOLOR);
635 swf_SetU8(tag->tag, color->rgba.r);
636 swf_SetU8(tag->tag, color->rgba.g);
637 swf_SetU8(tag->tag, color->rgba.b);
638 mylog("SetBackgroundColor(%02x,%02x,%02x) %08x -> %08x\n", color->rgba.r, color->rgba.g, color->rgba.b, (int)self, tag);
639 return (PyObject*)tag;
641 //----------------------------------------------------------------------------
642 static PyObject* f_DefineFont(PyObject* self, PyObject* args, PyObject* kwargs)
644 static char *kwlist[] = {"filename", NULL};
649 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &filename))
652 font = swf_ReadFont(filename);
653 mylog("font=%08x",font);
655 PyErr_SetString(PyExc_Exception, setError("Could not load %s", filename));
659 tag = TagObject_New();
661 tag->tag = swf_InsertTag(0, ST_DEFINEFONT2);
662 tag->font->id = 0xabcd; // swf_SetU16(id);
663 swf_FontSetDefine2(tag->tag, tag->font); // TODO: should this be done later, in taglist?
664 mylog("DefineFont %08x -> %08x\n", (int)self, (int)tag);
665 return (PyObject*)tag;
667 //----------------------------------------------------------------------------
668 static PyObject* f_Protect(PyObject* self, PyObject* args, PyObject* kwargs)
670 static char *kwlist[] = {"password", NULL};
674 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|s", kwlist, &password))
677 tag = TagObject_New();
678 tag->tag = swf_InsertTag(0, ST_PROTECT);
680 swf_SetPassword(tag->tag, password);
682 mylog("f_Protect %08x -> %08x\n", (int)self, (int)tag);
683 return (PyObject*)tag;
685 //----------------------------------------------------------------------------
686 static PyObject* f_DefineText(PyObject* self, PyObject* args, PyObject* kwargs)
688 static char *kwlist[] = {"font", "text", "size", "color", NULL};
695 RGBA rgba = {0,0,0,255};
696 ColorObject*color = 0;
700 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!u#i|O!", kwlist, &TagClass, &font, &text, &textlen, &size, &ColorClass, &color))
703 unicode16 = PyUnicode_DecodeUTF16(text, textlen*2, NULL, NULL);
704 unicode8 = PyUnicode_AsUTF8String(unicode16);
705 text = PyString_AS_STRING(unicode8);
710 mylog("DefineText: text = %s", text);
712 tag = TagObject_New();
713 tag ->tag= swf_InsertTag(0, ST_DEFINETEXT2);
714 swf_SetU16(tag->tag, /*ID*/0);
715 r = swf_SetDefineText(tag->tag, font->font, &rgba, text, size);
716 mylog("DefineText %08x -> %08x\n", (int)self, (int)tag);
717 return (PyObject*)tag;
719 //----------------------------------------------------------------------------
720 static PyObject* f_PlaceObject(PyObject* self, PyObject* args, PyObject* kwargs)
722 static char *kwlist[] = {"character", "depth", "matrix", "colortransform", "ratio", "name", "clipdepth", "action", NULL};
725 TagObject*character = 0;
728 MatrixObject*matrix = 0;
729 CXFormObject*cxform = 0;
731 ActionObject*action = 0;
734 po = malloc(sizeof(SWFPLACEOBJECT));
735 memset(po, 0, sizeof(SWFPLACEOBJECT));
737 swf_GetPlaceObject(0, po);
739 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!i|O!O!isiO!", kwlist,
740 &TagClass, &character,
742 &MatrixClass, &matrix,
743 &CXFormClass, &cxform,
752 po->clipdepth = clipdepth;
755 if(clipdepth) po->matrix = matrix->matrix;
756 if(cxform) po->cxform = cxform->cxform;
757 if(action) po->actions = action->action;
759 tag = TagObject_New();
760 tag->placeobject = po;
761 Py_INCREF(character);
762 tag->character = (PyObject*)character;
763 tag->tag= swf_InsertTag(0, ST_PLACEOBJECT2);
764 swf_SetPlaceObject(tag->tag, po);
765 mylog("PlaceObject %08x -> %08x\n", (int)self, (int)tag);
766 return (PyObject*)tag;
768 //----------------------------------------------------------------------------
769 static PyTypeObject SWFClass =
771 PyObject_HEAD_INIT(NULL)
774 tp_basicsize: sizeof(SWFObject),
776 tp_dealloc: swf_dealloc,
778 tp_getattr: swf_getattr,
779 tp_setattr: swf_setattr,
781 static PySequenceMethods taglist_as_sequence =
783 sq_length: taglist_length, // len(obj)
784 sq_concat: taglist_concat, // obj += [...], obj1+obj2
785 sq_repeat: 0, // x*n, intargfunc
786 sq_item: taglist_item, // obj[3]
787 sq_slice: 0, // x[i:j] intintargfunc
788 sq_ass_item: 0, // x[i] = y intobjargproc
789 sq_ass_slice: 0, // x[i:j] = v intintobjargproc
790 sq_contains: 0, //???
792 static PyTypeObject TagListClass =
794 PyObject_HEAD_INIT(NULL)
797 tp_basicsize: sizeof(TagListObject),
799 tp_dealloc: taglist_dealloc,
800 tp_print: 0, // print x
801 tp_getattr: taglist_getattr, // x.attr
802 tp_setattr: 0, // x.attr = v
803 tp_compare: 0, // x>y
804 tp_repr: 0, // `x`, print x
806 tp_as_sequence: &taglist_as_sequence,
808 static PyTypeObject TagClass =
810 PyObject_HEAD_INIT(NULL)
813 tp_basicsize: sizeof(TagObject),
815 tp_dealloc: tag_dealloc,
817 tp_getattr: tag_getattr,
819 //----------------------------------------------------------------------------
821 static PyMethodDef SWFMethods[] =
824 {"load", f_load, METH_VARARGS, "Load a SWF from disc."},
825 {"create", (PyCFunction)f_create, METH_KEYWORDS, "Create a new SWF from scratch."},
828 {"Color", (PyCFunction)f_Color, METH_KEYWORDS, "Create a new color object."},
829 {"Gradient", (PyCFunction)f_Gradient, METH_KEYWORDS, "Create a new gradient object."},
830 {"ColorTransform", (PyCFunction)f_ColorTransform, METH_KEYWORDS, "Create a new colortransform object."},
831 {"Matrix", (PyCFunction)f_Matrix, METH_KEYWORDS, "Create a new matrix object."},
832 {"BBox", (PyCFunction)f_BBox, METH_KEYWORDS, "Create a new bounding box object."},
835 {"SetBackgroundColor", (PyCFunction)f_SetBackgroundColor, METH_KEYWORDS, "Create a SetBackGroundColor Tag."},
836 {"Protect", (PyCFunction)f_Protect, METH_KEYWORDS, "Create a Protect Tag."},
837 {"DefineFont", (PyCFunction)f_DefineFont, METH_KEYWORDS, "Create a DefineFont Tag."},
838 {"DefineText", (PyCFunction)f_DefineText, METH_KEYWORDS, "Create a DefineText Tag."},
839 {"PlaceObject", (PyCFunction)f_PlaceObject, METH_KEYWORDS, "Create a PlaceObject Tag."},
840 {NULL, NULL, 0, NULL}
845 SWFClass.ob_type = &PyType_Type;
847 initLog("test.log",8,0,0,0,0);
849 (void)Py_InitModule("SWF", SWFMethods);