Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed a graphical interactive IronPython shell in an application?

I've tried the obvious path in my pet open source project RevitPythonShell (a plugin for the building modeling software Autodesk Revit Architecture 2010): code.interact() with the IronPython engine set up to use .NET streams for STDIN and STDOUT. These I then redirect to a TextBox control. It kinda works, but really is only an ugly hack.

The main problem is getting all the shell stuff to work: Up-arrow and down-arrow for history, editing, copy & paste, EOF, syntax highlighting, tool tips etc. It takes a lot of work to get this right, and it is not really the problem I'm trying to solve (I'm trying to get an interactive shell hosted in Revit, not make the perfect shell GUI).

If this weren't a .NET project, I'd probably look into reusing PyCrust/PyWrap, but I'm not sure if that can be done from a WinForms project. Is there anything similar for .NET?

Has anyone ever implemented the IConsole interface and can show an example of what I'd need to do? It seems this would be the proper route to go (as opposed to using the code module), but for the life of me I can't figure it out. IronPython source code has no comments whatsoever.

UPDATE: After trying out some stuff, I eventually settled on the superb IronLab code. It includes an example shell with syntax highlighting and all. The code was nice and easy to integrate. Check the RevitPythonShell code on hints on how to embed it.

like image 577
Daren Thomas Avatar asked Mar 04 '10 09:03

Daren Thomas


1 Answers

I was looking for a similar thing and I discovered that the IronLab project contains a nice IronPython console. The source code can be found here https://github.com/rwg0/ironlab/tree/master/IronPythonConsole.

[edit on 25/10/2016] fixed broken url

like image 126
Samuel Avatar answered Oct 26 '22 15:10

Samuel