Click here to Skip to main content
12,692,288 members (35,001 online)
Click here to Skip to main content
Add your own
alternative version


29 bookmarked

IronTextBox - a TextBox and UserControl based console that may be used with IronPython.

, 26 May 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A Short Introduction to IronPython. IronTextBox v1.4.1.0b

Sample Image - irontextbox.jpg


Microsoft's IronPython 1.0 (or try IronPython's main website for the latest release) is a release of the Python programming language for the .NET platform. Below are some of the most important of IronPython's 1.0 namespaces and counting:

namespace IronPython.Compiler;
namespace IronPython.Compiler.Ast;
namespace IronPython.Hosting;
namespace IronPython.Modules;
namespace IronPython.Runtime;
namespace IronPython.Runtime.Exceptions;
namespace IronPython.Runtime.Calls;
namespace IronPython.Runtime.Types;
namespace IronPython.Runtime.Operations;
namespace IronPython.CodeDom;

Please keep in mind that IronPython is written for a CLI platform. I became interested in it after learning about ConceptNet: A Practical Commonsense Reasoning Toolkit written in Python. I started a C# library class for ConceptNet and needed to trace though it. So I then found myself sidetracked by writing this IronTextBox control for myself. It may be useful to others and it may not. However, it is another small introduction into Microsoft's IronPython.

IronTextBox for IronPython 2

This article's IronTextBox is for IronPython 1.1. For the latest version please see


The TextBox control that I developed to help me understand some unfamiliar python code is IronTextbox. I find it useful to see what IronPython's limits are since it is still in its beta stage. Plus IronPython is staged on a CLI platform and this TextBox control creates more of a non-CLI platform. It currently has three namespaces
UIIronTextBox //(the main IronTextBox and IronTextBoxControl namespace) <BR>UIIronTextBox.Paths //(a class to store common paths for the "paths" command) <BR>UIIronTextBox.Utils //(a misc namespace)<BR>UIIronTextBox.IPEWrapper //(a class to handle PythonEngine stream output

Here is a screen capture of the help menu for IronTextBox
IronTextBox Command Help Menu

The Demo

This demo uses a TextBox and UserControl based control that I named IronTextBox. It is to be used with Microsoft's IronPython. There is a bunch of useful methods in Python and IronPython 1.0 does a great job of implementing all of the common ones. Let the record state that I am not an expert at Python nor IronPython but am just learning both at the same time and it is amazing to me the work the IronPython team has done. I created this control to help me evaluate some Python scripts and learn IronPython.
IronPython 1.0 comes with several Console classes but I decided not to use them in this demo because I would have to distribute the classes within the project. Besides, what fun would that be. Also, the IronTextBox can be used as a COM object so anyone may use it to help test their applications. At least that's what I use it for.
I first started out with a TextBox based control then thought a nice color control would be outstanding. I have a very rough draft RichTextBox control still in active development. I may post the project with this article but as I am typing this I have not decided. I had to quit developing the control because I was having coloring problems with strings. I am not that up on my Rtf knowledge so due to me spinning my wheels for a couple of days I decided I was sidetracked and bailed because learning Rtf was not my main goal. So that is why the control in black and white.
I have tried to make the code easy to follow and included as many comments as I could. Therefore, I am time pressed and will not go into depth in this article. Microsoft has plenty of outstanding demos to use, although I understand that it is beta and still does not have much documentation.
Probably the most important thing to know about IronPython's PythonEngine is that it handles Python script by Executing it or Evaluating it. As long as you understand that then learning the rest of IronPython is not that difficult.

In myIronPythonDemo 1.2 try stepping thru some Python code. If you have installed ConceptNet 2.1 (please see my ConceptNet article) click on the "MontyLemmatiser commands" button and this imports MontyREChunker (if your UIIronTextBox.Paths are set correctly) and runs its python method. THIS DEMO WILL ERROR OUT. Set a breakpoint on line 92 in (you may need to run this first for proper results, as of this writing I am not sure why it does not like to run behind one of the other click events)

Here is a screen shot of Microsoft Visual C# Express 2005 debugging a Python module:

If you download the latest release of the
Visual Studio 2005 SDK you may run VS 2005 under it's Experimental Hive which supports IronPython integration. In this mode, it will do Python syntax coloring for you and also auto-indentation.

Below is an incomplete custom MessageBox I wrote to help me debug. It is now located in the UIIronTextBox.Utils namespace.

