Interactive Console for Win32 Application
Fredrik Lundh
fredrik at pythonware.com
Sun Sep 19 05:37:54 EDT 2004
Devrim Erdem wrote:
> I am on win32 with python2.2.
>
> My python added C++ app is an OpenGL application so there is no real
> GUI code around it. I have built in the python interpreter which works
> very great. I would like to have the opportunity to popup a console
> from my application which has access to the python module which is
> defined and instantiated in my application.
>
> If I had the time, I would implement a Quake like console. To save
> time, I wanted to check if there is already a way of doing this on
> Windows.
I'll leave it to you to write the code that reads a line from the user, but
once you have that in place, the "code" module provides the rest:
http://www.python.org/doc/current/lib/module-code.html
outline:
console = code.InteractiveConsole()
myconsole = DisplayMyConsole(callback=console.push)
sys.stdout = myconsole.get_output_handler(WHITE)
sys.stderr = myconsole.get_output_handler(RED)
myconsole.enter_event_loop()
(where the callback argument is called whenever the user enters a new
line, and get_output_handler returns a file-like object that prints to the
console window (it must implement a "write" method, but that's about
it).
</F>
More information about the Python-list
mailing list