diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2002-08-09 09:03:31 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2002-08-09 09:03:31 (GMT) |
commit | a70ab8cd4f6f4475b42cee5419ac6018d1ca7a01 (patch) | |
tree | d1d6451727bb97f7552934cf22151a715c30cd86 /Mac | |
parent | 9536bcbfd866fa230d48211f202634a2606c5c1e (diff) | |
download | cpython-a70ab8cd4f6f4475b42cee5419ac6018d1ca7a01.zip cpython-a70ab8cd4f6f4475b42cee5419ac6018d1ca7a01.tar.gz cpython-a70ab8cd4f6f4475b42cee5419ac6018d1ca7a01.tar.bz2 |
Depracated some non-carbon modules.
Diffstat (limited to 'Mac')
-rw-r--r-- | Mac/Unsupported/Classic/Printingmodule.c | 465 | ||||
-rw-r--r-- | Mac/Unsupported/Classic/README | 2 | ||||
-rw-r--r-- | Mac/Unsupported/Classic/macspeechmodule.c | 546 |
3 files changed, 1013 insertions, 0 deletions
diff --git a/Mac/Unsupported/Classic/Printingmodule.c b/Mac/Unsupported/Classic/Printingmodule.c new file mode 100644 index 0000000..e0c4017 --- /dev/null +++ b/Mac/Unsupported/Classic/Printingmodule.c @@ -0,0 +1,465 @@ +/****************************************************************** +Copyright 1998 by Just van Rossum, Den Haag, The Netherlands. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the name of Just van Rossum not be +used in advertising or publicity pertaining to distribution of the +software without specific, written prior permission. + +JUST VAN ROSSUM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, +INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO +EVENT SHALL JUST VAN ROSSUM BE LIABLE FOR ANY SPECIAL, INDIRECT OR +CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF +USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. + +******************************************************************/ + +#include "Python.h" +#include "macglue.h" +#include "pymactoolbox.h" +#include <Printing.h> + +static PyObject *ErrorObject; + +/* ----------------------------------------------------- */ + +static int +TPRect_Convert(PyObject *v, TPRect *r) +{ + if (v == Py_None) { + *r = NULL; + return 1; + } + return PyArg_Parse(v, "(hhhh)", &(*r)->left, &(*r)->top, &(*r)->right, &(*r)->bottom); +} + + +static char Pr_NewTPrintRecord__doc__[] = +"creates a new TPrint handle" +; + +static PyObject * +Pr_NewTPrintRecord(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + Handle hPrint; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + hPrint = NewHandleClear((long) sizeof(TPrint)); + if ( hPrint == NULL ) { + PyErr_NoMemory(); + return NULL; + } + return (PyObject *)ResObj_New(hPrint); +} + +static char Pr_PrPurge__doc__[] = +"PrPurge() -> None" +; + +static PyObject * +Pr_PrPurge(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + + if (!PyArg_ParseTuple(args, "")) + return NULL; + PrPurge(); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrNoPurge__doc__[] = +"PrNoPurge() -> None" +; + +static PyObject * +Pr_PrNoPurge(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + + if (!PyArg_ParseTuple(args, "")) + return NULL; + PrNoPurge(); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrOpen__doc__[] = +"PrOpen() -> None" +; + +static PyObject * +Pr_PrOpen(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + + if (!PyArg_ParseTuple(args, "")) + return NULL; + PrOpen(); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrClose__doc__[] = +"PrClose() -> None" +; + +static PyObject * +Pr_PrClose(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + + if (!PyArg_ParseTuple(args, "")) + return NULL; + PrClose(); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrintDefault__doc__[] = +"PrintDefault(THPrint hPrint) -> None" +; + +static PyObject * +Pr_PrintDefault(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + THPrint hPrint; + + if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) + return NULL; + PrintDefault(hPrint); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrValidate__doc__[] = +"PrValidate(THPrint hPrint) -> None" +; + +static PyObject * +Pr_PrValidate(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + THPrint hPrint; + + if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) + return NULL; + PrValidate(hPrint); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrStlDialog__doc__[] = +"PrStlDialog(THPrint hPrint) -> Boolean" +; + +static PyObject * +Pr_PrStlDialog(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + THPrint hPrint; + Boolean rv; + + if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) + return NULL; + rv = PrStlDialog(hPrint); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + return Py_BuildValue("h", rv); +} + +static char Pr_PrJobDialog__doc__[] = +"PrJobDialog(THPrint hPrint) -> Boolean" +; + +static PyObject * +Pr_PrJobDialog(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + THPrint hPrint; + Boolean rv; + + if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) + return NULL; + rv = PrJobDialog(hPrint); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + return Py_BuildValue("h", rv); +} + +static char Pr_PrJobMerge__doc__[] = +"PrJobMerge(THPrint hPrintSrc, THPrint hPrintDst) -> none" +; + +static PyObject * +Pr_PrJobMerge(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + THPrint hPrintSrc, hPrintDst; + + if (!PyArg_ParseTuple(args, "O&O&", ResObj_Convert, &hPrintSrc, ResObj_Convert, &hPrintDst)) + return NULL; + PrJobMerge(hPrintSrc, hPrintDst); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrOpenDoc__doc__[] = +"PrOpenDoc(THPrint hPrint) -> TPPrPort aTPPort" +; + +static PyObject * +Pr_PrOpenDoc(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + THPrint hPrint; + TPPrPort aTPPort; + + if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) + return NULL; + aTPPort = PrOpenDoc(hPrint, NULL, NULL); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + return Py_BuildValue("O&", GrafObj_New, aTPPort); +} + +static char Pr_PrCloseDoc__doc__[] = +"PrCloseDoc(TPPrPort pPrPort) -> None" +; + +static PyObject * +Pr_PrCloseDoc(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + TPPrPort pPrPort; + + if (!PyArg_ParseTuple(args, "O&", GrafObj_Convert, &pPrPort)) + return NULL; + PrCloseDoc(pPrPort); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrOpenPage__doc__[] = +"PrOpenPage(TPPrPort pPrPort, TPRect pPageFrame) -> None" +; + +static PyObject * +Pr_PrOpenPage(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + TPPrPort pPrPort; + Rect dummyrect = {0, 0, 0, 0}; + TPRect pPageFrame = &dummyrect; + + if (!PyArg_ParseTuple(args, "O&O&", GrafObj_Convert, &pPrPort, TPRect_Convert, &pPageFrame)) + return NULL; + PrOpenPage(pPrPort, pPageFrame); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrClosePage__doc__[] = +"PrClosePage(TPPrPort pPrPort) -> None" +; + +static PyObject * +Pr_PrClosePage(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + TPPrPort pPrPort; + + if (!PyArg_ParseTuple(args, "O&", GrafObj_Convert, &pPrPort)) + return NULL; + PrClosePage(pPrPort); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrPicFile__doc__[] = +"PrPicFile(THPrint hPrint) -> none" +; + +static PyObject * +Pr_PrPicFile(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + THPrint hPrint; + TPrStatus prStatus; + + if (!PyArg_ParseTuple(args, "O&", ResObj_Convert, &hPrint)) + return NULL; + PrPicFile(hPrint, NULL, NULL, NULL, &prStatus); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrGeneral__doc__[] = +"not implemented" +; + +static PyObject * +Pr_PrGeneral(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + + if (!PyArg_ParseTuple(args, "")) + return NULL; + //PrGeneral(); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + Py_INCREF(Py_None); + return Py_None; +} + +static char Pr_PrDrvrVers__doc__[] = +"PrDrvrVers() -> version" +; + +static PyObject * +Pr_PrDrvrVers(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + short rv; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + rv = PrDrvrVers(); + { + OSErr _err = PrError(); + if (_err != noErr) return PyMac_Error(_err); + } + return Py_BuildValue("h", rv); +} + +/* List of methods defined in the module */ + +static struct PyMethodDef Pr_methods[] = { + {"NewTPrintRecord", (PyCFunction)Pr_NewTPrintRecord, METH_VARARGS, Pr_NewTPrintRecord__doc__}, + {"PrPurge", (PyCFunction)Pr_PrPurge, METH_VARARGS, Pr_PrPurge__doc__}, + {"PrNoPurge", (PyCFunction)Pr_PrNoPurge, METH_VARARGS, Pr_PrNoPurge__doc__}, + {"PrOpen", (PyCFunction)Pr_PrOpen, METH_VARARGS, Pr_PrOpen__doc__}, + {"PrClose", (PyCFunction)Pr_PrClose, METH_VARARGS, Pr_PrClose__doc__}, + {"PrintDefault",(PyCFunction)Pr_PrintDefault, METH_VARARGS, Pr_PrintDefault__doc__}, + {"PrValidate", (PyCFunction)Pr_PrValidate, METH_VARARGS, Pr_PrValidate__doc__}, + {"PrStlDialog", (PyCFunction)Pr_PrStlDialog, METH_VARARGS, Pr_PrStlDialog__doc__}, + {"PrJobDialog", (PyCFunction)Pr_PrJobDialog, METH_VARARGS, Pr_PrJobDialog__doc__}, + {"PrJobMerge", (PyCFunction)Pr_PrJobMerge, METH_VARARGS, Pr_PrJobMerge__doc__}, + {"PrOpenDoc", (PyCFunction)Pr_PrOpenDoc, METH_VARARGS, Pr_PrOpenDoc__doc__}, + {"PrCloseDoc", (PyCFunction)Pr_PrCloseDoc, METH_VARARGS, Pr_PrCloseDoc__doc__}, + {"PrOpenPage", (PyCFunction)Pr_PrOpenPage, METH_VARARGS, Pr_PrOpenPage__doc__}, + {"PrClosePage", (PyCFunction)Pr_PrClosePage, METH_VARARGS, Pr_PrClosePage__doc__}, + {"PrPicFile", (PyCFunction)Pr_PrPicFile, METH_VARARGS, Pr_PrPicFile__doc__}, +// {"PrGeneral", (PyCFunction)Pr_PrGeneral, METH_VARARGS, Pr_PrGeneral__doc__}, + {"PrDrvrVers", (PyCFunction)Pr_PrDrvrVers, METH_VARARGS, Pr_PrDrvrVers__doc__}, + + {NULL, (PyCFunction)NULL, 0, NULL} /* sentinel */ +}; + + +/* Initialization function for the module (*must* be called initPrinting) */ + +static char Printing_module_documentation[] = +"" +; + +void initPrinting(); + +void +initPrinting() +{ + PyObject *m, *d; + + /* Create the module and add the functions */ + m = Py_InitModule4("Printing", Pr_methods, + Printing_module_documentation, + (PyObject*)NULL,PYTHON_API_VERSION); + + /* Add some symbolic constants to the module */ + d = PyModule_GetDict(m); + ErrorObject = PyString_FromString("Printing.error"); + PyDict_SetItemString(d, "error", ErrorObject); + + /* XXXX Add constants here */ + +} + diff --git a/Mac/Unsupported/Classic/README b/Mac/Unsupported/Classic/README new file mode 100644 index 0000000..531d9f0 --- /dev/null +++ b/Mac/Unsupported/Classic/README @@ -0,0 +1,2 @@ +These modules no longer work under Carbon. If you are trying to revive +non-carbon builds of MacPython you may want to revive them. diff --git a/Mac/Unsupported/Classic/macspeechmodule.c b/Mac/Unsupported/Classic/macspeechmodule.c new file mode 100644 index 0000000..a8388e9 --- /dev/null +++ b/Mac/Unsupported/Classic/macspeechmodule.c @@ -0,0 +1,546 @@ +/*********************************************************** +Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam, +The Netherlands. + + All Rights Reserved + +Permission to use, copy, modify, and distribute this software and its +documentation for any purpose and without fee is hereby granted, +provided that the above copyright notice appear in all copies and that +both that copyright notice and this permission notice appear in +supporting documentation, and that the names of Stichting Mathematisch +Centrum or CWI not be used in advertising or publicity pertaining to +distribution of the software without specific, written prior permission. + +STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO +THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE +FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT +OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +******************************************************************/ + + +#include "Python.h" +#include "macglue.h" + +#include <Gestalt.h> +#include "Speech.h" + +#ifdef __MWERKS__ +#define OLDP2C 1 +#include <TextUtils.h> +#ifndef c2pstr +#define c2pstr C2PStr +#endif +#ifndef p2cstr +#define p2cstr P2CStr +#endif +#else +#include "pascal.h" +#endif /* __MWERKS__ */ + +#include <CodeFragments.h> +int lib_available; + +/* Somehow the Apple Fix2X and X2Fix don't do what I expect */ +#define fixed2double(x) (((double)(x))/32768.0) +#define double2fixed(x) ((Fixed)((x)*32768.0)) + +char *CurrentSpeech; +PyObject *ms_error_object; +int speech_available; + +static +init_available() { + OSErr err; + long result; + + lib_available = ((ProcPtr)SpeakString != (ProcPtr)0); + err = Gestalt(gestaltSpeechAttr, &result); + if ( err == noErr && (result & (1<<gestaltSpeechMgrPresent))) + return 1; + return 0; +} + +static +check_available() { + if ( !speech_available ) { + PyErr_SetString(ms_error_object, "Speech Mgr not available"); + return 0; + } + if ( !lib_available ) { + PyErr_SetString(ms_error_object, "Speech Mgr available, but shared lib missing"); + return 0; + } + return 1; +} + +/* ------------- +** +** Part one - the speech channel object +*/ +typedef struct { + PyObject_HEAD + SpeechChannel chan; + PyObject *curtext; /* If non-NULL current text being spoken */ +} scobject; + +static PyTypeObject sctype; + +#define is_scobject(v) ((v)->ob_type == &sctype) + +static scobject * +newscobject(arg) + VoiceSpec *arg; +{ + scobject *self; + OSErr err; + + self = PyObject_NEW(scobject, &sctype); + if (self == NULL) + return NULL; + if ( (err=NewSpeechChannel(arg, &self->chan)) != 0) { + Py_DECREF(self); + return (scobject *)PyErr_Mac(ms_error_object, err); + } + self->curtext = NULL; + return self; +} + +/* sc methods */ + +static void +sc_dealloc(self) + scobject *self; +{ + DisposeSpeechChannel(self->chan); + PyObject_DEL(self); +} + +static PyObject * +sc_Stop(self, args) + scobject *self; + PyObject *args; +{ + OSErr err; + + if (!PyArg_NoArgs(args)) + return NULL; + if ((err=StopSpeech(self->chan)) != 0) { + PyErr_Mac(ms_error_object, err); + return NULL; + } + if ( self->curtext ) { + Py_DECREF(self->curtext); + self->curtext = NULL; + } + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +sc_SpeakText(self, args) + scobject *self; + PyObject *args; +{ + OSErr err; + char *str; + int len; + + if (!PyArg_Parse(args, "s#", &str, &len)) + return NULL; + if ( self->curtext ) { + StopSpeech(self->chan); + Py_DECREF(self->curtext); + self->curtext = NULL; + } + if ((err=SpeakText(self->chan, (Ptr)str, (long)len)) != 0) { + PyErr_Mac(ms_error_object, err); + return 0; + } + (void)PyArg_Parse(args, "O", &self->curtext); /* Or should I check this? */ + Py_INCREF(self->curtext); + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +sc_GetRate(self, args) + scobject *self; + PyObject *args; +{ + OSErr err; + Fixed farg; + + if (!PyArg_NoArgs(args)) + return NULL; + if ((err=GetSpeechRate(self->chan, &farg)) != 0) { + PyErr_Mac(ms_error_object, err); + return 0; + } + return PyFloat_FromDouble(fixed2double(farg)); +} + +static PyObject * +sc_GetPitch(self, args) + scobject *self; + PyObject *args; +{ + OSErr err; + Fixed farg; + + if (!PyArg_NoArgs(args)) + return NULL; + if ((err=GetSpeechPitch(self->chan, &farg)) != 0) { + PyErr_Mac(ms_error_object, err); + return 0; + } + return PyFloat_FromDouble(fixed2double(farg)); +} + +static PyObject * +sc_SetRate(self, args) + scobject *self; + PyObject *args; +{ + OSErr err; + double darg; + + if (!PyArg_Parse(args, "d", &darg)) + return NULL; + if ((err=SetSpeechRate(self->chan, double2fixed(darg))) != 0) { + PyErr_Mac(ms_error_object, err); + return 0; + } + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +sc_SetPitch(self, args) + scobject *self; + PyObject *args; +{ + OSErr err; + double darg; + + if (!PyArg_Parse(args, "d", &darg)) + return NULL; + if ((err=SetSpeechPitch(self->chan, double2fixed(darg))) != 0) { + PyErr_Mac(ms_error_object, err); + return NULL; + } + Py_INCREF(Py_None); + return Py_None; +} + +static struct PyMethodDef sc_methods[] = { + {"Stop", (PyCFunction)sc_Stop}, + {"SetRate", (PyCFunction)sc_SetRate}, + {"GetRate", (PyCFunction)sc_GetRate}, + {"SetPitch", (PyCFunction)sc_SetPitch}, + {"GetPitch", (PyCFunction)sc_GetPitch}, + {"SpeakText", (PyCFunction)sc_SpeakText}, + {NULL, NULL} /* sentinel */ +}; + +static PyObject * +sc_getattr(self, name) + scobject *self; + char *name; +{ + return Py_FindMethod(sc_methods, (PyObject *)self, name); +} + +static PyTypeObject sctype = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "macspeech.MacSpeechChannel", /*tp_name*/ + sizeof(scobject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)sc_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc)sc_getattr, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ +}; + +/* ------------- +** +** Part two - the voice object +*/ +typedef struct { + PyObject_HEAD + int initialized; + VoiceSpec vs; + VoiceDescription vd; +} mvobject; + +static PyTypeObject mvtype; + +#define is_mvobject(v) ((v)->ob_type == &mvtype) + +static mvobject * +newmvobject() +{ + mvobject *self; + self = PyObject_NEW(mvobject, &mvtype); + if (self == NULL) + return NULL; + self->initialized = 0; + return self; +} + +static int +initmvobject(self, ind) + mvobject *self; + int ind; +{ + OSErr err; + + if ( (err=GetIndVoice((short)ind, &self->vs)) != 0 ) { + PyErr_Mac(ms_error_object, err); + return 0; + } + if ( (err=GetVoiceDescription(&self->vs, &self->vd, sizeof self->vd)) != 0) { + PyErr_Mac(ms_error_object, err); + return 0; + } + self->initialized = 1; + return 1; +} +/* mv methods */ + +static void +mv_dealloc(self) + mvobject *self; +{ + PyObject_DEL(self); +} + +static PyObject * +mv_getgender(self, args) + mvobject *self; + PyObject *args; +{ + PyObject *rv; + + if (!PyArg_NoArgs(args)) + return NULL; + if (!self->initialized) { + PyErr_SetString(ms_error_object, "Uninitialized voice"); + return NULL; + } + rv = PyInt_FromLong(self->vd.gender); + return rv; +} + +static PyObject * +mv_newchannel(self, args) + mvobject *self; + PyObject *args; +{ + if (!PyArg_NoArgs(args)) + return NULL; + if (!self->initialized) { + PyErr_SetString(ms_error_object, "Uninitialized voice"); + return NULL; + } + return (PyObject *)newscobject(&self->vs); +} + +static struct PyMethodDef mv_methods[] = { + {"GetGender", (PyCFunction)mv_getgender}, + {"NewChannel", (PyCFunction)mv_newchannel}, + {NULL, NULL} /* sentinel */ +}; + +static PyObject * +mv_getattr(self, name) + mvobject *self; + char *name; +{ + return Py_FindMethod(mv_methods, (PyObject *)self, name); +} + +static PyTypeObject mvtype = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "macspeech.MacVoice", /*tp_name*/ + sizeof(mvobject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)mv_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + (getattrfunc)mv_getattr, /*tp_getattr*/ + 0, /*tp_setattr*/ + 0, /*tp_compare*/ + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ +}; + + +/* ------------- +** +** Part three - The module interface +*/ + +/* See if Speech manager available */ + +static PyObject * +ms_Available(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + + if (!PyArg_NoArgs(args)) + return NULL; + return PyInt_FromLong(speech_available); +} + +/* Count number of busy speeches */ + +static PyObject * +ms_Busy(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + short result; + + if (!PyArg_NoArgs(args)) + return NULL; + if ( !check_available() ) + return NULL; + result = SpeechBusy(); + return PyInt_FromLong(result); +} + +/* Say something */ + +static PyObject * +ms_SpeakString(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + OSErr err; + char *str; + int len; + + if (!PyArg_Parse(args, "s", &str)) + return NULL; + if ( !check_available()) + return NULL; + if (CurrentSpeech) { + /* Free the old speech, after killing it off + ** (note that speach is async and c2pstr works inplace) + */ + SpeakString("\p"); + free(CurrentSpeech); + } + len = strlen(str); + CurrentSpeech = malloc(len+1); + strcpy(CurrentSpeech, str); + err = SpeakString(c2pstr(CurrentSpeech)); + if ( err ) { + PyErr_Mac(ms_error_object, err); + return NULL; + } + Py_INCREF(Py_None); + return Py_None; +} + + +/* Count number of available voices */ + +static PyObject * +ms_CountVoices(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + short result; + + if (!PyArg_NoArgs(args)) + return NULL; + if ( !check_available()) + return NULL; + CountVoices(&result); + return PyInt_FromLong(result); +} + +static PyObject * +ms_GetIndVoice(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + mvobject *rv; + long ind; + + if( !PyArg_Parse(args, "i", &ind)) + return NULL; + if ( !check_available() ) + return NULL; + rv = newmvobject(); + if ( !initmvobject(rv, ind) ) { + Py_DECREF(rv); + return NULL; + } + return (PyObject *)rv; +} + + +static PyObject * +ms_Version(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + NumVersion v; + + if (!PyArg_NoArgs(args)) + return NULL; + if ( !check_available()) + return NULL; + v = SpeechManagerVersion(); + return PyInt_FromLong(*(int *)&v); +} + + +/* List of functions defined in the module */ + +static struct PyMethodDef ms_methods[] = { + {"Available", ms_Available}, + {"CountVoices", ms_CountVoices}, + {"Busy", ms_Busy}, + {"SpeakString", ms_SpeakString}, + {"GetIndVoice", ms_GetIndVoice}, + {"Version", ms_Version}, + {NULL, NULL} /* sentinel */ +}; + +/* Initialization function for the module (*must* be called initmacspeech) */ + +void +initmacspeech() +{ + PyObject *m, *d; + + speech_available = init_available(); + /* Create the module and add the functions */ + m = Py_InitModule("macspeech", ms_methods); + + /* Add some symbolic constants to the module */ + d = PyModule_GetDict(m); + ms_error_object = PyErr_NewException("macspeech.error", NULL, NULL); + PyDict_SetItemString(d, "error", ms_error_object); +} |