When embedding with no natural console...?

Alex Martelli aleaxit at yahoo.com
Tue Feb 20 15:00:49 EST 2001


"Owen F. Ransen" <ransen_spam_me_not at nemo.it> wrote in message
news:3a969ec3.5744237 at news.newsguy.com...
> When embedding with no natural console (I mean that
> the application does not have a console output, it
> is pure GUI) what suggestions are there for printing?

Set the 'stdout' attribute of module 'sys' (PySys_SetObject
may work well for that, but it seems to be undocumented
so I'm not sure it's best; you might do it in Python itself,
executing a small piece of Python source from within your
embedding application) to a "suitable" object -- one that
implements a "suitable" write method, accepting a (buffer)
Python object (and lets Python set and get an attribute
named 'softspace').  It's simplest to do it in Python, with
a small Python class that just directs the argument of that
write method to a module-level function in your module.
(You may want to do the same for the 'stderr' attribute).

Your module-level function may do whatever you see fit --
emit the output with Win32 API "OutputDebugString", use
the event-logging system functions of NT, add it to a real
on-disk file, scroll it on a listbox or other within-a-GUI sort
of "console-alike", etc, etc.

> *) Create some sort of console in the GUI app.
>    Maybe with AllocConsole WriteConsole and
>    FreeConsole...

That's one possibilities, but real consoles don't work all
that well on Win95/Win98 and don't offer many advantages
(wrt a scrolling text window that you can embed/dock/etc
within your GUI) for text-output.

> *) Ridirect output to a log file...
> *) Do not print anything...
> *) Other...

It might be best to let the user choose (by configuration
options, menus, preferences, ...) among these (zero or
more thereof).

> Since my final app will be aimed at beginning programmers
> I think some sort of console output would be nice.

Scrolling text-output (with a long-enough 'history' that is
scrollable backwards, ability to save to a textfile, etc) should
be good enough for that.


Alex






More information about the Python-list mailing list