![]() |
Desktop Development »
Edit Controls »
General
Intermediate
License: The MIT License
IronTextBox2By JoeSoxA CLI control for IronPython 2.0B2+. |
C# (C# 1.0, C# 2.0, C# 3.0), Python (IronPython), Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||


As of this writing, IronPython version 2 (IP2) is now in beta after months of alpha builds so I decided it was safe enough to start on the next version of IronTextBox to work with IP2. If you are working with IP1.1, here is the version of IronTextBox that will work with IP1.1. Many new IronPython users often ask how to host an IronPythonEngine within a Form, or for simple out of the box code to look at. I first created IronTextBox when IronPython was rather new. Since then, many improvements and other development tools have been developed by Microsoft to help dissect Python code, like IronPython Studio. IronTextBox is still pretty handy because you can quickly browse to one Python file on the fly and get it running in the CLI.
|
IronTextBox was designed to be a CLI-like control to be drag-n-dropped into a Form or other .NET controls.
|
|
Too much has changed from IronPython 1.1 but one of the biggest changes in my mind is the PythonEngine and running Python code. IP2 is more centered around the namespace Microsoft.Scripting. So, you can not easily create a PythonEngine object and start running. In IronTextBox, I created three methods which pretty much handle the main things that need to happen and to easily replace IronTextBox version 1 code:
/// Executes the Python file within the IronTextBox environment.
/// A nice way to quickly get a Python module in CLI to test or use.
object DoIPExecuteFile(string pyfile)
{
ScriptSource source = engine.CreateScriptSourceFromFile(pyfile);
return source.Execute(scope);
}
/// Executes the code in SourceCodeKind.SingleStatement to fire the command event
/// Use DoIPEvaluate if you do not wish to fire the commandevent
object DoIPExecute(string pycode)
{
ScriptSource source = engine.CreateScriptSourceFromString(pycode,
SourceCodeKind.SingleStatement);
return source.Execute(scope);
}
/// Executes the code in SourceCodeKind.Expression not to fire the command event
/// Use DoIPExecute if you do wish to fire the commandevent
object DoIPEvaluate(string pycode)
{
ScriptSource source = engine.CreateScriptSourceFromString(pycode,
SourceCodeKind.Expression);
return source.Execute(scope);
}
Here are some details on what's new in each file:
//Paths.cs - version 2.0.2.0b
//
// WHAT'S NEW:
// - Updated IronPython_Tutorial to point to IronPython 2.0B2 path
// - Added Python25Dirs
////////////////////////////////////
//IronTextBox.cs - version 2.0.2.0b
//WHAT'S NEW:
// -IronPython 2.0B2 Support
// -Removed ParsetheText() since IronPython.Compiler.Ast removed in IP2SimEnter();
// -Added DoIPExecuteFile(), DoIPExecute(), DoIPEvaluate()
////////////////////////////////////
When using IronTextBox, your executable directory must contain:
Just add references to these in your project and set Properties for Copy Local to True. All of these files (besides IronTextBox.dll, of course) is found in the IronPython 2.0B2 download.
Tip: try including the files above if you receive the following exception: "Microsoft.Scripting.InvalidImplementationException : Type 'IronPython.Runtime.PythonContext' doesn't provide a suitable public constructor or its implementation is faulty."
Environment.SpecialFolder.MyDocuments + @"\Visual Studio 2008\Projects\IronPython-2.0B2\Tutorial" in the project. However, I have implemented an OpenFileDialog to correct any incorrect paths. If you are new to IronPython, you may run the IronTextBox command 'runfile' and then browse to IronPython-2.0B2\Tutorial\first.py; notice how you may use add, factorial, and print hi. You can run a 'dir()' command to see what is available.
IronTextBox v2 can be dropped into a Form to provide a Command Line Interface (CLI) with IronPython 2.0B2. The previous version of IronTextBox works with IP1.1. IronTextBox also displays ways to work with IronPython 2.0B2.
| You must Sign In to use this message board. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 20 Jun 2008 Editor: Smitha Vijayan |
Copyright 2008 by JoeSox Everything else Copyright © CodeProject, 1999-2009 Web22 | Advertise on the Code Project |