From cf27c2d5417b55fa71c2b1a76afde16185e80ac5 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 25 Jan 1995 23:06:44 +0000 Subject: Some layout changes; added EventRecord Get/Build functions (as a tuple). --- Mac/Include/macglue.h | 32 ++++++++++----- Mac/Python/macglue.c | 107 ++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 119 insertions(+), 20 deletions(-) diff --git a/Mac/Include/macglue.h b/Mac/Include/macglue.h index e2ec8cd..730fc2a 100644 --- a/Mac/Include/macglue.h +++ b/Mac/Include/macglue.h @@ -24,18 +24,32 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include -char *macstrerror Py_PROTO((int)); /* strerror with mac errors */ +char *macstrerror(int); /* strerror with mac errors */ -PyObject *PyErr_Mac Py_PROTO((PyObject *, int)); /* Exception with a mac error */ +extern PyObject *PyMac_OSErrException; /* Exception for OSErr */ +PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */ -int PyMac_Idle Py_PROTO((void)); /* Idle routine */ +PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */ +PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */ -int PyMac_GetOSType Py_PROTO((PyObject *, OSType *)); /* argument parser for OSType */ -PyObject *PyMac_BuildOSType Py_PROTO((OSType)); /* Convert OSType to PyObject */ +int PyMac_Idle(void); /* Idle routine */ -int PyMac_GetStr255 Py_PROTO((PyObject *, Str255)); /* argument parser for Str255 */ -PyObject *PyMac_BuildStr255 Py_PROTO((Str255)); /* Convert Str255 to PyObject */ +int PyMac_GetOSType(PyObject *, OSType *); /* argument parser for OSType */ +PyObject *PyMac_BuildOSType(OSType); /* Convert OSType to PyObject */ -int PyMac_GetFSSpec Py_PROTO((PyObject *, FSSpec *)); /* argument parser for FSSpec */ -PyObject *PyMac_BuildFSSpec Py_PROTO((FSSpec *)); /* Convert FSSpec to PyObject */ +int PyMac_GetStr255(PyObject *, Str255); /* argument parser for Str255 */ +PyObject *PyMac_BuildStr255(Str255); /* Convert Str255 to PyObject */ + +int PyMac_GetFSSpec(PyObject *, FSSpec *); /* argument parser for FSSpec */ +PyObject *PyMac_BuildFSSpec(FSSpec *); /* Convert FSSpec to PyObject */ + +int PyMac_GetRect(PyObject *, Rect *); /* argument parser for Rect */ +PyObject *PyMac_BuildRect(Rect *); /* Convert Rect to PyObject */ + +int PyMac_GetPoint(PyObject *, Point *); /* argument parser for Point */ +PyObject *PyMac_BuildPoint(Point); /* Convert Point to PyObject */ + +int PyMac_GetEventRecord(PyObject *, EventRecord *); /* argument parser for EventRecord */ +PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to PyObject */ diff --git a/Mac/Python/macglue.c b/Mac/Python/macglue.c index f350f97..f70ca60 100644 --- a/Mac/Python/macglue.c +++ b/Mac/Python/macglue.c @@ -71,6 +71,18 @@ char *macstrerror(int err) return buf; } +/* Exception object shared by all Mac specific modules for Mac OS errors */ +PyObject *PyMac_OSErrException; + +/* Initialize and return PyMac_OSErrException */ +PyObject * +PyMac_GetOSErrException() +{ + if (PyMac_OSErrException == NULL) + PyMac_OSErrException = PyString_FromString("Mac OS Error"); + return PyMac_OSErrException; +} + /* Set a MAC-specific error from errno, and return NULL; return None if no error */ PyObject * PyErr_Mac(PyObject *eobj, int err) @@ -91,6 +103,13 @@ PyErr_Mac(PyObject *eobj, int err) return NULL; } +/* Call PyErr_Mac with PyMac_OSErrException */ +PyObject * +PyMac_Error(OSErr err) +{ + return PyErr_Mac(PyMac_GetOSErrException(), err); +} + /* ** Idle routine for busy-wait loops. ** This is rather tricky: if we see an event we check whether it is @@ -117,9 +136,9 @@ PyMac_Idle() } -/* Convert a ResType argument */ +/* Convert a 4-char string object argument to an OSType value */ int -PyMac_GetOSType(PyObject *v, ResType *pr) +PyMac_GetOSType(PyObject *v, OSType *pr) { if (!PyString_Check(v) || PyString_Size(v) != 4) { PyErr_SetString(PyExc_TypeError, @@ -130,7 +149,15 @@ PyMac_GetOSType(PyObject *v, ResType *pr) return 1; } -/* Convert a Python string to a Str255 */ +/* Convert an OSType value to a 4-char string object */ +PyObject * +PyMac_BuildOSType(OSType t) +{ + return PyString_FromStringAndSize((char *)&t, 4); +} + + +/* Convert a Python string object to a Str255 */ int PyMac_GetStr255(PyObject *v, Str255 pbuf) { @@ -145,8 +172,18 @@ PyMac_GetStr255(PyObject *v, Str255 pbuf) return 1; } +/* Convert a Str255 to a Python string object */ +PyObject * +PyMac_BuildStr255(Str255 s) +{ + return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); +} + + /* -** Convert anything resembling an FSSpec argument +** Convert a Python object to an FSSpec. +** The object may either be a full pathname or a triple +** (vrefnum, dirid, path). ** NOTE: This routine will fail on pre-sys7 machines. ** The caller is responsible for not calling this routine ** in those cases (which is fine, since everyone calling @@ -180,23 +217,71 @@ PyMac_GetFSSpec(PyObject *v, FSSpec *fs) return 1; } -/* Return a Python object that describes an FSSpec */ +/* Convert an FSSpec to a Python object -- a triple (vrefnum, dirid, path) */ PyObject * PyMac_BuildFSSpec(FSSpec *fs) { return Py_BuildValue("(iis#)", fs->vRefNum, fs->parID, &fs->name[1], fs->name[0]); } -/* Convert an OSType value to a 4-char string object */ + +/* Convert a Python object to a Rect. + The object must be a (top, left, bottom, right) tuple. + (Unfortunately this is different from STDWIN's convention). */ +int +PyMac_GetRect(PyObject *v, Rect *r) +{ + return PyArg_Parse(v, "(hhhh)", &r->top, &r->left, &r->bottom, &r->right); +} + +/* Convert a Rect to a Python object */ PyObject * -PyMac_BuildOSType(OSType t) +PyMac_BuildRect(Rect *r) { - return PyString_FromStringAndSize((char *)&t, 4); + return Py_BuildValue("(hhhh)", r->top, r->left, r->bottom, r->right); +} + + +/* Convert a Python object to a Point. + The object must be a (v, h) tuple. + (Unfortunately this is different from STDWIN's convention). */ +int +PyMac_GetPoint(PyObject *v, Point *p) +{ + return PyArg_Parse(v, "(hh)", &p->v, &p->h); } -/* Convert a Str255 to a Python string */ +/* Convert a Point to a Python object */ PyObject * -PyMac_BuildStr255(Str255 s) +PyMac_BuildPoint(Point p) { - return PyString_FromStringAndSize((char *)&s[1], (int)s[0]); + return Py_BuildValue("(hh)", p.v, p.h); +} + + +/* Convert a Python object to an EventRecord. + The object must be a (what, message, when, (v, h), modifiers) tuple. */ +int +PyMac_GetEventRecord(PyObject *v, EventRecord *e) +{ + return PyArg_Parse(v, "(hll(hh)h)", + &e->what, + &e->message, + &e->when, + &e->where.v, + &e->where.h, + &e->modifiers); +} + +/* Convert a Rect to an EventRecord object */ +PyObject * +PyMac_BuildEventRecord(EventRecord *e) +{ + return Py_BuildValue("(hll(hh)h)", + e->what, + e->message, + e->when, + e->where.v, + e->where.h, + e->modifiers); } -- cgit v0.12