1994-09-16 07:54:21 -03:00
|
|
|
/***********************************************************
|
1997-01-31 12:15:11 -04:00
|
|
|
Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
|
1995-01-08 10:33:34 -04:00
|
|
|
The Netherlands.
|
1994-09-16 07:54:21 -03: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 10:02:24 -04:00
|
|
|
#include "macglue.h"
|
1994-09-16 07:54:21 -03:00
|
|
|
|
1995-01-27 10:43:25 -04:00
|
|
|
#include <Windows.h>
|
1996-02-29 12:11:32 -04:00
|
|
|
#include <Files.h>
|
1996-09-30 11:43:22 -03:00
|
|
|
#include <LowMem.h>
|
1995-01-27 10:43:25 -04:00
|
|
|
|
1994-09-16 07:54:21 -03:00
|
|
|
static PyObject *MacOS_Error; /* Exception MacOS.Error */
|
|
|
|
|
1995-02-21 17:01:05 -04:00
|
|
|
#ifdef MPW
|
1995-02-18 11:02:02 -04:00
|
|
|
#define bufferIsSmall -607 /*error returns from Post and Accept */
|
|
|
|
#endif
|
|
|
|
|
1996-02-29 12:11:32 -04:00
|
|
|
static PyObject *ErrorObject;
|
|
|
|
|
|
|
|
/* ----------------------------------------------------- */
|
|
|
|
|
|
|
|
/* Declarations for objects of type Resource fork */
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
PyObject_HEAD
|
|
|
|
short fRefNum;
|
|
|
|
int isclosed;
|
|
|
|
} rfobject;
|
|
|
|
|
|
|
|
staticforward PyTypeObject Rftype;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
do_close(self)
|
|
|
|
rfobject *self;
|
|
|
|
{
|
|
|
|
if (self->isclosed ) return;
|
|
|
|
(void)FSClose(self->fRefNum);
|
|
|
|
self->isclosed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static char rf_read__doc__[] =
|
|
|
|
"Read data from resource fork"
|
|
|
|
;
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
rf_read(self, args)
|
|
|
|
rfobject *self;
|
|
|
|
PyObject *args;
|
|
|
|
{
|
|
|
|
long n;
|
|
|
|
PyObject *v;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
if (self->isclosed) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Operation on closed file");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "l", &n))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
v = PyString_FromStringAndSize((char *)NULL, n);
|
|
|
|
if (v == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
err = FSRead(self->fRefNum, &n, PyString_AsString(v));
|
|
|
|
if (err && err != eofErr) {
|
|
|
|
PyMac_Error(err);
|
|
|
|
Py_DECREF(v);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
_PyString_Resize(&v, n);
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char rf_write__doc__[] =
|
|
|
|
"Write to resource fork"
|
|
|
|
;
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
rf_write(self, args)
|
|
|
|
rfobject *self;
|
|
|
|
PyObject *args;
|
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
long size;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
if (self->isclosed) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Operation on closed file");
|
|
|
|
return NULL;
|
|
|
|
}
|
1997-02-24 09:56:59 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "m#", &buffer, &size))
|
1996-02-29 12:11:32 -04:00
|
|
|
return NULL;
|
|
|
|
err = FSWrite(self->fRefNum, &size, buffer);
|
|
|
|
if (err) {
|
|
|
|
PyMac_Error(err);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char rf_seek__doc__[] =
|
|
|
|
"Set file position"
|
|
|
|
;
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
rf_seek(self, args)
|
|
|
|
rfobject *self;
|
|
|
|
PyObject *args;
|
|
|
|
{
|
|
|
|
long amount, pos;
|
|
|
|
int whence = SEEK_SET;
|
|
|
|
long eof;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
if (self->isclosed) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Operation on closed file");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!PyArg_ParseTuple(args, "l|i", &amount, &whence))
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if ( err = GetEOF(self->fRefNum, &eof))
|
|
|
|
goto ioerr;
|
|
|
|
|
|
|
|
switch (whence) {
|
|
|
|
case SEEK_CUR:
|
|
|
|
if (err = GetFPos(self->fRefNum, &pos))
|
|
|
|
goto ioerr;
|
|
|
|
break;
|
|
|
|
case SEEK_END:
|
|
|
|
pos = eof;
|
|
|
|
break;
|
|
|
|
case SEEK_SET:
|
|
|
|
pos = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
PyErr_BadArgument();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos += amount;
|
|
|
|
|
|
|
|
/* Don't bother implementing seek past EOF */
|
|
|
|
if (pos > eof || pos < 0) {
|
|
|
|
PyErr_BadArgument();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( err = SetFPos(self->fRefNum, fsFromStart, pos) ) {
|
|
|
|
ioerr:
|
|
|
|
PyMac_Error(err);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static char rf_tell__doc__[] =
|
|
|
|
"Get file position"
|
|
|
|
;
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
rf_tell(self, args)
|
|
|
|
rfobject *self;
|
|
|
|
PyObject *args;
|
|
|
|
{
|
|
|
|
long where;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
if (self->isclosed) {
|
|
|
|
PyErr_SetString(PyExc_ValueError, "Operation on closed file");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!PyArg_ParseTuple(args, ""))
|
|
|
|
return NULL;
|
|
|
|
if ( err = GetFPos(self->fRefNum, &where) ) {
|
|
|
|
PyMac_Error(err);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
return PyInt_FromLong(where);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char rf_close__doc__[] =
|
|
|
|
"Close resource fork"
|
|
|
|
;
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
rf_close(self, args)
|
|
|
|
rfobject *self;
|
|
|
|
PyObject *args;
|
|
|
|
{
|
|
|
|
if (!PyArg_ParseTuple(args, ""))
|
|
|
|
return NULL;
|
|
|
|
do_close(self);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static struct PyMethodDef rf_methods[] = {
|
|
|
|
{"read", rf_read, 1, rf_read__doc__},
|
|
|
|
{"write", rf_write, 1, rf_write__doc__},
|
|
|
|
{"seek", rf_seek, 1, rf_seek__doc__},
|
|
|
|
{"tell", rf_tell, 1, rf_tell__doc__},
|
|
|
|
{"close", rf_close, 1, rf_close__doc__},
|
|
|
|
|
|
|
|
{NULL, NULL} /* sentinel */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ---------- */
|
|
|
|
|
|
|
|
|
|
|
|
static rfobject *
|
|
|
|
newrfobject()
|
|
|
|
{
|
|
|
|
rfobject *self;
|
|
|
|
|
|
|
|
self = PyObject_NEW(rfobject, &Rftype);
|
|
|
|
if (self == NULL)
|
|
|
|
return NULL;
|
|
|
|
self->isclosed = 1;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
rf_dealloc(self)
|
|
|
|
rfobject *self;
|
|
|
|
{
|
|
|
|
do_close(self);
|
|
|
|
PyMem_DEL(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
rf_getattr(self, name)
|
|
|
|
rfobject *self;
|
|
|
|
char *name;
|
|
|
|
{
|
|
|
|
return Py_FindMethod(rf_methods, (PyObject *)self, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char Rftype__doc__[] =
|
|
|
|
"Resource fork file object"
|
|
|
|
;
|
|
|
|
|
|
|
|
static PyTypeObject Rftype = {
|
|
|
|
PyObject_HEAD_INIT(&PyType_Type)
|
|
|
|
0, /*ob_size*/
|
|
|
|
"Resource fork", /*tp_name*/
|
|
|
|
sizeof(rfobject), /*tp_basicsize*/
|
|
|
|
0, /*tp_itemsize*/
|
|
|
|
/* methods */
|
|
|
|
(destructor)rf_dealloc, /*tp_dealloc*/
|
|
|
|
(printfunc)0, /*tp_print*/
|
|
|
|
(getattrfunc)rf_getattr, /*tp_getattr*/
|
|
|
|
(setattrfunc)0, /*tp_setattr*/
|
|
|
|
(cmpfunc)0, /*tp_compare*/
|
|
|
|
(reprfunc)0, /*tp_repr*/
|
|
|
|
0, /*tp_as_number*/
|
|
|
|
0, /*tp_as_sequence*/
|
|
|
|
0, /*tp_as_mapping*/
|
|
|
|
(hashfunc)0, /*tp_hash*/
|
|
|
|
(ternaryfunc)0, /*tp_call*/
|
|
|
|
(reprfunc)0, /*tp_str*/
|
|
|
|
|
|
|
|
/* Space for future expansion */
|
|
|
|
0L,0L,0L,0L,
|
|
|
|
Rftype__doc__ /* Documentation string */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* End of code for Resource fork objects */
|
|
|
|
/* -------------------------------------------------------- */
|
1994-09-16 07:54:21 -03:00
|
|
|
|
1995-01-09 09:20:04 -04:00
|
|
|
/*----------------------------------------------------------------------*/
|
|
|
|
/* Miscellaneous File System Operations */
|
|
|
|
|
|
|
|
static PyObject *
|
1995-01-22 14:42:12 -04:00
|
|
|
MacOS_GetCreatorAndType(PyObject *self, PyObject *args)
|
1995-01-09 09:20:04 -04:00
|
|
|
{
|
|
|
|
Str255 name;
|
|
|
|
FInfo info;
|
1995-01-22 14:42:12 -04:00
|
|
|
PyObject *creator, *type, *res;
|
1995-01-09 09:20:04 -04:00
|
|
|
OSErr err;
|
|
|
|
|
1995-01-21 09:46:04 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "O&", PyMac_GetStr255, &name))
|
1995-01-09 09:20:04 -04:00
|
|
|
return NULL;
|
1995-01-22 14:42:12 -04:00
|
|
|
if ((err = GetFInfo(name, 0, &info)) != noErr)
|
|
|
|
return PyErr_Mac(MacOS_Error, err);
|
1995-01-09 09:20:04 -04:00
|
|
|
creator = PyString_FromStringAndSize((char *)&info.fdCreator, 4);
|
1995-01-22 14:42:12 -04:00
|
|
|
type = PyString_FromStringAndSize((char *)&info.fdType, 4);
|
|
|
|
res = Py_BuildValue("OO", creator, type);
|
1995-01-12 08:37:24 -04:00
|
|
|
Py_DECREF(creator);
|
1995-01-22 14:42:12 -04:00
|
|
|
Py_DECREF(type);
|
1995-01-09 09:20:04 -04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *
|
1995-01-22 14:42:12 -04:00
|
|
|
MacOS_SetCreatorAndType(PyObject *self, PyObject *args)
|
1995-01-09 09:20:04 -04:00
|
|
|
{
|
|
|
|
Str255 name;
|
1995-01-22 14:42:12 -04:00
|
|
|
ResType creator, type;
|
1995-01-09 09:20:04 -04:00
|
|
|
FInfo info;
|
|
|
|
OSErr err;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "O&O&O&",
|
1995-01-22 14:42:12 -04:00
|
|
|
PyMac_GetStr255, &name, PyMac_GetOSType, &creator, PyMac_GetOSType, &type))
|
1995-01-09 09:20:04 -04:00
|
|
|
return NULL;
|
1995-01-22 14:42:12 -04:00
|
|
|
if ((err = GetFInfo(name, 0, &info)) != noErr)
|
|
|
|
return PyErr_Mac(MacOS_Error, err);
|
1995-01-09 09:20:04 -04:00
|
|
|
info.fdCreator = creator;
|
1995-01-22 14:42:12 -04:00
|
|
|
info.fdType = type;
|
|
|
|
if ((err = SetFInfo(name, 0, &info)) != noErr)
|
|
|
|
return PyErr_Mac(MacOS_Error, err);
|
1995-01-09 09:20:04 -04:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
1995-01-18 19:58:07 -04: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-25 19:09:20 -04:00
|
|
|
MacOS_HighLevelEventProc(EventRecord *e)
|
1995-01-18 19:58:07 -04:00
|
|
|
{
|
|
|
|
if (MacOS_HighLevelEventHandler != NULL) {
|
1995-01-25 19:09:20 -04:00
|
|
|
PyObject *args = PyMac_BuildEventRecord(e);
|
1995-01-18 19:58:07 -04: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 12:36:45 -04:00
|
|
|
/* XXXX Need to come here from PyMac_DoYield too... */
|
|
|
|
|
1995-01-18 19:58:07 -04: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 12:36:45 -04: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 11:46:10 -04:00
|
|
|
if ( bgi == -2 || bgy == -2 ) {
|
1995-01-26 12:36:45 -04:00
|
|
|
bgi = fgi;
|
|
|
|
bgy = fgy;
|
|
|
|
}
|
|
|
|
PyMac_SetYield(fgi, fgy, bgi, bgy);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
1995-01-27 10:43:25 -04:00
|
|
|
static PyObject *
|
|
|
|
MacOS_EnableAppswitch(PyObject *self, PyObject *args)
|
|
|
|
{
|
1995-02-26 06:20:53 -04:00
|
|
|
int old, new;
|
1995-01-27 10:43:25 -04:00
|
|
|
|
1995-02-26 06:20:53 -04:00
|
|
|
if (!PyArg_ParseTuple(args, "i", &new))
|
1995-01-27 10:43:25 -04:00
|
|
|
return NULL;
|
1995-02-26 06:20:53 -04:00
|
|
|
old = PyMac_DoYieldEnabled;
|
|
|
|
PyMac_DoYieldEnabled = new;
|
|
|
|
return Py_BuildValue("i", old);
|
1995-01-27 10:43:25 -04:00
|
|
|
}
|
|
|
|
|
1995-02-02 10:25:56 -04: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;
|
|
|
|
}
|
|
|
|
|
1995-07-17 08:36:01 -03:00
|
|
|
static PyObject *
|
|
|
|
MacOS_GetErrorString(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
int errn;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "i", &errn))
|
|
|
|
return NULL;
|
|
|
|
return Py_BuildValue("s", PyMac_StrError(errn));
|
|
|
|
}
|
|
|
|
|
1996-05-20 08:32:00 -03:00
|
|
|
static char splash_doc[] = "Open a splash-screen dialog by resource-id (0=close)";
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
MacOS_splash(PyObject *self, PyObject *args)
|
|
|
|
{
|
1996-09-15 19:12:00 -03:00
|
|
|
int resid = -1;
|
1996-05-20 08:32:00 -03:00
|
|
|
static DialogPtr curdialog;
|
1996-09-23 12:49:43 -03:00
|
|
|
WindowRef theWindow;
|
|
|
|
CGrafPtr thePort;
|
|
|
|
short xpos, ypos, width, height, swidth, sheight;
|
1996-05-20 08:32:00 -03:00
|
|
|
|
1996-09-15 19:12:00 -03:00
|
|
|
if (!PyArg_ParseTuple(args, "|i", &resid))
|
1996-05-20 08:32:00 -03:00
|
|
|
return NULL;
|
|
|
|
if (curdialog)
|
|
|
|
DisposeDialog(curdialog);
|
|
|
|
|
1996-09-15 19:12:00 -03:00
|
|
|
if ( resid != -1 ) {
|
|
|
|
curdialog = GetNewDialog(resid, NULL, (WindowPtr)-1);
|
1996-09-23 12:49:43 -03:00
|
|
|
if ( curdialog ) {
|
|
|
|
theWindow = GetDialogWindow(curdialog);
|
|
|
|
thePort = GetWindowPort(theWindow);
|
|
|
|
width = thePort->portRect.right - thePort->portRect.left;
|
|
|
|
height = thePort->portRect.bottom - thePort->portRect.top;
|
|
|
|
swidth = qd.screenBits.bounds.right - qd.screenBits.bounds.left;
|
|
|
|
sheight = qd.screenBits.bounds.bottom - qd.screenBits.bounds.top - LMGetMBarHeight();
|
|
|
|
xpos = (swidth-width)/2;
|
|
|
|
ypos = (sheight-height)/5 + LMGetMBarHeight();
|
|
|
|
MoveWindow(theWindow, xpos, ypos, 0);
|
|
|
|
ShowWindow(theWindow);
|
1996-09-15 19:12:00 -03:00
|
|
|
DrawDialog(curdialog);
|
1996-09-23 12:49:43 -03:00
|
|
|
}
|
1996-09-15 19:12:00 -03:00
|
|
|
}
|
1996-05-20 08:32:00 -03:00
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
|
|
|
|
1996-09-30 11:43:22 -03:00
|
|
|
static char DebugStr_doc[] = "Switch to low-level debugger with a message";
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
MacOS_DebugStr(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
Str255 message;
|
|
|
|
PyObject *object = 0;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "O&|O", PyMac_GetStr255, message, &object))
|
|
|
|
return NULL;
|
|
|
|
DebugStr(message);
|
|
|
|
Py_INCREF(Py_None);
|
|
|
|
return Py_None;
|
|
|
|
}
|
1996-05-20 08:32:00 -03:00
|
|
|
|
1996-02-29 12:11:32 -04:00
|
|
|
static char openrf_doc[] = "Open resource fork of a file";
|
|
|
|
|
|
|
|
static PyObject *
|
|
|
|
MacOS_openrf(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
OSErr err;
|
|
|
|
char *mode = "r";
|
|
|
|
FSSpec fss;
|
|
|
|
SignedByte permission = 1;
|
|
|
|
rfobject *fp;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "O&|s", PyMac_GetFSSpec, &fss, &mode))
|
|
|
|
return NULL;
|
|
|
|
while (*mode) {
|
|
|
|
switch (*mode++) {
|
|
|
|
case '*': break;
|
|
|
|
case 'r': permission = 1; break;
|
|
|
|
case 'w': permission = 2; break;
|
|
|
|
case 'b': break;
|
|
|
|
default:
|
|
|
|
PyErr_BadArgument();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (fp = newrfobject()) == NULL )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum);
|
|
|
|
|
|
|
|
if ( err == fnfErr ) {
|
|
|
|
/* In stead of doing complicated things here to get creator/type
|
|
|
|
** correct we let the standard i/o library handle it
|
|
|
|
*/
|
|
|
|
FILE *tfp;
|
|
|
|
char pathname[257];
|
|
|
|
|
1996-11-09 14:46:57 -04:00
|
|
|
if ( err=PyMac_GetFullPath(&fss, pathname) ) {
|
1996-02-29 12:11:32 -04:00
|
|
|
PyMac_Error(err);
|
|
|
|
Py_DECREF(fp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( (tfp = fopen(pathname, "w")) == NULL ) {
|
|
|
|
PyMac_Error(fnfErr); /* What else... */
|
|
|
|
Py_DECREF(fp);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fclose(tfp);
|
|
|
|
err = HOpenRF(fss.vRefNum, fss.parID, fss.name, permission, &fp->fRefNum);
|
|
|
|
}
|
|
|
|
if ( err ) {
|
|
|
|
Py_DECREF(fp);
|
|
|
|
PyMac_Error(err);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
fp->isclosed = 0;
|
|
|
|
return (PyObject *)fp;
|
|
|
|
}
|
|
|
|
|
1994-09-16 07:54:21 -03:00
|
|
|
static PyMethodDef MacOS_Methods[] = {
|
1995-01-18 19:58:07 -04:00
|
|
|
{"AcceptHighLevelEvent", MacOS_AcceptHighLevelEvent, 1},
|
1995-01-22 14:42:12 -04:00
|
|
|
{"GetCreatorAndType", MacOS_GetCreatorAndType, 1},
|
|
|
|
{"SetCreatorAndType", MacOS_SetCreatorAndType, 1},
|
1995-01-18 19:58:07 -04:00
|
|
|
#ifdef USE_STDWIN
|
|
|
|
{"SetHighLevelEventHandler", MacOS_SetHighLevelEventHandler, 1},
|
|
|
|
#endif
|
1995-01-26 12:36:45 -04:00
|
|
|
{"SetScheduleTimes", MacOS_SetScheduleTimes, 1},
|
1995-01-27 10:43:25 -04:00
|
|
|
{"EnableAppswitch", MacOS_EnableAppswitch, 1},
|
1995-02-02 10:25:56 -04:00
|
|
|
{"HandleEvent", MacOS_HandleEvent, 1},
|
1995-07-17 08:36:01 -03:00
|
|
|
{"GetErrorString", MacOS_GetErrorString, 1},
|
1996-02-29 12:11:32 -04:00
|
|
|
{"openrf", MacOS_openrf, 1, openrf_doc},
|
1996-05-20 08:32:00 -03:00
|
|
|
{"splash", MacOS_splash, 1, splash_doc},
|
1996-09-30 11:43:22 -03:00
|
|
|
{"DebugStr", MacOS_DebugStr, 1, DebugStr_doc},
|
1995-01-18 19:58:07 -04:00
|
|
|
{NULL, NULL} /* Sentinel */
|
1994-09-16 07:54:21 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
MacOS_Init()
|
|
|
|
{
|
|
|
|
PyObject *m, *d;
|
|
|
|
|
|
|
|
m = Py_InitModule("MacOS", MacOS_Methods);
|
|
|
|
d = PyModule_GetDict(m);
|
|
|
|
|
|
|
|
/* Initialize MacOS.Error exception */
|
1995-01-25 19:09:20 -04:00
|
|
|
MacOS_Error = PyMac_GetOSErrException();
|
1994-09-29 07:02:56 -03:00
|
|
|
if (MacOS_Error == NULL || PyDict_SetItemString(d, "Error", MacOS_Error) != 0)
|
1994-09-16 07:54:21 -03:00
|
|
|
Py_FatalError("can't define MacOS.Error");
|
|
|
|
}
|
1995-02-26 06:20:53 -04:00
|
|
|
|