Commit a0472f73 authored by Jack Jansen's avatar Jack Jansen

Mods by Alexandre Parenteau to allow embedding programs to disable the...

Mods by Alexandre Parenteau to allow embedding programs to disable the MacPython console window completely, and optionally route console output (and input) to routines provided by the embedding app.

Things don't fully work yet, but at least it doesn't break anything.
parent 509ad424
......@@ -5,8 +5,11 @@ GUSISetupFactories
__vt__15GUSISIOUXDevice # GUSISIOUXDevice::__vt
__vt__15GUSISIOUXSocket # GUSISIOUXSocket::__vt
sInstance__15GUSISIOUXDevice # GUSISIOUXDevice::sInstance
sInstance__15GUSISIOUXSocket # GUSISIOUXSocket::sInstance
initialized__15GUSISIOUXSocket # GUSISIOUXSocket::initialized
__dt__15GUSISIOUXDeviceFv # GUSISIOUXDevice::~GUSISIOUXDevice()
PyMac_DummyWriteHandler
PyMac_DummyReadHandler
PyMac_SetConsoleHandler
GUSISetupConsoleDescriptors
open__15GUSISIOUXDeviceFR13GUSIFileTokeni # GUSISIOUXDevice::open(GUSIFileToken&,int)
Want__15GUSISIOUXDeviceFR13GUSIFileToken # GUSISIOUXDevice::Want(GUSIFileToken&)
......@@ -20,8 +23,8 @@ write__15GUSISIOUXSocketFRC12GUSIGatherer # GUSISIOUXSocket::write(const GUSIGa
read__15GUSISIOUXSocketFRC13GUSIScatterer # GUSISIOUXSocket::read(const GUSIScatterer&)
__dt__15GUSISIOUXSocketFv # GUSISIOUXSocket::~GUSISIOUXSocket()
Initialize__15GUSISIOUXSocketFv # GUSISIOUXSocket::Initialize()
__ct__15GUSISIOUXSocketFv # GUSISIOUXSocket::GUSISIOUXSocket()
Instance__15GUSISIOUXSocketFv # GUSISIOUXSocket::Instance()
__ct__15GUSISIOUXSocketFi # GUSISIOUXSocket::GUSISIOUXSocket(int)
Instance__15GUSISIOUXSocketFi # GUSISIOUXSocket::Instance(int)
Py_FileSystemDefaultEncoding
_PyBuiltin_Init
_PyEval_SliceIndex
......
......@@ -5,8 +5,11 @@ GUSISetupFactories
__vt__15GUSISIOUXDevice # GUSISIOUXDevice::__vt
__vt__15GUSISIOUXSocket # GUSISIOUXSocket::__vt
sInstance__15GUSISIOUXDevice # GUSISIOUXDevice::sInstance
sInstance__15GUSISIOUXSocket # GUSISIOUXSocket::sInstance
initialized__15GUSISIOUXSocket # GUSISIOUXSocket::initialized
__dt__15GUSISIOUXDeviceFv # GUSISIOUXDevice::~GUSISIOUXDevice()
PyMac_DummyWriteHandler
PyMac_DummyReadHandler
PyMac_SetConsoleHandler
GUSISetupConsoleDescriptors
open__15GUSISIOUXDeviceFR13GUSIFileTokeni # GUSISIOUXDevice::open(GUSIFileToken&,int)
Want__15GUSISIOUXDeviceFR13GUSIFileToken # GUSISIOUXDevice::Want(GUSIFileToken&)
......@@ -20,8 +23,8 @@ write__15GUSISIOUXSocketFRC12GUSIGatherer # GUSISIOUXSocket::write(const GUSIGa
read__15GUSISIOUXSocketFRC13GUSIScatterer # GUSISIOUXSocket::read(const GUSIScatterer&)
__dt__15GUSISIOUXSocketFv # GUSISIOUXSocket::~GUSISIOUXSocket()
Initialize__15GUSISIOUXSocketFv # GUSISIOUXSocket::Initialize()
__ct__15GUSISIOUXSocketFv # GUSISIOUXSocket::GUSISIOUXSocket()
Instance__15GUSISIOUXSocketFv # GUSISIOUXSocket::Instance()
__ct__15GUSISIOUXSocketFi # GUSISIOUXSocket::GUSISIOUXSocket(int)
Instance__15GUSISIOUXSocketFi # GUSISIOUXSocket::Instance(int)
Py_FileSystemDefaultEncoding
_PyBuiltin_Init
_PyEval_SliceIndex
......
......@@ -30,6 +30,12 @@
#include "macglue.h"
extern Boolean SIOUXUseWaitNextEvent;
static PyReadHandler sInConsole = 0L;
static PyWriteHandler sOutConsole = 0L;
static PyWriteHandler sErrConsole = 0L;
inline bool hasCustomConsole(void) { return sInConsole != 0L; }
class GUSISIOUXSocket : public GUSISocket {
public:
~GUSISIOUXSocket();
......@@ -42,14 +48,12 @@ virtual int fstat(struct stat * buf);
virtual int isatty();
bool select(bool * canRead, bool * canWrite, bool *);
static GUSISIOUXSocket * Instance();
private:
static GUSISIOUXSocket * sInstance;
GUSISIOUXSocket();
bool initialized;
void Initialize();
bool fDelayConsole;
static GUSISIOUXSocket * Instance(int fd);
private:
GUSISIOUXSocket(int fd);
static bool initialized;
static void Initialize();
int fFd;
};
class GUSISIOUXDevice : public GUSIDevice {
public:
......@@ -63,28 +67,19 @@ private:
static GUSISIOUXDevice * sInstance;
};
GUSISIOUXSocket * GUSISIOUXSocket::sInstance;
GUSISIOUXSocket * GUSISIOUXSocket::Instance()
GUSISIOUXSocket * GUSISIOUXSocket::Instance(int fd)
{
if (!sInstance)
if (sInstance = new GUSISIOUXSocket)
sInstance->AddReference();
return sInstance;
return new GUSISIOUXSocket(fd);
}
// This declaration lies about the return type
extern "C" void SIOUXHandleOneEvent(EventRecord *userevent);
GUSISIOUXSocket::GUSISIOUXSocket()
bool GUSISIOUXSocket::initialized = false;
GUSISIOUXSocket::GUSISIOUXSocket(int fd) : fFd(fd)
{
if (PyMac_GetDelayConsoleFlag())
fDelayConsole = true;
else
fDelayConsole = false;
if ( fDelayConsole )
initialized = 0;
else
if (!PyMac_GetDelayConsoleFlag() && !hasCustomConsole() && !initialized)
Initialize();
/* Tell the upper layers there's no unseen output */
PyMac_OutputSeen();
......@@ -93,24 +88,39 @@ GUSISIOUXSocket::GUSISIOUXSocket()
void
GUSISIOUXSocket::Initialize()
{
initialized = 1;
InstallConsole(0);
GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent);
PyMac_InitMenuBar();
if(!initialized && !hasCustomConsole())
{
initialized = true;
InstallConsole(0);
GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent);
PyMac_InitMenuBar();
}
}
GUSISIOUXSocket::~GUSISIOUXSocket()
{
if ( !initialized ) return;
if ( !initialized || hasCustomConsole() )
return;
initialized = false;
RemoveConsole();
}
ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer)
{
if(hasCustomConsole())
{
if(fFd == 0)
return buffer.SetLength(
sInConsole((char *) buffer.Buffer(), (int)buffer.Length()));
return 0;
}
if ( !initialized ) Initialize();
GUSIStdioFlush();
PyMac_OutputSeen();
......@@ -121,6 +131,16 @@ ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer)
}
ssize_t GUSISIOUXSocket::write(const GUSIGatherer & buffer)
{
if(hasCustomConsole())
{
if(fFd == 1)
return sOutConsole((char *) buffer.Buffer(), (int)buffer.Length());
else if(fFd == 2)
return sErrConsole((char *) buffer.Buffer(), (int)buffer.Length());
return 0;
}
ssize_t rv;
if ( !initialized ) Initialize();
......@@ -198,14 +218,33 @@ bool GUSISIOUXDevice::Want(GUSIFileToken & file)
}
GUSISocket * GUSISIOUXDevice::open(GUSIFileToken &, int)
{
return GUSISIOUXSocket::Instance();
return GUSISIOUXSocket::Instance(1);
}
void GUSISetupConsoleDescriptors()
{
GUSIDescriptorTable * table = GUSIDescriptorTable::Instance();
GUSISIOUXSocket * SIOUX = GUSISIOUXSocket::Instance();
table->InstallSocket(SIOUX);
table->InstallSocket(SIOUX);
table->InstallSocket(SIOUX);
table->InstallSocket(GUSISIOUXSocket::Instance(0));
table->InstallSocket(GUSISIOUXSocket::Instance(1));
table->InstallSocket(GUSISIOUXSocket::Instance(2));
}
void PyMac_SetConsoleHandler(PyReadHandler stdinH, PyWriteHandler stdoutH, PyWriteHandler stderrH)
{
if(stdinH && stdoutH && stderrH)
{
sInConsole = stdinH;
sOutConsole = stdoutH;
sErrConsole = stderrH;
}
}
long PyMac_DummyReadHandler(char *buffer, long n)
{
return 0;
}
long PyMac_DummyWriteHandler(char *buffer, long n)
{
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment