Converted the Carbon modules to use PEP252-style objects, with

descriptors in stead of manual getattr hooks to get at attributes
of the objects.

For Qd I have in stead gotten rid of most of the attribute access
in favor of the carbon-style accessor methods (with the exception
of visRgn, to be done later), and of the Carbon.Qd.qd global object,
for which accessor functions are also available.

For List I have fixed the fact that various methods were incorrectly
generated as functions.

CF is untouched: PEP252 doesn't allow "poor-mans-inheritance" with
basechain, so it will have to wait for PEP253 support.
This commit is contained in:
Jack Jansen 2002-11-29 23:40:48 +00:00
parent 818855939a
commit dbd5701d73
48 changed files with 2447 additions and 2507 deletions

View file

@ -211,7 +211,7 @@ SPB_interrupt(SPBPtr my_spb)
# create the module and object definition and link them
class SndObjectDefinition(ObjectDefinition):
class SndObjectDefinition(PEP252Mixin, ObjectDefinition):
def outputStructMembers(self):
ObjectDefinition.outputStructMembers(self)
@ -237,7 +237,37 @@ class SndObjectDefinition(ObjectDefinition):
#
class SpbObjectDefinition(ObjectDefinition):
class SpbObjectDefinition(PEP252Mixin, ObjectDefinition):
getsetlist = [
(
'inRefNum',
'return Py_BuildValue("l", self->ob_spb.inRefNum);',
'return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);',
None,
), (
'count',
'return Py_BuildValue("l", self->ob_spb.count);',
'return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);',
None
), (
'milliseconds',
'return Py_BuildValue("l", self->ob_spb.milliseconds);',
'return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);',
None,
), (
'error',
'return Py_BuildValue("h", self->ob_spb.error);',
None,
None
), (
'completionRoutine',
None,
"""self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
self->ob_completion = v;
Py_INCREF(v);
return 0;""",
None,
)]
def outputStructMembers(self):
Output("/* Members used to implement callbacks: */")
@ -286,54 +316,6 @@ class SpbObjectDefinition(ObjectDefinition):
Output("*p_itself = &((%s *)v)->ob_spb;", self.objecttype)
Output("return 1;")
OutRbrace()
def outputSetattr(self):
Output()
Output("static int %s_setattr(%s *self, char *name, PyObject *value)",
self.prefix, self.objecttype)
OutLbrace()
self.outputSetattrBody()
OutRbrace()
def outputSetattrBody(self):
Output("""
int rv = 0;
if (strcmp(name, "inRefNum") == 0)
rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
else if (strcmp(name, "count") == 0)
rv = PyArg_Parse(value, "l", &self->ob_spb.count);
else if (strcmp(name, "milliseconds") == 0)
rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
else if (strcmp(name, "buffer") == 0)
rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
else if (strcmp(name, "completionRoutine") == 0) {
self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
self->ob_completion = value;
Py_INCREF(value);
rv = 1;
#if !TARGET_API_MAC_CARBON
} else if (strcmp(name, "interruptRoutine") == 0) {
self->ob_spb.completionRoutine = NewSIInterruptUPP(SPB_interrupt);
self->ob_interrupt = value;
Py_INCREF(value);
rv = 1;
#endif
}
if ( rv ) return 0;
else return -1;""")
def outputGetattrHook(self):
Output("""
if (strcmp(name, "inRefNum") == 0)
return Py_BuildValue("l", self->ob_spb.inRefNum);
else if (strcmp(name, "count") == 0)
return Py_BuildValue("l", self->ob_spb.count);
else if (strcmp(name, "milliseconds") == 0)
return Py_BuildValue("l", self->ob_spb.milliseconds);
else if (strcmp(name, "error") == 0)
return Py_BuildValue("h", self->ob_spb.error);""")
sndobject = SndObjectDefinition('SndChannel', 'SndCh', 'SndChannelPtr')