1995-01-22 14:36:13 -04:00
|
|
|
/***********************************************************
|
1997-01-31 12:15:11 -04:00
|
|
|
Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
|
1995-01-22 14:36:13 -04:00
|
|
|
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.
|
|
|
|
|
|
|
|
******************************************************************/
|
1994-12-14 10:07:50 -04:00
|
|
|
|
1996-08-19 12:11:45 -03:00
|
|
|
|
1994-12-14 10:07:50 -04:00
|
|
|
#include "Python.h"
|
1995-02-13 21:27:24 -04:00
|
|
|
|
1994-12-14 10:07:50 -04:00
|
|
|
#include "macglue.h"
|
1995-02-15 18:58:33 -04:00
|
|
|
#include "marshal.h"
|
|
|
|
#include "import.h"
|
1997-06-12 12:29:46 -03:00
|
|
|
#include "importdl.h"
|
2001-05-19 09:31:09 -03:00
|
|
|
#include "pymactoolbox.h"
|
1994-12-14 10:07:50 -04:00
|
|
|
|
1995-08-14 09:35:10 -03:00
|
|
|
#include "pythonresources.h"
|
|
|
|
|
2001-05-12 19:46:35 -03:00
|
|
|
#ifdef WITHOUT_FRAMEWORKS
|
1994-12-14 10:07:50 -04:00
|
|
|
#include <OSUtils.h> /* for Set(Current)A5 */
|
1995-01-26 12:36:45 -04:00
|
|
|
#include <Files.h>
|
1995-02-13 07:33:28 -04:00
|
|
|
#include <StandardFile.h>
|
1994-12-14 10:07:50 -04:00
|
|
|
#include <Resources.h>
|
|
|
|
#include <Memory.h>
|
|
|
|
#include <Windows.h>
|
1995-01-26 12:36:45 -04:00
|
|
|
#include <Traps.h>
|
1995-01-27 10:43:25 -04:00
|
|
|
#include <Processes.h>
|
1995-02-18 11:01:31 -04:00
|
|
|
#include <Fonts.h>
|
|
|
|
#include <Menus.h>
|
1995-06-18 17:03:40 -03:00
|
|
|
#include <TextUtils.h>
|
2001-05-12 19:46:35 -03:00
|
|
|
#include <LowMem.h>
|
|
|
|
#include <Events.h>
|
|
|
|
#else
|
|
|
|
#include <Carbon/Carbon.h>
|
|
|
|
#endif
|
|
|
|
|
1995-02-27 12:17:28 -04:00
|
|
|
#ifdef __MWERKS__
|
|
|
|
#include <SIOUX.h>
|
2000-07-11 18:16:03 -03:00
|
|
|
extern void SIOUXSetupMenus(void);
|
|
|
|
extern void SIOUXDoAboutBox(void);
|
1995-02-27 12:17:28 -04:00
|
|
|
#endif
|
2000-07-11 18:16:03 -03:00
|
|
|
#ifdef USE_GUSI
|
|
|
|
/* Functions we redefine because they're in obscure libraries */
|
|
|
|
extern void SpinCursor(short x);
|
|
|
|
extern void RotateCursor(short x);
|
2002-06-26 17:37:40 -03:00
|
|
|
extern pascal unsigned char * PLstrcpy(unsigned char *, const unsigned char *);
|
|
|
|
extern pascal short PLstrcmp(const unsigned char *, const unsigned char *);
|
|
|
|
extern pascal char *PLstrrchr(const unsigned char *, short);
|
2000-07-11 18:16:03 -03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1996-09-05 21:30:45 -03:00
|
|
|
/* The ID of the Sioux apple menu */
|
|
|
|
#define SIOUX_APPLEID 32000
|
|
|
|
|
1995-01-27 10:43:25 -04:00
|
|
|
#include <signal.h>
|
1995-02-15 18:58:33 -04:00
|
|
|
#include <stdio.h>
|
1995-01-26 12:36:45 -04:00
|
|
|
|
1996-08-01 12:23:54 -03:00
|
|
|
/*
|
|
|
|
** When less than this amount of stackspace is left we
|
|
|
|
** raise a MemoryError.
|
|
|
|
*/
|
|
|
|
#ifndef MINIMUM_STACK_SIZE
|
|
|
|
#define MINIMUM_STACK_SIZE 8192
|
|
|
|
#endif
|
|
|
|
|
2001-02-02 18:40:28 -04:00
|
|
|
/*
|
|
|
|
** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer,
|
|
|
|
** but the stack cannot grow that far due to rlimit values. We cannot get at this value
|
|
|
|
** from Carbon, so we set a maximum to the stack here that is based on the default
|
|
|
|
** stack limit of 512K.
|
|
|
|
*/
|
|
|
|
#define MAXIMUM_STACK_SIZE (256*1024)
|
|
|
|
|
1995-01-27 10:43:25 -04:00
|
|
|
/*
|
1995-02-27 12:17:28 -04:00
|
|
|
** We have to be careful, since we can't handle
|
1995-01-27 10:43:25 -04:00
|
|
|
** things like updates (and they'll keep coming back if we don't
|
1995-02-27 12:17:28 -04:00
|
|
|
** handle them). Note that we don't know who has windows open, so
|
|
|
|
** even handing updates off to SIOUX under MW isn't going to work.
|
1995-01-27 10:43:25 -04:00
|
|
|
*/
|
1997-08-26 10:20:34 -03:00
|
|
|
#define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask)
|
1995-01-26 12:36:45 -04:00
|
|
|
|
|
|
|
#include <signal.h>
|
1994-12-14 10:07:50 -04:00
|
|
|
|
1995-01-22 14:36:13 -04:00
|
|
|
/* XXX We should include Errors.h here, but it has a name conflict
|
1995-01-18 09:53:49 -04:00
|
|
|
** with the python errors.h. */
|
|
|
|
#define fnfErr -43
|
|
|
|
|
1995-01-27 10:43:25 -04:00
|
|
|
/* Interrupt code variables: */
|
|
|
|
static int interrupted; /* Set to true when cmd-. seen */
|
2000-07-11 16:51:05 -03:00
|
|
|
static RETSIGTYPE intcatcher(int);
|
1995-01-27 10:43:25 -04:00
|
|
|
|
2001-05-12 19:46:35 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
2000-07-11 16:51:05 -03:00
|
|
|
static int PyMac_Yield(void);
|
2001-05-12 19:46:35 -03:00
|
|
|
#endif
|
1996-09-04 12:24:59 -03:00
|
|
|
|
1997-06-03 12:28:29 -03:00
|
|
|
/*
|
|
|
|
** These are the real scheduling parameters that control what we check
|
|
|
|
** in the event loop, and how often we check. The values are initialized
|
|
|
|
** from pyMac_SchedParamStruct.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct real_sched_param_struct {
|
|
|
|
int check_interrupt; /* if true check for command-dot */
|
|
|
|
int process_events; /* if nonzero enable evt processing, this mask */
|
|
|
|
int besocial; /* if nonzero be a little social with CPU */
|
|
|
|
unsigned long check_interval; /* how often to check, in ticks */
|
|
|
|
unsigned long bg_yield; /* yield so long when in background */
|
|
|
|
/* these are computed from previous and clock and such */
|
|
|
|
int enabled; /* check_interrupt OR process_event OR yield */
|
|
|
|
unsigned long next_check; /* when to check/yield next, in ticks */
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct real_sched_param_struct schedparams =
|
|
|
|
{ 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0};
|
|
|
|
|
1996-09-04 12:24:59 -03:00
|
|
|
/*
|
|
|
|
** Workaround for sioux/gusi combo: set when we are exiting
|
|
|
|
*/
|
|
|
|
int PyMac_ConsoleIsDead;
|
|
|
|
|
1997-06-12 07:49:13 -03:00
|
|
|
/*
|
|
|
|
** Sioux menu bar, saved early so we can restore it
|
|
|
|
*/
|
2001-02-17 18:02:07 -04:00
|
|
|
static MenuBarHandle sioux_mbar;
|
1997-06-12 07:49:13 -03:00
|
|
|
|
1997-06-20 13:18:15 -03:00
|
|
|
/*
|
|
|
|
** The python-code event handler
|
|
|
|
*/
|
|
|
|
static PyObject *python_event_handler;
|
|
|
|
|
2001-05-19 09:55:57 -03:00
|
|
|
/* Given an FSSpec, return the FSSpec of the parent folder */
|
|
|
|
|
|
|
|
static OSErr
|
|
|
|
get_folder_parent (FSSpec * fss, FSSpec * parent)
|
|
|
|
{
|
|
|
|
CInfoPBRec rec;
|
|
|
|
short err;
|
|
|
|
|
|
|
|
* parent = * fss;
|
|
|
|
rec.hFileInfo.ioNamePtr = parent->name;
|
|
|
|
rec.hFileInfo.ioVRefNum = parent->vRefNum;
|
|
|
|
rec.hFileInfo.ioDirID = parent->parID;
|
|
|
|
rec.hFileInfo.ioFDirIndex = -1;
|
|
|
|
rec.hFileInfo.ioFVersNum = 0;
|
|
|
|
if (err = PBGetCatInfoSync (& rec))
|
|
|
|
return err;
|
|
|
|
parent->parID = rec.dirInfo.ioDrParID;
|
|
|
|
/* parent->name[0] = 0; */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Given an FSSpec return a full, colon-separated pathname */
|
|
|
|
|
|
|
|
OSErr
|
2001-09-11 06:22:19 -03:00
|
|
|
PyMac_GetFullPathname (FSSpec *fss, char *buf, int length)
|
2001-05-19 09:55:57 -03:00
|
|
|
{
|
|
|
|
short err;
|
|
|
|
FSSpec fss_parent, fss_current;
|
|
|
|
char tmpbuf[1024];
|
|
|
|
int plen;
|
|
|
|
|
|
|
|
fss_current = *fss;
|
|
|
|
plen = fss_current.name[0];
|
2001-09-11 06:22:19 -03:00
|
|
|
if ( plen+2 > length ) {
|
|
|
|
*buf = 0;
|
|
|
|
return errFSNameTooLong;
|
|
|
|
}
|
2001-05-19 09:55:57 -03:00
|
|
|
memcpy(buf, &fss_current.name[1], plen);
|
|
|
|
buf[plen] = 0;
|
|
|
|
/* Special case for disk names */
|
|
|
|
if ( fss_current.parID <= 1 ) {
|
|
|
|
buf[plen++] = ':';
|
|
|
|
buf[plen] = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
while (fss_current.parID > 1) {
|
|
|
|
/* Get parent folder name */
|
2001-09-11 06:22:19 -03:00
|
|
|
if (err = get_folder_parent(&fss_current, &fss_parent)) {
|
|
|
|
*buf = 0;
|
2001-05-19 09:55:57 -03:00
|
|
|
return err;
|
2001-09-11 06:22:19 -03:00
|
|
|
}
|
2001-05-19 09:55:57 -03:00
|
|
|
fss_current = fss_parent;
|
|
|
|
/* Prepend path component just found to buf */
|
|
|
|
plen = fss_current.name[0];
|
|
|
|
if (strlen(buf) + plen + 1 > 1024) {
|
|
|
|
/* Oops... Not enough space (shouldn't happen) */
|
|
|
|
*buf = 0;
|
2001-09-11 06:22:19 -03:00
|
|
|
return errFSNameTooLong;
|
2001-05-19 09:55:57 -03:00
|
|
|
}
|
|
|
|
memcpy(tmpbuf, &fss_current.name[1], plen);
|
|
|
|
tmpbuf[plen] = ':';
|
|
|
|
strcpy(&tmpbuf[plen+1], buf);
|
2001-09-11 06:22:19 -03:00
|
|
|
if ( strlen(tmpbuf) > length ) {
|
|
|
|
*buf = 0;
|
|
|
|
return errFSNameTooLong;
|
|
|
|
}
|
2001-05-19 09:55:57 -03:00
|
|
|
strcpy(buf, tmpbuf);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
2000-07-24 16:50:16 -03:00
|
|
|
|
1996-08-19 08:01:05 -03:00
|
|
|
|
2000-04-07 06:10:49 -03:00
|
|
|
#ifdef USE_GUSI
|
1996-09-07 14:09:31 -03:00
|
|
|
/*
|
|
|
|
** SpinCursor (needed by GUSI) drags in heaps of stuff, so we
|
|
|
|
** provide a dummy here.
|
|
|
|
*/
|
1996-08-19 08:36:25 -03:00
|
|
|
void SpinCursor(short x) { /* Dummy */ }
|
1998-02-20 12:03:15 -04:00
|
|
|
void RotateCursor(short x) { /* Dummy */ }
|
1996-08-19 08:36:25 -03:00
|
|
|
|
1996-09-04 12:24:59 -03:00
|
|
|
|
1997-05-23 12:35:14 -03:00
|
|
|
/* Called at exit() time thru atexit(), to stop event processing */
|
|
|
|
void
|
|
|
|
PyMac_StopGUSISpin() {
|
|
|
|
PyMac_ConsoleIsDead = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* USE_GUSI */
|
1996-03-06 12:21:34 -04:00
|
|
|
|
1995-08-14 09:35:10 -03:00
|
|
|
|
1995-01-18 09:53:49 -04:00
|
|
|
/* Convert C to Pascal string. Returns pointer to static buffer. */
|
|
|
|
unsigned char *
|
|
|
|
Pstring(char *str)
|
|
|
|
{
|
|
|
|
static Str255 buf;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = strlen(str);
|
1995-01-21 09:46:04 -04:00
|
|
|
if (len > 255)
|
|
|
|
len = 255;
|
1995-01-18 09:53:49 -04:00
|
|
|
buf[0] = (unsigned char)len;
|
|
|
|
strncpy((char *)buf+1, str, len);
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2000-12-12 18:12:14 -04:00
|
|
|
|
1996-07-22 12:25:10 -03:00
|
|
|
#ifdef USE_STACKCHECK
|
|
|
|
/* Check for stack overflow */
|
|
|
|
int
|
|
|
|
PyOS_CheckStack()
|
|
|
|
{
|
2000-08-25 18:57:23 -03:00
|
|
|
char here;
|
|
|
|
static char *sentinel = 0;
|
2000-09-08 19:05:48 -03:00
|
|
|
static PyThreadState *thread_for_sentinel = 0;
|
1996-07-22 12:25:10 -03:00
|
|
|
|
2001-02-02 18:40:28 -04:00
|
|
|
if ( sentinel == 0 ) {
|
|
|
|
unsigned long stackspace = StackSpace();
|
|
|
|
|
|
|
|
#ifdef MAXIMUM_STACK_SIZE
|
|
|
|
/* See the comment at the definition */
|
|
|
|
if ( stackspace > MAXIMUM_STACK_SIZE )
|
|
|
|
stackspace = MAXIMUM_STACK_SIZE;
|
|
|
|
#endif
|
|
|
|
sentinel = &here - stackspace + MINIMUM_STACK_SIZE;
|
2000-08-25 18:57:23 -03:00
|
|
|
}
|
2000-09-08 19:05:48 -03:00
|
|
|
if ( thread_for_sentinel == 0 ) {
|
|
|
|
thread_for_sentinel = PyThreadState_Get();
|
|
|
|
}
|
|
|
|
if ( &here < sentinel ) {
|
|
|
|
if (thread_for_sentinel == PyThreadState_Get()) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
1996-07-22 12:25:10 -03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif /* USE_STACKCHECK */
|
|
|
|
|
2001-05-12 19:46:35 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
1995-01-27 10:43:25 -04:00
|
|
|
/* The catcher routine (which may not be used for all compilers) */
|
|
|
|
static RETSIGTYPE
|
|
|
|
intcatcher(sig)
|
|
|
|
int sig;
|
|
|
|
{
|
|
|
|
interrupted = 1;
|
|
|
|
signal(SIGINT, intcatcher);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PyOS_InitInterrupts()
|
|
|
|
{
|
|
|
|
if (signal(SIGINT, SIG_IGN) != SIG_IGN)
|
|
|
|
signal(SIGINT, intcatcher);
|
|
|
|
}
|
|
|
|
|
1997-08-08 11:57:37 -03:00
|
|
|
void
|
|
|
|
PyOS_FiniInterrupts()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-11-09 20:41:43 -04:00
|
|
|
/* Check whether we are in the foreground */
|
|
|
|
static int
|
|
|
|
PyMac_InForeground(void)
|
|
|
|
{
|
|
|
|
static ProcessSerialNumber ours;
|
|
|
|
static inited;
|
|
|
|
ProcessSerialNumber curfg;
|
|
|
|
Boolean eq;
|
|
|
|
|
|
|
|
if ( inited == 0 ) {
|
|
|
|
(void)GetCurrentProcess(&ours);
|
|
|
|
inited = 1;
|
|
|
|
}
|
|
|
|
if ( GetFrontProcess(&curfg) < 0 )
|
|
|
|
eq = 1;
|
|
|
|
else if ( SameProcess(&ours, &curfg, &eq) < 0 )
|
|
|
|
eq = 1;
|
|
|
|
return (int)eq;
|
|
|
|
}
|
|
|
|
|
1995-01-27 10:43:25 -04:00
|
|
|
/*
|
|
|
|
** This routine scans the event queue looking for cmd-.
|
|
|
|
*/
|
|
|
|
static void
|
2001-11-09 20:41:43 -04:00
|
|
|
scan_event_queue(force)
|
|
|
|
int force;
|
1995-01-27 10:43:25 -04:00
|
|
|
{
|
2001-11-09 20:41:43 -04:00
|
|
|
if ( interrupted || (!schedparams.check_interrupt && !force) )
|
|
|
|
return;
|
2001-01-12 19:42:28 -04:00
|
|
|
if ( CheckEventQueueForUserCancel() )
|
|
|
|
interrupted = 1;
|
1995-01-27 10:43:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1997-06-20 13:18:15 -03:00
|
|
|
PyErr_CheckSignals()
|
1995-01-27 10:43:25 -04:00
|
|
|
{
|
1997-06-03 12:28:29 -03:00
|
|
|
if (schedparams.enabled) {
|
2002-12-12 06:31:54 -04:00
|
|
|
if ( interrupted || (unsigned long)TickCount() > schedparams.next_check ) {
|
2001-11-09 20:41:43 -04:00
|
|
|
scan_event_queue(0);
|
1997-06-03 12:28:29 -03:00
|
|
|
if (interrupted) {
|
|
|
|
interrupted = 0;
|
1997-06-20 13:18:15 -03:00
|
|
|
PyErr_SetNone(PyExc_KeyboardInterrupt);
|
|
|
|
return -1;
|
1997-06-03 12:28:29 -03:00
|
|
|
}
|
2001-11-09 20:41:43 -04:00
|
|
|
if ( PyMac_Yield() < 0)
|
|
|
|
return -1;
|
2002-12-12 06:31:54 -04:00
|
|
|
schedparams.next_check = (unsigned long)TickCount()
|
2001-11-09 20:41:43 -04:00
|
|
|
+ schedparams.check_interval;
|
1997-06-03 12:28:29 -03:00
|
|
|
}
|
1995-01-27 10:43:25 -04:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1997-06-20 13:18:15 -03:00
|
|
|
int
|
|
|
|
PyOS_InterruptOccurred()
|
|
|
|
{
|
2001-11-09 20:41:43 -04:00
|
|
|
scan_event_queue(0);
|
|
|
|
if ( !interrupted )
|
|
|
|
return 0;
|
|
|
|
interrupted = 0;
|
|
|
|
return 1;
|
1995-01-27 10:43:25 -04:00
|
|
|
}
|
2001-05-12 19:46:35 -03:00
|
|
|
#endif
|
1995-01-27 10:43:25 -04:00
|
|
|
|
1997-06-20 13:18:15 -03:00
|
|
|
int
|
|
|
|
PyMac_SetEventHandler(PyObject *evh)
|
|
|
|
{
|
|
|
|
if ( evh && python_event_handler ) {
|
|
|
|
PyErr_SetString(PyExc_RuntimeError, "Python event handler already set");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if ( python_event_handler )
|
|
|
|
Py_DECREF(python_event_handler);
|
|
|
|
if ( evh )
|
|
|
|
Py_INCREF(evh);
|
|
|
|
python_event_handler = evh;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1995-02-02 10:25:56 -04:00
|
|
|
/*
|
|
|
|
** Handle an event, either one found in the mainloop eventhandler or
|
|
|
|
** one passed back from the python program.
|
|
|
|
*/
|
|
|
|
void
|
1997-06-20 13:18:15 -03:00
|
|
|
PyMac_HandleEventIntern(evp)
|
1995-02-02 10:25:56 -04:00
|
|
|
EventRecord *evp;
|
|
|
|
{
|
|
|
|
#ifdef __MWERKS__
|
1995-11-10 10:53:00 -04:00
|
|
|
{
|
|
|
|
int siouxdidit;
|
|
|
|
|
|
|
|
/* If SIOUX wants it we're done */
|
|
|
|
siouxdidit = SIOUXHandleOneEvent(evp);
|
|
|
|
if ( siouxdidit )
|
|
|
|
return;
|
|
|
|
}
|
1995-02-02 10:25:56 -04:00
|
|
|
#else
|
1997-08-26 10:20:34 -03:00
|
|
|
/* Other compilers are just unlucky... */
|
1995-02-02 10:25:56 -04:00
|
|
|
#endif /* !__MWERKS__ */
|
1997-06-20 13:18:15 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
** Handle an event, either through HandleEvent or by passing it to the Python
|
|
|
|
** event handler.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
PyMac_HandleEvent(evp)
|
|
|
|
EventRecord *evp;
|
|
|
|
{
|
|
|
|
PyObject *rv;
|
|
|
|
|
|
|
|
if ( python_event_handler ) {
|
|
|
|
rv = PyObject_CallFunction(python_event_handler, "(O&)",
|
|
|
|
PyMac_BuildEventRecord, evp);
|
|
|
|
if ( rv )
|
|
|
|
Py_DECREF(rv);
|
|
|
|
else
|
|
|
|
return -1; /* Propagate exception */
|
|
|
|
} else {
|
|
|
|
PyMac_HandleEventIntern(evp);
|
|
|
|
}
|
|
|
|
return 0;
|
1995-02-02 10:25:56 -04:00
|
|
|
}
|
|
|
|
|
2001-05-12 19:46:35 -03:00
|
|
|
#if !TARGET_API_MAC_OSX
|
1995-01-26 12:36:45 -04:00
|
|
|
/*
|
1997-06-03 12:28:29 -03:00
|
|
|
** Yield the CPU to other tasks without processing events.
|
1995-01-26 12:36:45 -04:00
|
|
|
*/
|
2000-04-07 06:10:49 -03:00
|
|
|
int
|
1997-06-03 12:28:29 -03:00
|
|
|
PyMac_DoYield(int maxsleep, int maycallpython)
|
1994-12-14 10:07:50 -04:00
|
|
|
{
|
|
|
|
EventRecord ev;
|
1995-01-26 12:36:45 -04:00
|
|
|
int gotone;
|
1997-06-03 12:28:29 -03:00
|
|
|
long latest_time_ready;
|
1997-06-20 13:18:15 -03:00
|
|
|
static int in_here = 0;
|
1995-01-26 12:36:45 -04:00
|
|
|
|
1997-06-20 13:18:15 -03:00
|
|
|
in_here++;
|
1996-09-04 12:24:59 -03:00
|
|
|
|
1997-06-03 12:28:29 -03:00
|
|
|
/*
|
|
|
|
** Check which of the eventloop cases we have:
|
|
|
|
** - process events
|
|
|
|
** - don't process events but do yield
|
|
|
|
** - do neither
|
|
|
|
*/
|
1997-06-20 13:18:15 -03:00
|
|
|
if( in_here > 1 || !schedparams.process_events ||
|
|
|
|
(python_event_handler && !maycallpython) ) {
|
1997-06-03 12:28:29 -03:00
|
|
|
if ( maxsleep >= 0 ) {
|
2002-12-12 06:31:54 -04:00
|
|
|
/* XXXX Need to do something here */
|
2001-04-25 19:07:27 -03:00
|
|
|
}
|
1997-06-03 12:28:29 -03:00
|
|
|
} else {
|
2002-12-12 06:31:54 -04:00
|
|
|
latest_time_ready = TickCount() + maxsleep;
|
2000-04-07 06:10:49 -03:00
|
|
|
do {
|
1997-08-26 10:20:34 -03:00
|
|
|
/* XXXX Hack by Jack.
|
|
|
|
** In time.sleep() you can click to another application
|
|
|
|
** once only. If you come back to Python you cannot get away
|
|
|
|
** again.
|
|
|
|
**/
|
1997-06-20 13:18:15 -03:00
|
|
|
gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL);
|
1997-06-03 12:28:29 -03:00
|
|
|
/* Get out quickly if nothing interesting is happening */
|
|
|
|
if ( !gotone || ev.what == nullEvent )
|
|
|
|
break;
|
1997-06-20 13:18:15 -03:00
|
|
|
if ( PyMac_HandleEvent(&ev) < 0 ) {
|
|
|
|
in_here--;
|
|
|
|
return -1;
|
|
|
|
}
|
2002-12-12 06:31:54 -04:00
|
|
|
maxsleep = latest_time_ready - TickCount();
|
2000-04-07 06:10:49 -03:00
|
|
|
} while ( maxsleep > 0 );
|
1994-12-14 10:07:50 -04:00
|
|
|
}
|
1997-06-20 13:18:15 -03:00
|
|
|
in_here--;
|
|
|
|
return 0;
|
1995-01-26 12:36:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-06-03 12:28:29 -03:00
|
|
|
** Process events and/or yield the CPU to other tasks if opportune
|
1995-01-26 12:36:45 -04:00
|
|
|
*/
|
1997-06-20 13:18:15 -03:00
|
|
|
int
|
1995-01-26 12:36:45 -04:00
|
|
|
PyMac_Yield() {
|
1997-06-03 12:28:29 -03:00
|
|
|
unsigned long maxsleep;
|
1995-01-26 12:36:45 -04:00
|
|
|
|
1997-06-03 12:28:29 -03:00
|
|
|
if( PyMac_InForeground() )
|
|
|
|
maxsleep = 0;
|
1995-01-27 10:43:25 -04:00
|
|
|
else
|
1997-06-03 12:28:29 -03:00
|
|
|
maxsleep = schedparams.bg_yield;
|
|
|
|
|
1997-06-20 13:18:15 -03:00
|
|
|
return PyMac_DoYield(maxsleep, 1);
|
1995-01-26 12:36:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-06-03 12:28:29 -03:00
|
|
|
** Return current scheduler parameters
|
1995-01-26 12:36:45 -04:00
|
|
|
*/
|
1997-06-03 12:28:29 -03:00
|
|
|
void
|
|
|
|
PyMac_GetSchedParams(PyMacSchedParams *sp)
|
1995-01-26 12:36:45 -04:00
|
|
|
{
|
1997-06-03 12:28:29 -03:00
|
|
|
sp->check_interrupt = schedparams.check_interrupt;
|
|
|
|
sp->process_events = schedparams.process_events;
|
|
|
|
sp->besocial = schedparams.besocial;
|
|
|
|
sp->check_interval = schedparams.check_interval / 60.0;
|
|
|
|
sp->bg_yield = schedparams.bg_yield / 60.0;
|
1994-12-14 10:07:50 -04:00
|
|
|
}
|
1996-09-04 12:24:59 -03:00
|
|
|
|
1997-06-03 12:28:29 -03:00
|
|
|
/*
|
|
|
|
** Set current scheduler parameters
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
PyMac_SetSchedParams(PyMacSchedParams *sp)
|
|
|
|
{
|
|
|
|
schedparams.check_interrupt = sp->check_interrupt;
|
|
|
|
schedparams.process_events = sp->process_events;
|
|
|
|
schedparams.besocial = sp->besocial;
|
|
|
|
schedparams.check_interval = (unsigned long)(sp->check_interval*60);
|
|
|
|
schedparams.bg_yield = (unsigned long)(sp->bg_yield*60);
|
|
|
|
if ( schedparams.check_interrupt || schedparams.process_events ||
|
|
|
|
schedparams.besocial )
|
|
|
|
schedparams.enabled = 1;
|
|
|
|
else
|
|
|
|
schedparams.enabled = 0;
|
|
|
|
schedparams.next_check = 0; /* Check immedeately */
|
|
|
|
}
|
1997-06-12 07:49:13 -03:00
|
|
|
|
1996-09-05 21:30:45 -03:00
|
|
|
/*
|
|
|
|
** Install our menu bar.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
PyMac_InitMenuBar()
|
|
|
|
{
|
|
|
|
MenuHandle applemenu;
|
2001-12-10 12:08:14 -04:00
|
|
|
Str255 about_text;
|
|
|
|
static unsigned char about_sioux[] = "\pAbout SIOUX";
|
1996-09-05 21:30:45 -03:00
|
|
|
|
2001-04-25 19:07:27 -03:00
|
|
|
if ( sioux_mbar ) return;
|
2001-11-30 10:16:36 -04:00
|
|
|
if ( (sioux_mbar=GetMenuBar()) == NULL || GetMenuHandle(SIOUX_APPLEID) == NULL) {
|
1997-06-12 07:49:13 -03:00
|
|
|
/* Sioux menu not installed yet. Do so */
|
|
|
|
SIOUXSetupMenus();
|
|
|
|
if ( (sioux_mbar=GetMenuBar()) == NULL )
|
|
|
|
return;
|
|
|
|
}
|
1997-04-08 12:27:00 -03:00
|
|
|
if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return;
|
2001-12-10 12:08:14 -04:00
|
|
|
GetMenuItemText(applemenu, 1, about_text);
|
|
|
|
if ( about_text[0] == about_sioux[0] &&
|
|
|
|
strncmp((char *)(about_text+1), (char *)(about_sioux+1), about_text[0]) == 0 )
|
|
|
|
SetMenuItemText(applemenu, 1, "\pAbout Python...");
|
1996-09-05 21:30:45 -03:00
|
|
|
}
|
|
|
|
|
1997-06-12 07:49:13 -03:00
|
|
|
/*
|
|
|
|
** Restore sioux menu bar
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
PyMac_RestoreMenuBar()
|
|
|
|
{
|
2001-02-17 18:02:07 -04:00
|
|
|
MenuBarHandle curmenubar;
|
|
|
|
|
|
|
|
curmenubar = GetMenuBar();
|
1997-06-12 12:29:46 -03:00
|
|
|
if ( sioux_mbar ) {
|
1997-06-12 07:49:13 -03:00
|
|
|
SetMenuBar(sioux_mbar);
|
1997-06-12 12:29:46 -03:00
|
|
|
DrawMenuBar();
|
2001-02-17 18:02:07 -04:00
|
|
|
} else {
|
1998-02-20 12:03:15 -04:00
|
|
|
PyMac_InitMenuBar();
|
2001-02-17 18:02:07 -04:00
|
|
|
DrawMenuBar();
|
|
|
|
}
|
1997-06-12 07:49:13 -03:00
|
|
|
}
|
|
|
|
|
2001-04-25 19:07:27 -03:00
|
|
|
void
|
|
|
|
PyMac_RaiseConsoleWindow()
|
|
|
|
{
|
|
|
|
/* Note: this is a hack. SIOUXTextWindow is SIOUX's internal structure
|
|
|
|
** and we happen to know that the first entry is the window pointer.
|
|
|
|
*/
|
|
|
|
extern WindowRef *SIOUXTextWindow;
|
|
|
|
|
|
|
|
if ( SIOUXTextWindow == NULL || *SIOUXTextWindow == NULL )
|
|
|
|
return;
|
|
|
|
if ( FrontWindow() != *SIOUXTextWindow )
|
|
|
|
BringToFront(*SIOUXTextWindow);
|
|
|
|
}
|
1997-06-12 07:49:13 -03:00
|
|
|
|
1996-09-05 21:30:45 -03:00
|
|
|
/*
|
|
|
|
** Our replacement about box
|
|
|
|
*/
|
1998-07-31 06:36:30 -03:00
|
|
|
|
|
|
|
#include "patchlevel.h"
|
|
|
|
|
1996-09-05 21:30:45 -03:00
|
|
|
void
|
|
|
|
SIOUXDoAboutBox(void)
|
|
|
|
{
|
|
|
|
DialogPtr theDialog;
|
1998-07-31 06:36:30 -03:00
|
|
|
WindowPtr theWindow;
|
1996-09-05 21:30:45 -03:00
|
|
|
short item;
|
1998-07-31 06:36:30 -03:00
|
|
|
short fontID;
|
1996-09-05 21:30:45 -03:00
|
|
|
|
|
|
|
if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL )
|
|
|
|
return;
|
1996-09-22 19:14:30 -03:00
|
|
|
theWindow = GetDialogWindow(theDialog);
|
1998-07-31 06:36:30 -03:00
|
|
|
SetPortWindowPort(theWindow);
|
|
|
|
GetFNum("\pPython-Sans", &fontID);
|
|
|
|
if (fontID == 0)
|
|
|
|
fontID = kFontIDGeneva;
|
|
|
|
TextFont(fontID);
|
|
|
|
TextSize(9);
|
2001-08-19 19:32:27 -03:00
|
|
|
ParamText(Pstring(PY_VERSION), "\p", "\p", "\p");
|
1996-09-22 19:14:30 -03:00
|
|
|
ShowWindow(theWindow);
|
1996-09-05 21:30:45 -03:00
|
|
|
ModalDialog(NULL, &item);
|
|
|
|
DisposeDialog(theDialog);
|
|
|
|
}
|
|
|
|
|
2001-05-12 19:46:35 -03:00
|
|
|
#endif /* !TARGET_API_MAC_OSX */
|