Monday, August 31, 2009

Developing cross-platform applications with IronPython: GtkBuilder and Glade on IronPython

IronPython is a great cross-platform development language, running on the Microsoft .NET framework for Windows and on Mono just about everywhere.

Even for CPython developers IronPython has a few features that make it of interest. These include:
  • Under IronPython there is no Global Interpreter Lock (GIL) meaning that multi-threaded pure-Python applications can scale across multiple CPUs with no extra work from the developer
  • .NET AppDomains allow you to create Python engines and restrict their security privileges, including controlling network and filesystem access and which assemblies the Python code can use
  • Easily create Python applications with multiple isolated Python engines in the same process
  • Easy to compile applications to binary and make binary only applications
  • Through the Dynamic Language Runtime (DLR) you get interoperability with languages like C# / F# / IronRuby and IronScheme
  • Extending IronPython with C#, for performance, is worlds easier than extending Python with C
For desktop application development a big question is what GUI framework to use if you want your application to run cross platform. Mono has a very complete implementation of Windows Forms, which is the standard .NET user interface on Windows. For Windows applications Windows Forms is good looking and easy to use, but by default on Linux and the Mac it isn't very attractive. It is useful for porting Windows applications but wouldn't be your first choice for a native Linux or Mac OS X application.

It definitely is possible to create good looking cross-platform applications with the Mono version of Windows Forms. Have a look at these screenshots of the Plastic SCM for an example. I haven't learned the requisite magic tricks to do this though.

There are at least two other alternatives: Qt (Qyoto) and Gtk (Gtk#).

Unfortunately there aren't yet good tutorials for developing with these user interface toolkits and IronPython, but these two blog entries will get you started with Glade and the GtkBuilder.

Someone asked me if I could add the missing parts of GtkBuilder in Gtk#Beans so he could use it with IronPython on mono.

Hey, it looks there's no missing parts ! It all works fine since day one. Here's the the trick...
Thanks to Stephane for his answer to my query about using GtkBuilder in IronPython. It turns out his Gtk#Beans package provides the magic sauce that is currently missing from the current stable release.

For completeness, here’s the code I sent him that accomplishes the same thing using the older Glade.XML object for those that are interested. It answers a long standing mailing list question about using Glade.XML.Autoconnect in IronPython...

No comments:

Post a Comment

Note: only a member of this blog may post a comment.