/// <span class="code-SummaryComment"><summary></span>
/// Custom MessageBox call. Excepts some random objects
/// from IronPython and converts to string.
/// <span class="code-SummaryComment"></summary></span>
/// <PARAM name="inobject">Output object from IronPython.</PARAM>
public void MessageBoxIronPy(Object inobject)
    Type itstype = inobject.GetType();

    switch (itstype.FullName)
        case "IronPython.Runtime.Tuple":
            Tuple IPTuple = new Tuple((Tuple)inobject);
        case "IronPython.Runtime.Dict":
            Dict IPDict = new Dict();
            IPDict = (Dict)inobject;
        case "IronPython.Runtime.List":
            List IPList = new List();
            IPList = (List)inobject;
        case "System.String":
        case "System.Int32":
        case "System.Collections.Specialized.StringCollection":
            StringCollection IPSC = new StringCollection();
            IPSC = (StringCollection)inobject;
            StringEnumerator SCE = IPSC.GetEnumerator();
            string output = "";
            while (SCE.MoveNext())
                output += SCE.Current.ToString();
            (inobject.GetType().ToString() + " not yet implemented.");

Try using the IronTextBox console after running the demo. When it has completed type "first.hi" at the prompt and then press enter. That executes first's hi method and displays its return value in the IronTextBox.

