[IronPython] WinForms UserComponent binding a IronPythonConsole

Jon Cooper Jon.Cooper at arrowgrass.com
Wed Jan 23 20:43:15 CET 2008


Aha. I've answered my own question. One needs to set the output stream's position to the beginning of the stream, i.e.:

        public String handleInput(String inputLine)
        {
            // execute
            python.ExecuteToConsole(inputLine + Environment.NewLine);
            pythonOutputStream.Position = 0;
            String returnValue = pythonReader.ReadToEnd();
            return returnValue;
        }


From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Jon Cooper
Sent: 23 January 2008 19:24
To: Discussion of IronPython
Subject: Re: [IronPython] WinForms UserComponent binding a IronPythonConsole

Thanks. I apologize for this followup, as it's not really a question about IronPython, but on the off chance someone else has dealt with this issue I post it here.

I've PythonEngine.SetStandardOutput to an instance of a MemoryStream, and then created a StreamReader off of that MemoryStream.

When I execute Python code with ExecuteToConsole, I get output in my MemoryStream (I can see it by looking in the buffer in the debugger), but my StreamReader doesn't believe it has data from the MemoryStream (StreamReader.EndOfStream = true, Peek() returns nothing, etc). Is this some kind of flushing issue?

Any help would be fantastic. I'm nearly there!

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dino Viehland
Sent: 23 January 2008 17:29
To: Discussion of IronPython
Subject: Re: [IronPython] WinForms UserComponent binding a IronPythonConsole

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

Hello,

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?

Thanks,

jon

________________________________
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.

________________________________
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.

________________________________
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/08c873f1/attachment.html>


More information about the Ironpython-users mailing list