views:

278

answers:

4

Hi,

I'd like to add "IDLE-like functionality" to C# WinForms application, but I don't quite have an idea how to do that and couldn't find anything useful with Google.

So basically I want interactive command line interface, where user could enter some Python code and execute it (not just expressions, should be possible to define new functions).

So, where to start? Are there any good tutorials or samples available?

+1  A: 

If my memory serves me correctly there's a chapter on embedding Python in the book Python in a Nutshell. Perhaps you can find some useful information there, but since the book is not Windows specific, you may have to adapt it yourself.

Brian Rasmussen
I think this is pretty .NET specific issue, so CPython related information is basically useless.
Harriv
You're probably right. To be honest I don't know how much will carry over from CPython to IronPython in that respect.
Brian Rasmussen
And I don't think so. Syntax and most libraries are same.
Migol
Of course the language is same, but backend is completely different.
Harriv
A: 

IronRuby comes with a command line interpreter. Doesn't IronPython also have one? If so, the source code would be a good start :) Oh, and if it doesn't, be sure to look at the IronRuby interpreter, because both languages are based on the DLR and are therefore similar enough to learn from both.

OregonGhost
It is text mode application, is the IronPyhton interpreter embedded to WinForms application?
Harriv
The IronRuby interpreter runs on the command line. I don't know how the IronPython interpreter, if available, works, but I suggest just looking for it in the IronPython distribution. There's nothing wrong with just looking for what you're looking for.
OregonGhost
+1  A: 

I would setyp my WinForm like this: add 2 textboxes.

1: for output. Set the multiline property of the first to true, and make it read only.

2: for input. Use KeyUp Or KeyPress Event for e.g. the return key and use the text to do what you want: add command to output textbox, launch code against the engine and capture output of interpreter

This link (http://groups.google.com/group/ironpy/browse_thread/thread/5e61a944c7c94d4b/0cbf29ec0f5fbb64?pli=1) might give some answers about launching commands agains a python engine.

dampee
A: 

Thru IronPython mailing list I found IronTextBox2, which is good example how things are done. It needs a little tweaking, to get it running, but otherwise is good solution.

Harriv