Thursday, February 26, 2009

An IronPython Silverlight Bonanza

Silverlight 2 is the Microsoft browser plugin that includes a cut down version of the .NET runtime called the CoreCLR. Silverlight 2 runs on the IE, Firefox and Safari browsers on Windows and Mac OS X (Intel only). The Dynamic Language Runtime can run inside Silverlight, making it possible to natively script the browser with Python.

Meanwhile, the Mono guys have been busy creating a Mono version of Silverlight 2 for Linux called Moonlight.

Although Moonlight 2 hasn't yet been released, they are making great progress with it. The latest development version (build instructions here) is capable of running some of my IronPython demos:
On my Silverlight pages I have a series of articles and simple demos of developing Silverlight applications with IronPython. This includes my Web IDE which is a great tool for interactively exploring the Silverlight APIs and comes with several different demos preloaded. Due to the minor trials of completing IronPython in Action I've only belatedly updated my articles and demos to work with the final release of Silverlight 2:
I'm not the only one experimenting with IronPython and Silverlight however. Steve Gilham got round to converting one of my demos to Silverlight 2 final before I did, and this blog entry compares it to a similar Java applet written using Jython:
Of IronPython and Silverlight he concludes: "now both products are at a stable release, it starts to make sense to actually use the technology".

Steve Gilham also blogs on his Tinesware blog, and has posted an example Silverlight app called astroclock written in IronPython:
Astroclock allows you to set your latitude and longitude and tells you the local time, with a nice animated clock face. It includes a 'permalink' feature that generates a URL to the clock, set to the specific coordinates it is currently set to. He has also developed a version of the clock in F# (a .NET functional programming language): Astroclock in F#

ArtyProg has also posted some example IronPython code for Silverlight, this one a port of a (very short) demo written by Scott Guthrie from C# to Python:
If you crave more detailed information rather than just demos then you'll be interested in this article from Marvin Killing:
There are quite a lot of articles about how to use System.Net.Sockets from inside of Silverlight 2.0 with C#. However, I've not found any info on how to do it with IronPython. Here's what I've found out so you can hopefully avoid some of the pitfalls I've encountered:

Prerequisites:
  • Silverlight 2.0
  • Silverlight Dynamic Languages SDK to develop a Silverlight application with Python
  • Python 2.5 or 2.6 to run the TCP server
  • Visual Studio 2008 to compile the policy server
What we're about to create:
  • A Silverlight app acting as a client (written in IronPython)
  • A TCP server to accept client connections (written in Python)
  • A policy server (written in C#)

No comments:

Post a Comment

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