||Home| |New Reviews| |Software Methodologies| |Popular Science| |AI/Machine Learning| |Programming| |Java| |XML| |Software Tools| |Web| |Tutorials| |Other| |All By Date| |All By Title||
In part one we looked at the .NET implementation of Python called IronPython, focussing on how it marries the Python language and libraries with Microsoft's .NET framework. The sample code that was developed used the Python console (ipy) and a text editor - in other words with simple text-based tools for writing short scripts. But for bigger projects, or when coding GUIs, a text editor obviously isn't enough. Which is a roundabout way of introducing IronPython Studio - a complete (and free) IDE for IronPython, including GUI design tools, a debugger and much more.
IronPython Studio is based on Microsoft's free Visual Studio 2008 Shell runtime. It requires .Net Framework 3.5 and the Visual Studio 2008 Shell (isolated mode) Redistributable (both available as downloads from Microsoft), as well as the installer which can be downloaded from http://www.codeplex.com/IronPythonStudio. In addition to the IDE, it also includes version 1.1.0 of the IronPython interpreter. As it uses isolated mode, IronPython Studio doesn't interfere with existing installations of Visual Studio 2005 or 2008. It's also worth noting that it's an open source project (released under the Microsoft Public License), and that the source code is also available for download.
Visually it presents a familiar look and feel and those who've ever used other versions of Visual Studio should feel quite at home. The usual array of tools bars, dockable controls, editors, navigation bars and the like are all present and correct. Clicking on New Project opens a dialog which offers a choice from four pre-defined templates: Class Library, Console Application, Windows Application and WPF Application. These latter choices providing the opportunity to code IronPython applications with a GUI front end.
WinForms applications are handled in the usual Visual Studio style, offering both a design view (with controls that can be dragged and dropped into place on a container, property grids where you can view and set properties etc), and a code view where you can edit code. The editor provides the usual functionality - syntax colouring, Intellisense, code navigation functions, error highlighting, bookmarking and so on. It makes creating Python applications for the .NET platform very straightforward, particularly for those developers already versed in the ways of Visual Studio.
Registering event handlers for widgets, for example, is as simple as assigning the handler to the widget. For example a button click handler can be assigned as follows:
self._button1.Click += self._button1_ClickHandler
This is a reference to the bit of Python code that will be called when the button is clicked. IronPython Studio even creates the skeleton code for you when you add a widget to your GUI. Dragging and dropping a button on a form generates the skeleton handler code:
@accepts(Self(), System.Object, System.EventArgs) @returns(None) def _button1_Click(self, sender, e): pass
The pass statement is a do nothing command, so replace it with the code to perform the action required. Other widgets are as easy to access and program. For example to grab a list of Excel workbooks in a directory that's entered in a text box and then dump them into a list box on the click of a button we can add the following code to the button click event:
@accepts(Self(), System.Object, System.EventArgs) @returns(None) def _button1_Click(self, sender, e): import glob wkbs = glob.glob(self._textBox1.Text) self._wkbList.Items.Clear() for w in wkbs: self._wkbList.Items.Add(w)
As previously mentioned WinForms aren't the only GUI option, and there's support for Windows Presentation Foundation (WPF) included as well. This includes editor support for XML, necessary for the editing of XAML files which define the GUI components. The IDE provides both a design view and a XAML view, so that widgets can be dragged onto a container and the XAML is updated automatically. And it's a two way process, edits to the XAML are rendered in the design view.
Debugging is very straightforward, with all of the normal debugging functionality provided for - stepping through code, setting breakpoints and watches, viewing debug output, local variables and so on. In practice this is one area of IronPython Studio that is prone to tip, but then this seems a bit ropey even in Visual Studio 2005 for more complex applications.
Deployment and builds are also handled within the IDE, which means that it's possible to create an IronPython application which can be packaged as an exe and distributed along with the IronPython dll files for deployment. Multiple build types can be defined for a project and these can be built, rebuilt or cleaned - dynamically or in batches.
Another thing worth noting is the facility to have an IronPython interpreter session open in a dockable window, which is kind of nice for those who like to try things out interactively and then paste the code into their projects. For seasoned Pythonistas this is very much in the glad to have category.
Other nice features include a server and database explorer, and there is also a snippets manager, so that you can template bits of code for easy insertion into your applications.
In all, IronPython Studio compares provides a pretty good environment for developing Python applications for the .NET platform. At the moment there's a lot of focus on dynamic or scripting languages - such as Python, Ruby and Groovy - exploiting the Java platform, but the existence of IronPython and IronRuby shows that .NET isn't about to be left behind - and IronPython Studio provides some much needed tool support in this area.