In addition to the samples produced by the IronPython team below, another nice site to look for IronPython code is http://www.ironpython.info
. This website is driven by the IronPython community.
Samples Download Pages
Overview of Samples
This sample, written by Dino Viehland, is a sample paint program built upon the Windows Presentation Foundation framework in C#. What distinguishes this paint application from others is it's use of Microsoft .NET 4.0's Dynamic Language Runtime (DLR) feature. The DLR is utilized to dynamically and programmatically modify visual objects within the paint canvas. Such a feat is extremely difficult to accomplish with statically typed languages, and the DLR makes this a breeze to implement for Python. The readme.htm in the download will get you started.NOTE
This sample works with IronPython 2.6.1 (for .NET 4.0) and higher.
IronPython Windows Forms Tutorial (WinFormsMapPoint)
This tutorial, written by Martin Schray, consists of a set of IronPython programs that show how to use the Windows controls found within System.Windows.Forms. These IronPython tutorial programs vary greatly in functionality and include:
- Several “Hello World” applications showing how to leverage core Windows forms classes
- An application with an embedded web browser
- A small application based on Windows MapPoint Web Services that provides a map, given a location
- Another application based on MapPoint that lets the user get a route map given start and end points
The tutorial.htm file in the download will get you started. This sample builds from simple "Hello World" applications to a web browser application and finally to a mapping application.
DiskUse - Graphical Disk Usage Utility
This utility written by Jocelyn Turcotte is an IronPython program that leverages Windows Presentation Foundation (WPF) and System.Windows.Forms to create a handy utility that graphically displays disk usage information. The readme.htm file in the download will get you started.
When the application is first launched, a file dialog prompts you to pick a base directory. This is the directory that will be analyzed. Once a base directory is chosen, the application scans the file system to retrieve the names and sizes of subdirectories and files. The utility displays the directory and file information with a treeview in the left pane and a graphical presentation of the relative file size information in the right pane.
This sample written by Ravi Chugh is an IronPython program that builds on top of System.Windows.Forms to create a fun slide puzzle game using maps. The readme.htm file in the download will get you started. The puzzle game comes with several maps (games) that you can start with. If you want more challenging maps, Slide Local gives you the ability to choose or create your own map to play with.
The map tiles the program uses are pulled from Virtual Earth tile servers using the System.Net APIs. If the caching option is selected, all downloaded map tiles are saved to the file system, allowing tiles to be rendered much faster the second time around. Enabling caching also allows you to continue to play games when you don’t have a network connection. Keep an eye on the size of the cache folder though since there is no size limit.
This sample, written by Matt Gruskin, is a frequency modulation synthesizer that uses DirectX and System.Windows.Forms. The readme.htm in the download will get you started.
In the FMSynth UI you can quickly generate tones by clicking on the provided piano keyboard or take more control by specifying a precise frequency and wave type. You can combine several carrier and modulator wave forms together to form more complex musical sounds and effects. You can save your “synth” in an XML file. FMSynth also comes with several sample synth files in the “synths” subfolder which you can load and experiment with.
This sample, written by Brad Dodson, is a music player written in IronPython that uses DirectShow, Windows Presentation Foundation, and COM Interop. The readme.htm in the download will get you started.
When launched, IronTunes presents you with a graphical interface from which you can load any number of music files and begin playing them. Further, you can search through your loaded music collection by typing inside the search field and see your playlist filtered as you type. IronTunes provides the basic playback functionality (play, pause, volume control) by using DirectShow COM APIs from IronPython via COM interop.NOTE
This sample does not work with IronPython 2.0.x sample.
PowerShell from IronPython (IPPowerShell)
This sample shows how to use PowerShell commands from IronPython by invoking the PowerShell API(s) directly and also by using a nice Python helper class. The samples use both of these techniques to detect whether a host meets some of the minimum system requirements for playing Age of Empires III Trial edition. The readme.htm in the download will get you started.
By utilizing managed PowerShell API(s) from IronPython, it becomes downright easy to perform a runtime inspection of the system. As an example, you can determine how much memory your video card has installed on it using only a couple lines of IronPython code. To make working with PowerShell even easier, the “powershell.py” module (included with this sample) allows you to run PowerShell cmdlets in a very elegant and object-oriented manner.
Pyc - Python Command-Line Compiler
This sample shows developers how to create .NET executables directly out of IronPython scripts. The readme.htm in the download will get you started.
IronPython’s Hosting APIs can be used to compile Python scripts into DLLs, console executables, or Windows executables. The pyc.py script included in this tutorial leverages these hosting APIs and can be used to compile other Python scripts. It provides a variety of flags such as the ability to specify the target platform of the .NET assembly (e.g., x64).
While the assemblies produced by the IronPython Hosting APIs are true .NET assemblies, the dynamic nature of the Python language makes it difficult to use these from other .NET languages. In short, this means that attempting to import Python types into other .NET languages such as C# is not recommended.NOTE
This sample is not available with IronPython 2.6 and higher as it was incorporated directly into IronPython releases as a tool.
3D Graphics in IronPython (Direct3D)
This sample, written by Lee Culver, provides a step-by-step, comprehensive tutorial on creating graphical applications using managed DirectX API(s) from IronPython. It will teach you how to:
- Load and render DirectX meshes
- Position, rotate, and move objects
- Auto-track objects with cameras
The readme.htm in the download is quintessential to understanding this sample. It is written in tutorial format and walks you through various exercises that teach you DirectX API manipulation and usage. You do not need prior knowledge of DirectX or WinForms to follow the tutorial, although having some basic Python knowledge is highly advisable. By the time you finish with the tutorial, you should be able to comfortably work with basic Direct3D classes from Python.NOTE
There is one noteworthy issue that will affect PCs which had the August 2006 DirectX SDK installed. In a nutshell, managed DirectX 2.0 is not removed from the global assembly cache by the SDK's uninstall program and the 2.0 assembly has precedence over managed DirectX 1. This causes problems as this sample needs the managed DirectX 1.0 assembly. To circumvent this, it will be necessary to specify the DirectX assembly to use by name throughout the sample IronPython files. Instructions on doing this can be found in the Prerequisites
section of the readme.htm distributed with the sample.
Dynamic Web Service Helpers
This sample is primarily intended to show how web services can be consumed from IronPython in an easy-to-use manner. Included is the “Dynamic Web Service Helpers” library which is utilized to achieve this. Another objective is to illustrate how attribute injectors are used. The readme.htm in the download will get you started.
Distributed with this sample are seven IronPython web service consumer scripts which vary greatly in functionality. For example, the simplest script utilizes an ASP.NET example web service which adds two numbers together. Amazon.py on the other hand is a little more complex in that it connects to www.amazon.com and performs a search on books. It should be noted that several of the scripts require you to obtain your own web service subscriptions to run them. Details on this are in the readme.htm
Not only will this sample show you how to utilize Word's spell checking functionality from IronPython; it'll also make your own Python code better! You see, this sample processes Python files looking for code comments that contain misspellings. Once these mistakes have been identified Word is utilized again to present you with the correct spellings. All of this is tied together with an elegant, user-friendly interface constructed from .NET's Windows Presentation Framework.
The ClrType sample shows how to define a class in IronPython with required CLR members. Normally, a class definition in Python does not map directly to a unique CLR type. This is because the semantics of classes are different between Python and the CLR. For example, in Python it is possible to change the base types just by assigning to the
attribute on the type object. However, the same is not possible with CLR classes. Hence, IronPython implements Python classes without mapping them directly to CLR types. Using the ClrType sample you’ll be able to define CLR fields, properties, class-level attributes, and declare strongly-typed methods.