Index: genmodule.py =================================================================== --- genmodule.py (revision 58978) +++ genmodule.py (working copy) @@ -27,7 +27,9 @@ # Names of functions in the object-description struct. # FUNCLIST = ['new', 'tp_dealloc', 'tp_print', 'tp_getattr', 'tp_setattr', - 'tp_compare', 'tp_repr', 'tp_hash', 'tp_call', 'tp_str'] + 'tp_compare', 'tp_repr', 'tp_hash', 'tp_call', 'tp_str', + 'tp_methods', 'tp_members', 'tp_init', 'tp_new', 'tp_traverse', + 'tp_clear'] TYPELIST = ['tp_as_number', 'tp_as_sequence', 'tp_as_mapping', 'structure'] # @@ -92,6 +94,7 @@ self.typelist = [] self.methodlist = [] self.funclist = ['new'] + self.memberlist = [] writer.__init__(self) def writecode(self, fp): @@ -100,10 +103,36 @@ self.writebody(fp) def writehead(self, fp): + saved = self.memberlist + new_ml = '' + for fn in self.memberlist: + self.member = fn + new_ml = new_ml + ( + 'XXX %s;\n' + %(fn)) + self.memberlist = new_ml self.addcode('object_head', fp) + self.memberlist = saved def writebody(self, fp): new_ml = '' + for fn in self.memberlist: + self.member = fn + print 'member', fn + self.addcode('object_member', fp) + new_ml = new_ml + ( + '{"%s",\tT_XXX, offsetof(%sObject,%s),\t0,\t%s_%s__doc__},\n' + %(fn, self.abbrev, fn, self.abbrev, fn)) + self.memberlist = new_ml + + if len(self.memberlist) > 0 : + self.addcode('object_mlist2', fp) + + # Add tp_members if we have methods + if self.memberlist and not 'tp_members' in self.funclist: + self.funclist.insert(0, 'tp_members') + + new_ml = '' for fn in self.methodlist: self.method = fn self.addcode('object_method', fp) @@ -113,9 +142,9 @@ self.methodlist = new_ml self.addcode('object_mlist', fp) - # Add getattr if we have methods - if self.methodlist and not 'tp_getattr' in self.funclist: - self.funclist.insert(0, 'tp_getattr') + # Add tp_methods if we have methods + if self.methodlist and not 'tp_methods' in self.funclist: + self.funclist.insert(0, 'tp_methods') for fn in FUNCLIST: setattr(self, fn, '0') @@ -133,6 +162,13 @@ self.funclist.remove('tp_setattr') self.tp_getattr = self.abbrev + '_getattr' self.tp_setattr = self.abbrev + '_setattr' + + if 'tp_dealloc' in self.funclist: + if 'tp_traverse' not in self.funclist: + self.funclist.insert(0, 'tp_traverse') + if 'tp_clear' not in self.funclist: + self.funclist.insert(0, 'tp_clear') + for fn in self.funclist: self.addcode('object_'+fn, fp) setattr(self, fn, '%s_%s'%(self.abbrev, fn[3:])) Index: modulator.py =================================================================== --- modulator.py (revision 58978) +++ modulator.py (working copy) @@ -18,7 +18,7 @@ import sys, os if os.name <> 'mac': - sys.path.append(os.path.join(os.environ['HOME'], + sys.path.append(os.path.join(os.environ['HOMEPATH'], 'src/python/Tools/modulator')) from Tkinter import * @@ -108,7 +108,14 @@ if not fn: return + root, ext = os.path.splitext(fn) + fp = open(fn, 'w') + pycode = pycode + """\n +fp = open('%s', 'w') +genmodule.write(fp, m) +fp.close() +""" % ( root + '.c' ) fp.write(pycode) fp.close() @@ -210,7 +217,7 @@ raise oops def gencode(self, name, objects): - rv = '' + rv = 'import genmodule\n' self.synchronize() for o in objects: o.synchronize() Index: Templates/copyright =================================================================== --- Templates/copyright (revision 58978) +++ Templates/copyright (working copy) @@ -0,0 +1,3 @@ +// WePlay Inc. +// + Index: Templates/module_head =================================================================== --- Templates/module_head (revision 58978) +++ Templates/module_head (working copy) @@ -1,6 +1,4 @@ #include "Python.h" -static PyObject *ErrorObject; - /* ----------------------------------------------------- */ Index: Templates/module_tail =================================================================== --- Templates/module_tail (revision 58978) +++ Templates/module_tail (working copy) @@ -13,7 +13,7 @@ "" ; -void +PyMODINIT_FUNC init$name$() { PyObject *m, *d; @@ -24,9 +24,8 @@ (PyObject*)NULL,PYTHON_API_VERSION); /* Add some symbolic constants to the module */ - d = PyModule_GetDict(m); - ErrorObject = PyString_FromString("$name$.error"); - PyDict_SetItemString(d, "error", ErrorObject); + Py_INCREF(&$abbrev$Type); + PyModule_AddObject(m, "$abbrev$", (PyObject *)&$abbrev$Type); /* XXXX Add constants here */ Index: Templates/object_head =================================================================== --- Templates/object_head (revision 58978) +++ Templates/object_head (working copy) @@ -3,10 +3,11 @@ typedef struct { PyObject_HEAD + $memberlist$ /* XXXX Add your own stuff here */ -} $abbrev$object; +} $abbrev$Object; -static PyTypeObject $Abbrev$type; +extern static PyTypeObject $Abbrev$Type; Index: Templates/object_member =================================================================== --- Templates/object_member (revision 0) +++ Templates/object_member (revision 0) @@ -0,0 +1,5 @@ + +static char $abbrev$_$member$__doc__[] = +"" +; + Index: Templates/object_method =================================================================== --- Templates/object_method (revision 58978) +++ Templates/object_method (working copy) @@ -4,11 +4,14 @@ ; static PyObject * -$abbrev$_$method$($abbrev$object *self, PyObject *args) +$abbrev$_$method$($abbrev$Object *self, PyObject *args) { + PyObject* retval = Py_None; + if (!PyArg_ParseTuple(args, "")) return NULL; - Py_INCREF(Py_None); - return Py_None; + + Py_INCREF(retval); + return retval; } Index: Templates/object_mlist2 =================================================================== --- Templates/object_mlist2 (revision 0) +++ Templates/object_mlist2 (revision 0) @@ -0,0 +1,8 @@ + +static struct PyMemberDef $abbrev$_members[] = { + $memberlist$ + {NULL, NULL} /* sentinel */ +}; + +/* ---------- */ + Index: Templates/object_new =================================================================== --- Templates/object_new (revision 58978) +++ Templates/object_new (working copy) @@ -1,10 +1,10 @@ -static $abbrev$object * -new$abbrev$object() +static $abbrev$Object * +new$abbrev$Object() { - $abbrev$object *self; + $abbrev$Object *self; - self = PyObject_NEW($abbrev$object, &$Abbrev$type); + self = PyObject_NEW($abbrev$Object, & $Abbrev$Type); if (self == NULL) return NULL; /* XXXX Add your own initializers here */ Index: Templates/object_structure =================================================================== --- Templates/object_structure (revision 58978) +++ Templates/object_structure (working copy) @@ -12,7 +12,7 @@ }; static PyObject * -$abbrev$_getattr($abbrev$object *self, char *name) +$abbrev$_getattr($abbrev$Object *self, char *name) { PyObject *rv; @@ -26,7 +26,7 @@ static int -$abbrev$_setattr($abbrev$object *self, char *name, PyObject *v) +$abbrev$_setattr($abbrev$Object *self, char *name, PyObject *v) { /* XXXX Add your own setattr code here */ if ( v == NULL ) { Index: Templates/object_tail =================================================================== --- Templates/object_tail (revision 58978) +++ Templates/object_tail (working copy) @@ -1,19 +1,19 @@ -static char $Abbrev$type__doc__[] = +static char $Abbrev$Type__doc__[] = "" ; -static PyTypeObject $Abbrev$type = { +static PyTypeObject $Abbrev$Type = { PyObject_HEAD_INIT(&PyType_Type) 0, /*ob_size*/ "$name$", /*tp_name*/ - sizeof($abbrev$object), /*tp_basicsize*/ + sizeof($abbrev$Object), /*tp_basicsize*/ 0, /*tp_itemsize*/ /* methods */ (destructor)$tp_dealloc$, /*tp_dealloc*/ (printfunc)$tp_print$, /*tp_print*/ - (getattrfunc)$tp_getattr$, /*tp_getattr*/ - (setattrfunc)$tp_setattr$, /*tp_setattr*/ + (getattrfunc)0, /*tp_getattr*/ + (setattrfunc)0, /*tp_setattr*/ (cmpfunc)$tp_compare$, /*tp_compare*/ (reprfunc)$tp_repr$, /*tp_repr*/ $tp_as_number$, /*tp_as_number*/ @@ -24,8 +24,32 @@ (reprfunc)$tp_str$, /*tp_str*/ /* Space for future expansion */ - 0L,0L,0L,0L, - $Abbrev$type__doc__ /* Documentation string */ + + (getattrofunc)$tp_getattro$, /*tp_getattro*/ + (setattrofunc)$tp_setattro$, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + + $Abbrev$Type__doc__, /* Documentation string */ + + (traverseproc)$tp_traverse$, /* tp_traverse */ + (inquiry)$tp_clear$, /* tp_clear */ + 0, /* tp_richcompare */ + 0, /* tp_weaklistoffset */ + 0, /* tp_iter */ + 0, /* tp_iternext */ + $tp_methods$, /* tp_methods */ + $tp_members$, /* tp_members */ + 0, /* tp_getset */ + 0, /* tp_base */ + 0, /* tp_dict */ + 0, /* tp_descr_get */ + 0, /* tp_descr_set */ + 0, /* tp_dictoffset */ + (initproc)$tp_init$, /* tp_init */ + 0, /* tp_alloc */ + $tp_new$, /* tp_new */ + }; /* End of code for $name$ objects */ Index: Templates/object_tp_as_mapping =================================================================== --- Templates/object_tp_as_mapping (revision 58978) +++ Templates/object_tp_as_mapping (working copy) @@ -2,19 +2,19 @@ /* Code to access $name$ objects as mappings */ static int -$abbrev$_length($abbrev$object *self) +$abbrev$_length($abbrev$Object *self) { /* XXXX Return the size of the mapping */ } static PyObject * -$abbrev$_subscript($abbrev$object *self, PyObject *key) +$abbrev$_subscript($abbrev$Object *self, PyObject *key) { /* XXXX Return the item of self indexed by key */ } static int -$abbrev$_ass_sub($abbrev$object *self, PyObject *v, PyObject *w) +$abbrev$_ass_sub($abbrev$Object *self, PyObject *v, PyObject *w) { /* XXXX Put w in self under key v */ return 0; Index: Templates/object_tp_as_number =================================================================== --- Templates/object_tp_as_number (revision 58978) +++ Templates/object_tp_as_number (working copy) @@ -2,103 +2,103 @@ /* Code to access $name$ objects as numbers */ static PyObject * -$abbrev$_add($abbrev$object *v, $abbrev$object *w) +$abbrev$_add($abbrev$Object *v, $abbrev$Object *w) { /* XXXX Add them */ } static PyObject * -$abbrev$_sub($abbrev$object *v, $abbrev$object *w) +$abbrev$_sub($abbrev$Object *v, $abbrev$Object *w) { /* XXXX Subtract them */ } static PyObject * -$abbrev$_mul($abbrev$object *v, $abbrev$object *w) +$abbrev$_mul($abbrev$Object *v, $abbrev$Object *w) { /* XXXX Multiply them */ } static PyObject * -$abbrev$_div($abbrev$object *x, $abbrev$object *y) +$abbrev$_div($abbrev$Object *x, $abbrev$Object *y) { /* XXXX Divide them */ } static PyObject * -$abbrev$_mod($abbrev$object *x, $abbrev$object *y) +$abbrev$_mod($abbrev$Object *x, $abbrev$Object *y) { /* XXXX Modulo them */ } static PyObject * -$abbrev$_divmod($abbrev$object *x, $abbrev$object *y) +$abbrev$_divmod($abbrev$Object *x, $abbrev$Object *y) { /* XXXX Return 2-tuple with div and mod */ } static PyObject * -$abbrev$_pow($abbrev$object *v, $abbrev$object *w, $abbrev$object *z) +$abbrev$_pow($abbrev$Object *v, $abbrev$Object *w, $abbrev$Object *z) { /* XXXX */ } static PyObject * -$abbrev$_neg($abbrev$object *v) +$abbrev$_neg($abbrev$Object *v) { /* XXXX */ } static PyObject * -$abbrev$_pos($abbrev$object *v) +$abbrev$_pos($abbrev$Object *v) { /* XXXX */ } static PyObject * -$abbrev$_abs($abbrev$object *v) +$abbrev$_abs($abbrev$Object *v) { /* XXXX */ } static int -$abbrev$_nonzero($abbrev$object *v) +$abbrev$_nonzero($abbrev$Object *v) { /* XXXX Return 1 if non-zero */ } static PyObject * -$abbrev$_invert($abbrev$object *v) +$abbrev$_invert($abbrev$Object *v) { /* XXXX */ } static PyObject * -$abbrev$_lshift($abbrev$object *v, $abbrev$object *w) +$abbrev$_lshift($abbrev$Object *v, $abbrev$Object *w) { /* XXXX */ } static PyObject * -$abbrev$_rshift($abbrev$object *v, $abbrev$object *w) +$abbrev$_rshift($abbrev$Object *v, $abbrev$Object *w) { /* XXXX */ } static PyObject * -$abbrev$_and($abbrev$object *v, $abbrev$object *w) +$abbrev$_and($abbrev$Object *v, $abbrev$Object *w) { /* XXXX */ } static PyObject * -$abbrev$_xor($abbrev$object *v, $abbrev$object *w) +$abbrev$_xor($abbrev$Object *v, $abbrev$Object *w) { /* XXXX */ } static PyObject * -$abbrev$_or($abbrev$object *v, $abbrev$object *w) +$abbrev$_or($abbrev$Object *v, $abbrev$Object *w) { /* XXXX */ } @@ -111,31 +111,31 @@ } static PyObject * -$abbrev$_int($abbrev$object *v) +$abbrev$_int($abbrev$Object *v) { /* XXXX */ } static PyObject * -$abbrev$_long($abbrev$object *v) +$abbrev$_long($abbrev$Object *v) { /* XXXX */ } static PyObject * -$abbrev$_float($abbrev$object *v) +$abbrev$_float($abbrev$Object *v) { /* XXXX */ } static PyObject * -$abbrev$_oct($abbrev$object *v) +$abbrev$_oct($abbrev$Object *v) { /* XXXX Return object as octal stringobject */ } static PyObject * -$abbrev$_hex($abbrev$object *v) +$abbrev$_hex($abbrev$Object *v) { /* XXXX Return object as hex stringobject */ } Index: Templates/object_tp_as_sequence =================================================================== --- Templates/object_tp_as_sequence (revision 58978) +++ Templates/object_tp_as_sequence (working copy) @@ -2,37 +2,37 @@ /* Code to handle accessing $name$ objects as sequence objects */ static int -$abbrev$_length($abbrev$object *self) +$abbrev$_length($abbrev$Object *self) { /* XXXX Return the size of the object */ } static PyObject * -$abbrev$_concat($abbrev$object *self, PyObject *bb) +$abbrev$_concat($abbrev$Object *self, PyObject *bb) { /* XXXX Return the concatenation of self and bb */ } static PyObject * -$abbrev$_repeat($abbrev$object *self, int n) +$abbrev$_repeat($abbrev$Object *self, int n) { /* XXXX Return a new object that is n times self */ } static PyObject * -$abbrev$_item($abbrev$object *self, int i) +$abbrev$_item($abbrev$Object *self, int i) { /* XXXX Return the i-th object of self */ } static PyObject * -$abbrev$_slice($abbrev$object *self, int ilow, int ihigh) +$abbrev$_slice($abbrev$Object *self, int ilow, int ihigh) { /* XXXX Return the ilow..ihigh slice of self in a new object */ } static int -$abbrev$_ass_item($abbrev$object *self, int i, PyObject *v) +$abbrev$_ass_item($abbrev$Object *self, int i, PyObject *v) { /* XXXX Assign to the i-th element of self */ return 0; Index: Templates/object_tp_call =================================================================== --- Templates/object_tp_call (revision 58978) +++ Templates/object_tp_call (working copy) @@ -1,6 +1,6 @@ static PyObject * -$abbrev$_call($abbrev$object *self, PyObject *args, PyObject *kwargs) +$abbrev$_call($abbrev$Object *self, PyObject *args, PyObject *kwargs) { /* XXXX Return the result of calling self with argument args */ } Index: Templates/object_tp_clear =================================================================== --- Templates/object_tp_clear (revision 0) +++ Templates/object_tp_clear (revision 0) @@ -0,0 +1,6 @@ + +static int +$abbrev$_clear($abbrev$Object *self) +{ + /* XXXX Add your own cleanup code here */ +} Index: Templates/object_tp_compare =================================================================== --- Templates/object_tp_compare (revision 58978) +++ Templates/object_tp_compare (working copy) @@ -1,6 +1,6 @@ static int -$abbrev$_compare($abbrev$object *v, $abbrev$object *w) +$abbrev$_compare($abbrev$Object *v, $abbrev$Object *w) { /* XXXX Compare objects and return -1, 0 or 1 */ } Index: Templates/object_tp_dealloc =================================================================== --- Templates/object_tp_dealloc (revision 58978) +++ Templates/object_tp_dealloc (working copy) @@ -1,7 +1,9 @@ static void -$abbrev$_dealloc($abbrev$object *self) +$abbrev$_dealloc($abbrev$Object *self) { + $abbrev$_clear(self); + /* XXXX Add your own cleanup code here */ - PyMem_DEL(self); + PyObject_DEL(self); } Index: Templates/object_tp_getattr =================================================================== --- Templates/object_tp_getattr (revision 58978) +++ Templates/object_tp_getattr (working copy) @@ -1,7 +1,8 @@ static PyObject * -$abbrev$_getattr($abbrev$object *self, char *name) +$abbrev$_getattr($abbrev$Object *self, char *name) { /* XXXX Add your own getattr code here */ - return Py_FindMethod($abbrev$_methods, (PyObject *)self, name); + + return PyObject_GetAttrString( self, name ); } Index: Templates/object_tp_getattro =================================================================== --- Templates/object_tp_getattro (revision 0) +++ Templates/object_tp_getattro (revision 0) @@ -0,0 +1,8 @@ + +static PyObject * +$abbrev$_getattro($abbrev$Object *self, PyObject *name) +{ + /* XXXX Add your own getattro code here */ + + return PyObject_GenericGetAttr((PyObject *)self, name); +} Index: Templates/object_tp_hash =================================================================== --- Templates/object_tp_hash (revision 58978) +++ Templates/object_tp_hash (working copy) @@ -1,6 +1,6 @@ static long -$abbrev$_hash($abbrev$object *self) +$abbrev$_hash($abbrev$Object *self) { /* XXXX Return a hash of self (or -1) */ } Index: Templates/object_tp_init =================================================================== --- Templates/object_tp_init (revision 0) +++ Templates/object_tp_init (revision 0) @@ -0,0 +1,12 @@ + +static int +$abbrev$_init($abbrev$Object *self, PyObject *args, PyObject *kwds) +{ + static char *kwlist[] = {NULL}; + + if (! PyArg_ParseTupleAndKeywords(args, kwds, "", kwlist)) + return -1; + + return 0; +} + Index: Templates/object_tp_members =================================================================== --- Templates/object_tp_members (revision 0) +++ Templates/object_tp_members (revision 0) @@ -0,0 +1 @@ + Index: Templates/object_tp_methods =================================================================== --- Templates/object_tp_methods (revision 0) +++ Templates/object_tp_methods (revision 0) @@ -0,0 +1 @@ + Index: Templates/object_tp_new =================================================================== --- Templates/object_tp_new (revision 0) +++ Templates/object_tp_new (revision 0) @@ -0,0 +1,14 @@ + +static PyObject * +$abbrev$_new(PyTypeObject *type, PyObject *args, PyObject *kwds) +{ + $abbrev$Object *self; + + self = PyObject_New( $abbrev$Object, type ); + if (self != NULL) { + /* XXXX Add code here to put self into s */ + } + + return (PyObject *)self; +} + Index: Templates/object_tp_print =================================================================== --- Templates/object_tp_print (revision 58978) +++ Templates/object_tp_print (working copy) @@ -1,6 +1,6 @@ static int -$abbrev$_print($abbrev$object *self, FILE *fp, int flags) +$abbrev$_print($abbrev$Object *self, FILE *fp, int flags) { /* XXXX Add code here to print self to fp */ return 0; Index: Templates/object_tp_repr =================================================================== --- Templates/object_tp_repr (revision 58978) +++ Templates/object_tp_repr (working copy) @@ -1,6 +1,6 @@ static PyObject * -$abbrev$_repr($abbrev$object *self) +$abbrev$_repr($abbrev$Object *self) { PyObject *s; Index: Templates/object_tp_setattr =================================================================== --- Templates/object_tp_setattr (revision 58978) +++ Templates/object_tp_setattr (working copy) @@ -1,9 +1,10 @@ static int -$abbrev$_setattr($abbrev$object *self, char *name, PyObject *v) +$abbrev$_setattr($abbrev$Object *self, char *name, PyObject *v) { /* Set attribute 'name' to value 'v'. v==NULL means delete */ /* XXXX Add your own setattr code here */ - return -1; + + return PyObject_SetAttrString( self, name, v ); } Index: Templates/object_tp_setattro =================================================================== --- Templates/object_tp_setattro (revision 0) +++ Templates/object_tp_setattro (revision 0) @@ -0,0 +1,10 @@ + +static int +$abbrev$_setattro($abbrev$Object *self, PyObject *name, PyObject *v) +{ + /* Set attribute 'name' to value 'v'. v==NULL means delete */ + + /* XXXX Add your own setattro code here */ + + return PyObject_GenericSetAttr((PyObject *)self, name, v); +} Index: Templates/object_tp_str =================================================================== --- Templates/object_tp_str (revision 58978) +++ Templates/object_tp_str (working copy) @@ -1,6 +1,6 @@ static PyObject * -$abbrev$_str($abbrev$object *self) +$abbrev$_str($abbrev$Object *self) { PyObject *s; Index: Templates/object_tp_traverse =================================================================== --- Templates/object_tp_traverse (revision 0) +++ Templates/object_tp_traverse (revision 0) @@ -0,0 +1,7 @@ + +static int +$abbrev$_traverse($abbrev$Object *self) +{ + /* XXXX Add your own cleanup code here */ + return 0; +} Index: Tkextra.py =================================================================== --- Tkextra.py (revision 58978) +++ Tkextra.py (working copy) @@ -27,7 +27,7 @@ msg = Message(top, {'width': '3i', 'text': text, - 'font': '-Adobe-Times-Medium-R-Normal-*-180-*', + 'font': 'Times', Pack: {'side': 'right', 'expand': 1, 'fill': 'both', 'padx': '3m', 'pady': '3m'}}) @@ -104,7 +104,7 @@ msg = Message(top, {'width': '3i', 'text': text, - 'font': '-Adobe-Times-Medium-R-Normal-*-180-*', + 'font': 'Times', Pack: {'side': 'left', 'fill': 'both', 'padx': '3m', 'pady': '3m'}})