[IronPython] WinForms UserComponent binding a IronPythonConsole

Dino Viehland dinov at exchange.microsoft.com
Wed Jan 23 18:28:53 CET 2008

Generally speaking you want to do 2 things:

1.       Wire up std out / std err to a stream you can send to your window.  You can do this via PythonEngine.SetStandardOutput/PythonEngine.SetStandardInput.  You could also wire up std-in but that'll be less important (it's only going to matter if someone calls something like raw_input).

2.       When you get input from the user call PythonEngine.ExecuteToConsole("input")

Between those two you should have your console up and running.  The IConsole interface is actually just used by the command line implementation and isn't part of the hosting APIs.  That's why you're not finding it anywhere on the engine - the linked blog came before IronPython 1.0.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Jon Cooper
Sent: Wednesday, January 23, 2008 5:02 AM
To: users at lists.ironpython.com
Subject: [IronPython] WinForms UserComponent binding a IronPythonConsole


I've been enjoying using IronPython.

I'm now going to embed it in my C# WinForms application to provide a way for users to perform simple ad-hoc scripting. Unfortunately this has been less easy than I thought it would be!

I've built a subclass of TextBox that I can use to display and input the text coming to/from my user. Now I just need to connect it to a PythonEngine.

In the article at http://blogs.msdn.com/jmstall/archive/2005/09/01/Howto_embed_ironpython.aspx, one gets the impression that a PythonEngine has a MyConsole property where one can connect an IConsole. Perfect! Unfortunately, that's not the case on my 1.1 build.

Digging through the source I find that this stuff exists on IronPythonConsole, but that class appears to be designed for use statically.

Before I go to the trouble of ripping apart IronPythonConsole and likely reinventing the wheel, is there something I'm missing here?



Arrowgrass Capital Partners (US) LP is a limited partnership registered in the State of Delaware.

This message is for the named person's use only. It may contain confidential, proprietary or legally privileged information. No confidentiality or privilege is waived or lost by any transmission errors. If you receive this message in error, please immediately delete it and all copies of it from your system, destroy any hard copies of it and notify the sender. You must not, directly or indirectly, use, disclose, distribute, print, or copy any part of this message if you are not the intended recipient.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080123/626d9347/attachment.html>

More information about the Ironpython-users mailing list