[Pythonmac-SIG] Problem when embedding classic
Jack Jansen
Jack.Jansen@cwi.nl
Mon, 5 Aug 2002 15:05:26 +0200
On Monday, August 5, 2002, at 12:32 , Stefan Petrucha wrote:
> I apologize for this Mac-beginner's problem and for bothering with old
> stuff (Python 2.1.1, classic).
Are you really using 2.1.1, not 2.2.1? And if you really are: why?
> I'm trying to embed Python into a classic application (I succeeded on
> Windows previously). The Mac port partially works, but:
>
> - MacPython opens its own window for standard and error output, which is
> not moveable and does update only when the application calls Python
In 2.2.1 you can make *very* sure that Python will never open a console
window by
using the PyMac_SetConsoleHandler() API defined in macglue.h. You can
pass the
courtesy routines PyMac_DummyReadHandler and PyMac_DummyWriteHandler
also defined there
to completely lose console I/O, or provide your own routines. You can
call PyMac_SetConsoleHandler() even before initializing Python.
Before 2.2.1 there wasn't a 100% safe method to get rid of the console,
only a
99% safe method. In your Python script make sure that no output can go
to the
console, by redirecting sys.stdout and sys.stderr at an early stage.
Also, drop the embedding program on EditPythonPrefs and set the "delay
console
window until needed" flag.
But:
> - redirecting outputs via sys.stdout=MyStream, where MyStream has a
> write method, does not work as on other platforms - MyStream gets
> nothing and Python's output window shows nothing too
this part I don't understand, and my guess is that it's a bug in your
code. I've done a
similar thing various times, and it has always worked....
--
- Jack Jansen <Jack.Jansen@oratrix.com>
http://www.cwi.nl/~jack -
- If I can't dance I don't want to be part of your revolution -- Emma
Goldman -