1994-09-16 12:54:21 +02:00
|
|
|
/***********************************************************
|
1995-01-08 15:33:34 +01:00
|
|
|
Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
|
|
|
|
The Netherlands.
|
1994-09-16 12:54:21 +02:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
******************************************************************/
|
|
|
|
|
|
|
|
/* Macintosh OS-specific interface */
|
|
|
|
|
|
|
|
#include "Python.h"
|
1994-12-14 15:02:24 +01:00
|
|
|
#include "macglue.h"
|
1994-09-16 12:54:21 +02:00
|
|
|
|
1995-01-27 15:43:25 +01:00
|
|
|
#include <Windows.h>
|
|
|
|
|
1994-09-16 12:54:21 +02:00
|
|
|
static PyObject *MacOS_Error; /* Exception MacOS.Error */
|
|
|
|
|
1995-02-21 22:01:05 +01:00
|
|
|
#ifdef MPW
|
1995-02-18 16:02:02 +01:00
|
|
|
#define bufferIsSmall -607 /*error returns from Post and Accept */
|
|
|
|
#endif
|
|
|
|
|
1994-09-16 12:54:21 +02:00
|
|
|
|
1995-01-09 14:20:04 +01:00
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
/* Miscellaneous File System Operations */
|
|
|
|
|
|
|
|
static PyObject *
|
1995-01-22 19:42:12 +01:00
|
|
|
MacOS_GetCreatorAndType(PyObject *self, PyObject *args)
|
1995-01-09 14:20:04 +01:00
|
|
|
{
|
|
|
|
Str255 name;
|
|
|
|
FInfo info;
|
1995-01-22 19:42:12 +01:00
|
|
|
PyObject *creator, *type, *res;
|
1995-01-09 14:20:04 +01:00
|
|
|
OSErr err;
|
|
|
|
|
1995-01-21 14:46:04 +01:00
|
|
|
if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, &name))
|
1995-01-09 14:20:04 +01:00
|
|
|
return NULL;
|
1995-01-22 19:42:12 +01:00
|
|
|
if ((err = GetFInfo(name, 0, &info)) != noErr)
|
|
|
|
return PyErr_Mac(MacOS_Error, err);
|
1995-01-09 14:20:04 +01:00
|
|
|
creator = PyString_FromStringAndSize((char *)&info.fdCreator, 4);
|
1995-01-22 19:42:12 +01:00
|
|
|
type = PyString_FromStringAndSize((char *)&info.fdType, 4);
|
|
|
|
res = Py_BuildValue("OO", creator, type);
|
1995-01-12 13:37:24 +01:00
|
|
|
Py_DECREF(creator);
|
1995-01-22 19:42:12 +01:00
|
|
|
Py_DECREF(type);
|
1995-01-09 14:20:04 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
1995-01-22 19:42:12 +01:00
|
|
|
MacOS_SetCreatorAndType(PyObject *self, PyObject *args)
|
1995-01-09 14:20:04 +01:00
|
|
|
{
|
|
|
|
Str255 name;
|
1995-01-22 19:42:12 +01:00
|
|
|
ResType creator, type;
|
1995-01-09 14:20:04 +01:00
|
|
|
FInfo info;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "O&O&O&",
|
1995-01-22 19:42:12 +01:00
|
|
|
PyMac_GetStr255, &name, PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
|
1995-01-09 14:20:04 +01:00
|
|
|
return NULL;
|
1995-01-22 19:42:12 +01:00
|
|
|
if ((err = GetFInfo(name, 0, &info)) != noErr)
|
|
|
|
return PyErr_Mac(MacOS_Error, err);
|
1995-01-09 14:20:04 +01:00
|
|
|
info.fdCreator = creator;
|
1995-01-22 19:42:12 +01:00
|
|
|
info.fdType = type;
|
|
|
|
if ((err = SetFInfo(name, 0, &info)) != noErr)
|
|
|
|
return PyErr_Mac(MacOS_Error, err);
|
1995-01-09 14:20:04 +01:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
1995-01-19 00:58:07 +01:00
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
/* STDWIN High Level Event interface */
|
|
|
|
|
|
|
|
#include <EPPC.h>
|
|
|
|
#include <Events.h>
|
|
|
|
|
|
|
|
#ifdef USE_STDWIN
|
|
|
|
|
|
|
|
extern void (*_w_high_level_event_proc)(EventRecord *);
|
|
|
|
|
|
|
|
static PyObject *MacOS_HighLevelEventHandler = NULL;
|
|
|
|
|
|
|
|
static void
|
1995-01-26 00:09:20 +01:00
|
|
|
MacOS_HighLevelEventProc(EventRecord *e)
|
1995-01-19 00:58:07 +01:00
|
|
|
{
|
|
|
|
if (MacOS_HighLevelEventHandler != NULL) {
|
1995-01-26 00:09:20 +01:00
|
|
|
PyObject *args = PyMac_BuildEventRecord(e);
|
1995-01-19 00:58:07 +01:00
|
|
|
PyObject *res;
|
|
|
|
if (args == NULL)
|
|
|
|
res = NULL;
|
|
|
|
else {
|
|
|
|
res = PyEval_CallObject(MacOS_HighLevelEventHandler, args);
|
|
|
|
Py_DECREF(args);
|
|
|
|
}
|
|
|
|
if (res == NULL) {
|
|
|
|
fprintf(stderr, "Exception in MacOS_HighLevelEventProc:\n");
|
|
|
|
PyErr_Print();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Py_DECREF(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-01-26 17:36:45 +01:00
|
|
|
/* XXXX Need to come here from PyMac_DoYield too... */
|
|
|
|
|
1995-01-19 00:58:07 +01:00
|
|
|
static PyObject *
|
|
|
|
MacOS_SetHighLevelEventHandler(self, args)
|
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
|
|
|
{
|
|
|
|
PyObject *previous = MacOS_HighLevelEventHandler;
|
|
|
|
PyObject *next = NULL;
|
|
|
|
if (!PyArg_ParseTuple(args, "|O", &next))
|
|
|
|
return NULL;
|
|
|
|
if (next == Py_None)
|
|
|
|
next = NULL;
|
|
|
|
Py_INCREF(next);
|
|
|
|
MacOS_HighLevelEventHandler = next;
|
|
|
|
if (next == NULL)
|
|
|
|
_w_high_level_event_proc = NULL;
|
|
|
|
else
|
|
|
|
_w_high_level_event_proc = MacOS_HighLevelEventProc;
|
|
|
|
if (previous == NULL) {
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
previous = Py_None;
|
|
|
|
}
|
|
|
|
return previous;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_STDWIN */
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
MacOS_AcceptHighLevelEvent(self, args)
|
|
|
|
PyObject *self;
|
|
|
|
PyObject *args;
|
|
|
|
{
|
|
|
|
TargetID sender;
|
|
|
|
unsigned long refcon;
|
|
|
|
Ptr buf;
|
|
|
|
unsigned long len;
|
|
|
|
OSErr err;
|
|
|
|
PyObject *res;
|
|
|
|
|
|
|
|
buf = NULL;
|
|
|
|
len = 0;
|
|
|
|
err = AcceptHighLevelEvent(&sender, &refcon, buf, &len);
|
|
|
|
if (err == bufferIsSmall) {
|
|
|
|
buf = malloc(len);
|
|
|
|
if (buf == NULL)
|
|
|
|
return PyErr_NoMemory();
|
|
|
|
err = AcceptHighLevelEvent(&sender, &refcon, buf, &len);
|
|
|
|
if (err != noErr) {
|
|
|
|
free(buf);
|
|
|
|
return PyErr_Mac(MacOS_Error, (int)err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (err != noErr)
|
|
|
|
return PyErr_Mac(MacOS_Error, (int)err);
|
|
|
|
res = Py_BuildValue("s#ls#",
|
|
|
|
(char *)&sender, (int)(sizeof sender), refcon, (char *)buf, (int)len);
|
|
|
|
free(buf);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1995-01-26 17:36:45 +01:00
|
|
|
/*
|
|
|
|
** Set poll frequency and cpu-yield-time
|
|
|
|
*/
|
|
|
|
static PyObject *
|
|
|
|
MacOS_SetScheduleTimes(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
long fgi, fgy, bgi, bgy;
|
|
|
|
|
|
|
|
bgi = bgy = -2;
|
|
|
|
if (!PyArg_ParseTuple(args, "ll|ll", &fgi, &fgy, &bgi, &bgy))
|
|
|
|
return NULL;
|
1995-02-20 16:46:10 +01:00
|
|
|
if ( bgi == -2 || bgy == -2 ) {
|
1995-01-26 17:36:45 +01:00
|
|
|
bgi = fgi;
|
|
|
|
bgy = fgy;
|
|
|
|
}
|
|
|
|
PyMac_SetYield(fgi, fgy, bgi, bgy);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
1995-01-27 15:43:25 +01:00
|
|
|
static PyObject *
|
|
|
|
MacOS_EnableAppswitch(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
int enable;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "i", &enable))
|
|
|
|
return NULL;
|
|
|
|
PyMac_DoYieldEnabled = enable;
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
1995-02-02 15:25:56 +01:00
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
MacOS_HandleEvent(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
EventRecord ev;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "O&", PyMac_GetEventRecord, &ev))
|
|
|
|
return NULL;
|
|
|
|
PyMac_HandleEvent(&ev);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
1994-09-16 12:54:21 +02:00
|
|
|
static PyMethodDef MacOS_Methods[] = {
|
1995-01-19 00:58:07 +01:00
|
|
|
{"AcceptHighLevelEvent", MacOS_AcceptHighLevelEvent, 1},
|
1995-01-22 19:42:12 +01:00
|
|
|
{"GetCreatorAndType", MacOS_GetCreatorAndType, 1},
|
|
|
|
{"SetCreatorAndType", MacOS_SetCreatorAndType, 1},
|
1995-01-19 00:58:07 +01:00
|
|
|
#ifdef USE_STDWIN
|
|
|
|
{"SetHighLevelEventHandler", MacOS_SetHighLevelEventHandler, 1},
|
|
|
|
#endif
|
1995-01-26 17:36:45 +01:00
|
|
|
{"SetScheduleTimes", MacOS_SetScheduleTimes, 1},
|
1995-01-27 15:43:25 +01:00
|
|
|
{"EnableAppswitch", MacOS_EnableAppswitch, 1},
|
1995-02-02 15:25:56 +01:00
|
|
|
{"HandleEvent", MacOS_HandleEvent, 1},
|
1995-01-19 00:58:07 +01:00
|
|
|
{NULL, NULL} /* Sentinel */
|
1994-09-16 12:54:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MacOS_Init()
|
|
|
|
{
|
|
|
|
PyObject *m, *d;
|
|
|
|
|
|
|
|
m = Py_InitModule("MacOS", MacOS_Methods);
|
|
|
|
d = PyModule_GetDict(m);
|
|
|
|
|
|
|
|
/* Initialize MacOS.Error exception */
|
1995-01-26 00:09:20 +01:00
|
|
|
MacOS_Error = PyMac_GetOSErrException();
|
1994-09-29 11:02:56 +01:00
|
|
|
if (MacOS_Error == NULL || PyDict_SetItemString(d, "Error", MacOS_Error) != 0)
|
1994-09-16 12:54:21 +02:00
|
|
|
Py_FatalError("can't define MacOS.Error");
|
|
|
|
}
|