How to Compile and Execute the Demo Application

  1. Make Sure you have downloaded and extracted IronPython 1.0 (or try IronPython's main website for the latest release). FYI: I have hardcoded the IronPython script folder to "Environment.SpecialFolder.MyDocuments + @"\Visual Studio 2005\Projects\IronPython-1.0-RC1\Tutorial"" in the project. However, I have implementated an OpenFileDialog to correct any incorrect paths.
  2. Download and unzip this article's .Net Solution and project files.
  3. From MS VC# 2005 Solution Explorer, Add a Reference by browsing to IronPython.dll and IronMath.dll located where you extracted the IronPython download.
  4. ReBuild both projects in the solution by right-clicking on each project (IronTextBox,myIronPythonDemo)and select ReBuild. The demo should now be able to execute.



IronPython is Microsoft's answer to handling Python script. It is a great resource to use. It lead me to develop this control for myself. I didn't put too much time into it, but feel free to build upon it or use it to test your own IronPython applications. I envisioned version to include a method for browsing to a Python module and running each line through the IronTextBox but I simply ran out of time. I will be implementing this feature and I will update the article at a later date. IronTextBox currently has "btwfi" command to walk thru a python module to see if any errors occur in IronPython.



  • Article and IronTextBox version posted.
  • Organized namespace UIIronTextBox and made the control Visual Studio ToolBox friendly. Now actually acts like an IronPython console after dropping the control into a Form.
  • UIIronTextBox.ConsoleControl is now named UIIronTextBox.IronTextBoxControl
  • Transfered irontextboxControl_CommandEntered and GelpHelpText() from the project demo to the IronTextBox control.
  • UIIronTextBoxControl now accesses public UIIronTextBox.ConsoleEngine global_eng by calling irontextboxControl_CommandEntered.
  • Article project and IronTextBox version uploaded.
  • Some cool new IronTextBox commands added like btaf and btwfi added along with 2 new namespaces(see below).
  • Added Support for loading a Python .py file line-by-line. eg. WalkPythonFile(string fullpathfilename)
  • Added UIIronTextBox.Paths class to store common paths.
  • Added UIIronTextBox.Utils for misc use. eg. MessageBoxIronPy(Object inobject)
  • Added btaf to IronTextBox's internal commands. Appends a folder by first calling FolderBrowserDialog.
  • Added btwfi to IronTextBox's internal commands. Reads a .py line-by-line into IronTextBox by first calling OpenFileDialog.
  • Added paths [-arg] - args: -misc, -python24, -ironpython, -all. Appends all hardcoded common paths stored in UIIronTextBox.Paths
  • IronTextBox.dll version uploaded.
  • Updated the demo application. Now myIronPythonDemo 1.2, supports IronTextBox.dll version 1.1.x
  • Added IronTextBox menu screen shot and screen shot of Python file debugging.
  • Improved IronTextBox: WalkPythonFile(string fullpathfilename) handles """ and # comments properly.
  • Added IronTextBox: DelStmt catch for misc Evaluatations.
  • Added IronTextBox command: rew - Re-Write a Python file into a StringBuilder.(for testing).
  • Added IronTextBox command: runfile - Run a .Py file. Calls OpenFileDialog to run the module by calling PythonEngine.RunFile.
  • BugFix IronTextBox: Misc. IronPython.Compiler.ExprStmt calls getting Evaluated and Executed twice fixed.
  • IronTextBox.dll version uploaded.
  • Added IronTextBox section to the article.
  • Updated the demo application to version
  • Updated IronTextBox.dll to version
  • Updated misc support for IronPython beta8. Many changes to IronPython forced these updates. Previous versions of IronPython are not supported.
  • BugFix: IPEStreamWrapper.sbOutput not clearing. submitted by slide_o_mix. Now IPEStreamWrapper.sbOutput clears directly after displaying if it is a misc command in irontextboxControl_CommandEntered().
  • Uploaded the demo application with new version of IronTextBox
  • Uploaded IronTextBox.dll to version
  • Updated the demo application to version
  • Updated IronTextBox.dll to version
  • Updated support for IronPython RC1.
  • IronTextBox BugFix: 'IronPython.Hosting.EngineModule' does not contain a definition for 'CallerContext'.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Network Administrator
United States United States
Born in Pennsylvania (USA), just north of Philadelphia. Joe has been programming since he was ten[now much older]. He is entirely self-taught programmer, and he is currently working as an IT Manager in Seattle WA. He was previously U.S. Navy Active Reservist for (SPAWAR)
In '98 was honorably discharged from the USN. He served onboard the USS Carl Vinson (94-98) He was lucky enough to drink President Clinton's leftover wine, promoted by his Captain, and flew in a plane off the flightdeck but not all at the same time. His interests, when time allows, are developing
misc apps and Artificial Intelligence proof-of-concept demos that specifically exhibits human behavior. He is a true sports-a-holic, needs plenty of caffeine, and a coding junkie. He also enjoys alternative music and a big Pearl Jam, Nirvana, and new alternative music fan.

Joe is an INTP[^] personality type. Joe "sees everything in terms of how it could be improved, or what it could be turned into. INTP's live primarily inside their own minds." INTPs also can have the "greatest precision in thought and language. Can readily discern contradictions and inconsistencies. The world exists primarily to be understood. 1% of the total population" [

You may also be interested in...


Comments and Discussions

GeneralInstalling Iron Python Pin
carlos chavarriaga13-Aug-08 8:58
membercarlos chavarriaga13-Aug-08 8:58 
GeneralRe: Installing Iron Python Pin
JoeSox13-Aug-08 11:00
memberJoeSox13-Aug-08 11:00 
QuestionTab completion Pin
withak3027-Feb-07 9:04
memberwithak3027-Feb-07 9:04 
AnswerRe: Tab completion Pin
JoeSox27-Feb-07 16:11
memberJoeSox27-Feb-07 16:11 
GeneralRe: Tab completion Pin
adamhill3-Mar-07 21:17
memberadamhill3-Mar-07 21:17 
GeneralRe: Tab completion Pin
JoeSox5-Mar-07 4:46
memberJoeSox5-Mar-07 4:46 
QuestionPrinting in for loop Pin
zmask22-Jan-07 8:55
memberzmask22-Jan-07 8:55 
AnswerRe: Printing in for loop Pin
JoeSox22-Jan-07 15:16
memberJoeSox22-Jan-07 15:16 
GeneralNice Work ! Pin
Martin Gagne9-Aug-06 3:52
memberMartin Gagne9-Aug-06 3:52 
GeneralRe: Nice Work ! Pin
JoeSox9-Aug-06 4:23
memberJoeSox9-Aug-06 4:23 
GeneralRe: IronTextBox v1.4.1.0b posted Pin
JoeSox10-Aug-06 16:31
memberJoeSox10-Aug-06 16:31 
QuestionBug? Pin
slide_o_mix25-Jul-06 12:52
memberslide_o_mix25-Jul-06 12:52 
AnswerRe: Bug Fixed[modified] Pin
JoeSox25-Jul-06 16:35
memberJoeSox25-Jul-06 16:35 
GeneralAlternative to IronPython... Pin
Christian Birkl20-Mar-06 9:06
memberChristian Birkl20-Mar-06 9:06 
NewsYou might be interested in... Pin
leppie14-Mar-06 22:04
memberleppie14-Mar-06 22:04 
GeneralRe: You might be interested in... Pin
JoeSox14-Mar-06 22:18
memberJoeSox14-Mar-06 22:18 
GeneralRe: You might be interested in... Pin
leppie15-Mar-06 4:32
memberleppie15-Mar-06 4:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 27 May 2008
Article Copyright 2006 by JoeSox
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid