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 ...@@ -5,8 +5,11 @@ GUSISetupFactories
__vt__15GUSISIOUXDevice # GUSISIOUXDevice::__vt __vt__15GUSISIOUXDevice # GUSISIOUXDevice::__vt
__vt__15GUSISIOUXSocket # GUSISIOUXSocket::__vt __vt__15GUSISIOUXSocket # GUSISIOUXSocket::__vt
sInstance__15GUSISIOUXDevice # GUSISIOUXDevice::sInstance sInstance__15GUSISIOUXDevice # GUSISIOUXDevice::sInstance
sInstance__15GUSISIOUXSocket # GUSISIOUXSocket::sInstance initialized__15GUSISIOUXSocket # GUSISIOUXSocket::initialized
__dt__15GUSISIOUXDeviceFv # GUSISIOUXDevice::~GUSISIOUXDevice() __dt__15GUSISIOUXDeviceFv # GUSISIOUXDevice::~GUSISIOUXDevice()
PyMac_DummyWriteHandler
PyMac_DummyReadHandler
PyMac_SetConsoleHandler
GUSISetupConsoleDescriptors GUSISetupConsoleDescriptors
open__15GUSISIOUXDeviceFR13GUSIFileTokeni # GUSISIOUXDevice::open(GUSIFileToken&,int) open__15GUSISIOUXDeviceFR13GUSIFileTokeni # GUSISIOUXDevice::open(GUSIFileToken&,int)
Want__15GUSISIOUXDeviceFR13GUSIFileToken # GUSISIOUXDevice::Want(GUSIFileToken&) Want__15GUSISIOUXDeviceFR13GUSIFileToken # GUSISIOUXDevice::Want(GUSIFileToken&)
...@@ -20,8 +23,8 @@ write__15GUSISIOUXSocketFRC12GUSIGatherer # GUSISIOUXSocket::write(const GUSIGa ...@@ -20,8 +23,8 @@ write__15GUSISIOUXSocketFRC12GUSIGatherer # GUSISIOUXSocket::write(const GUSIGa
read__15GUSISIOUXSocketFRC13GUSIScatterer # GUSISIOUXSocket::read(const GUSIScatterer&) read__15GUSISIOUXSocketFRC13GUSIScatterer # GUSISIOUXSocket::read(const GUSIScatterer&)
__dt__15GUSISIOUXSocketFv # GUSISIOUXSocket::~GUSISIOUXSocket() __dt__15GUSISIOUXSocketFv # GUSISIOUXSocket::~GUSISIOUXSocket()
Initialize__15GUSISIOUXSocketFv # GUSISIOUXSocket::Initialize() Initialize__15GUSISIOUXSocketFv # GUSISIOUXSocket::Initialize()
__ct__15GUSISIOUXSocketFv # GUSISIOUXSocket::GUSISIOUXSocket() __ct__15GUSISIOUXSocketFi # GUSISIOUXSocket::GUSISIOUXSocket(int)
Instance__15GUSISIOUXSocketFv # GUSISIOUXSocket::Instance() Instance__15GUSISIOUXSocketFi # GUSISIOUXSocket::Instance(int)
Py_FileSystemDefaultEncoding Py_FileSystemDefaultEncoding
_PyBuiltin_Init _PyBuiltin_Init
_PyEval_SliceIndex _PyEval_SliceIndex
......
...@@ -5,8 +5,11 @@ GUSISetupFactories ...@@ -5,8 +5,11 @@ GUSISetupFactories
__vt__15GUSISIOUXDevice # GUSISIOUXDevice::__vt __vt__15GUSISIOUXDevice # GUSISIOUXDevice::__vt
__vt__15GUSISIOUXSocket # GUSISIOUXSocket::__vt __vt__15GUSISIOUXSocket # GUSISIOUXSocket::__vt
sInstance__15GUSISIOUXDevice # GUSISIOUXDevice::sInstance sInstance__15GUSISIOUXDevice # GUSISIOUXDevice::sInstance
sInstance__15GUSISIOUXSocket # GUSISIOUXSocket::sInstance initialized__15GUSISIOUXSocket # GUSISIOUXSocket::initialized
__dt__15GUSISIOUXDeviceFv # GUSISIOUXDevice::~GUSISIOUXDevice() __dt__15GUSISIOUXDeviceFv # GUSISIOUXDevice::~GUSISIOUXDevice()
PyMac_DummyWriteHandler
PyMac_DummyReadHandler
PyMac_SetConsoleHandler
GUSISetupConsoleDescriptors GUSISetupConsoleDescriptors
open__15GUSISIOUXDeviceFR13GUSIFileTokeni # GUSISIOUXDevice::open(GUSIFileToken&,int) open__15GUSISIOUXDeviceFR13GUSIFileTokeni # GUSISIOUXDevice::open(GUSIFileToken&,int)
Want__15GUSISIOUXDeviceFR13GUSIFileToken # GUSISIOUXDevice::Want(GUSIFileToken&) Want__15GUSISIOUXDeviceFR13GUSIFileToken # GUSISIOUXDevice::Want(GUSIFileToken&)
...@@ -20,8 +23,8 @@ write__15GUSISIOUXSocketFRC12GUSIGatherer # GUSISIOUXSocket::write(const GUSIGa ...@@ -20,8 +23,8 @@ write__15GUSISIOUXSocketFRC12GUSIGatherer # GUSISIOUXSocket::write(const GUSIGa
read__15GUSISIOUXSocketFRC13GUSIScatterer # GUSISIOUXSocket::read(const GUSIScatterer&) read__15GUSISIOUXSocketFRC13GUSIScatterer # GUSISIOUXSocket::read(const GUSIScatterer&)
__dt__15GUSISIOUXSocketFv # GUSISIOUXSocket::~GUSISIOUXSocket() __dt__15GUSISIOUXSocketFv # GUSISIOUXSocket::~GUSISIOUXSocket()
Initialize__15GUSISIOUXSocketFv # GUSISIOUXSocket::Initialize() Initialize__15GUSISIOUXSocketFv # GUSISIOUXSocket::Initialize()
__ct__15GUSISIOUXSocketFv # GUSISIOUXSocket::GUSISIOUXSocket() __ct__15GUSISIOUXSocketFi # GUSISIOUXSocket::GUSISIOUXSocket(int)
Instance__15GUSISIOUXSocketFv # GUSISIOUXSocket::Instance() Instance__15GUSISIOUXSocketFi # GUSISIOUXSocket::Instance(int)
Py_FileSystemDefaultEncoding Py_FileSystemDefaultEncoding
_PyBuiltin_Init _PyBuiltin_Init
_PyEval_SliceIndex _PyEval_SliceIndex
......
...@@ -30,6 +30,12 @@ ...@@ -30,6 +30,12 @@
#include "macglue.h" #include "macglue.h"
extern Boolean SIOUXUseWaitNextEvent; 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 { class GUSISIOUXSocket : public GUSISocket {
public: public:
~GUSISIOUXSocket(); ~GUSISIOUXSocket();
...@@ -42,14 +48,12 @@ virtual int fstat(struct stat * buf); ...@@ -42,14 +48,12 @@ virtual int fstat(struct stat * buf);
virtual int isatty(); virtual int isatty();
bool select(bool * canRead, bool * canWrite, bool *); bool select(bool * canRead, bool * canWrite, bool *);
static GUSISIOUXSocket * Instance(); static GUSISIOUXSocket * Instance(int fd);
private: private:
static GUSISIOUXSocket * sInstance; GUSISIOUXSocket(int fd);
static bool initialized;
GUSISIOUXSocket(); static void Initialize();
bool initialized; int fFd;
void Initialize();
bool fDelayConsole;
}; };
class GUSISIOUXDevice : public GUSIDevice { class GUSISIOUXDevice : public GUSIDevice {
public: public:
...@@ -63,28 +67,19 @@ private: ...@@ -63,28 +67,19 @@ private:
static GUSISIOUXDevice * sInstance; static GUSISIOUXDevice * sInstance;
}; };
GUSISIOUXSocket * GUSISIOUXSocket::sInstance;
GUSISIOUXSocket * GUSISIOUXSocket::Instance() GUSISIOUXSocket * GUSISIOUXSocket::Instance(int fd)
{ {
if (!sInstance) return new GUSISIOUXSocket(fd);
if (sInstance = new GUSISIOUXSocket)
sInstance->AddReference();
return sInstance;
} }
// This declaration lies about the return type // This declaration lies about the return type
extern "C" void SIOUXHandleOneEvent(EventRecord *userevent); extern "C" void SIOUXHandleOneEvent(EventRecord *userevent);
GUSISIOUXSocket::GUSISIOUXSocket() bool GUSISIOUXSocket::initialized = false;
GUSISIOUXSocket::GUSISIOUXSocket(int fd) : fFd(fd)
{ {
if (PyMac_GetDelayConsoleFlag()) if (!PyMac_GetDelayConsoleFlag() && !hasCustomConsole() && !initialized)
fDelayConsole = true;
else
fDelayConsole = false;
if ( fDelayConsole )
initialized = 0;
else
Initialize(); Initialize();
/* Tell the upper layers there's no unseen output */ /* Tell the upper layers there's no unseen output */
PyMac_OutputSeen(); PyMac_OutputSeen();
...@@ -93,24 +88,39 @@ GUSISIOUXSocket::GUSISIOUXSocket() ...@@ -93,24 +88,39 @@ GUSISIOUXSocket::GUSISIOUXSocket()
void void
GUSISIOUXSocket::Initialize() GUSISIOUXSocket::Initialize()
{ {
initialized = 1; if(!initialized && !hasCustomConsole())
InstallConsole(0); {
GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent); initialized = true;
GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent); InstallConsole(0);
GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent); GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent); GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent); GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent); GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent); GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent);
PyMac_InitMenuBar(); GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent);
GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent);
PyMac_InitMenuBar();
}
} }
GUSISIOUXSocket::~GUSISIOUXSocket() GUSISIOUXSocket::~GUSISIOUXSocket()
{ {
if ( !initialized ) return; if ( !initialized || hasCustomConsole() )
return;
initialized = false;
RemoveConsole(); RemoveConsole();
} }
ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer) 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(); if ( !initialized ) Initialize();
GUSIStdioFlush(); GUSIStdioFlush();
PyMac_OutputSeen(); PyMac_OutputSeen();
...@@ -121,6 +131,16 @@ ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer) ...@@ -121,6 +131,16 @@ ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer)
} }
ssize_t GUSISIOUXSocket::write(const GUSIGatherer & 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; ssize_t rv;
if ( !initialized ) Initialize(); if ( !initialized ) Initialize();
...@@ -198,14 +218,33 @@ bool GUSISIOUXDevice::Want(GUSIFileToken & file) ...@@ -198,14 +218,33 @@ bool GUSISIOUXDevice::Want(GUSIFileToken & file)
} }
GUSISocket * GUSISIOUXDevice::open(GUSIFileToken &, int) GUSISocket * GUSISIOUXDevice::open(GUSIFileToken &, int)
{ {
return GUSISIOUXSocket::Instance(); return GUSISIOUXSocket::Instance(1);
} }
void GUSISetupConsoleDescriptors() void GUSISetupConsoleDescriptors()
{ {
GUSIDescriptorTable * table = GUSIDescriptorTable::Instance(); GUSIDescriptorTable * table = GUSIDescriptorTable::Instance();
GUSISIOUXSocket * SIOUX = GUSISIOUXSocket::Instance();
table->InstallSocket(SIOUX); table->InstallSocket(GUSISIOUXSocket::Instance(0));
table->InstallSocket(SIOUX); table->InstallSocket(GUSISIOUXSocket::Instance(1));
table->InstallSocket(SIOUX); 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