Introduction to IronPython & Silverlight

Python in Your Browser

That cunning snake

 

 

Loading ...

 

Introduction

Silverlight 2 is a browser plugin from Microsoft. Through Silverlight it is possible to create dynamic applications and natively script the browser with Python.

In this series of articles we will look at what it is possible to achieve with Silverlight, and how to get started with dynamic applications. This includes the following topics:

  • Create dynamic applications
  • Using the Silverlight APIs
  • Including consuming XAML and create controls
  • Access the browser DOM
  • Calling between Javascript and Silverlight code
  • Embed IronPython in a C# Silverlight application
  • Compile C# for Silverlight without Visual Studio installed

The examples used throughout these articles are online and available for download. They all require Silverlight 2.0 Beta 1.

First though, an introduction to both IronPython and Silverlight. (For the quick lowdown on what's new in Silverlight 2, read Silverlight 2 and Dynamic Silverlight.)

IronPython

IronPython is an implementation of the popular dynamic programming language Python. Python is a general purpose programming language used for everything from desktop applications, running YouTube, games, managing Imageworks animation pipeline, automated hard drive testing for Seagate - and much more.

IronPython runs on the .NET framework and Mono. This allows Python programmers to take advantage of the extensive framework libraries and powerful runtime of .NET, and allows .NET programmers to take advantage of Python!

IronPython was originally created by Jim Hugunin, and is now developed by a team of programmers (which sometimes includes Jim!) at Microsoft. IronPython is a Python compiler, compiling Python code to in memory assemblies.

  • The stable version is 1.1.1, which targets Python 2.4.
  • The development version is 2.0, which is still in beta, built on top of the Dynamic Language Runtime, and targets Python 2.5.

For a more comprehensive introduction to Python and IronPython you can read the first chapter of IronPython in Action which is free to download.

Silverlight

Silverlight is Microsoft's entry into the rich internet application framework race.

  • A cross-platform cross-browser plugin
  • Intended for games and Rich Internet Application
  • Silverlight code runs in the browser
  • Streaming media and video
  • Includes the 'Core-CLR'
  • Through the DLR, runs IronPython 2 (Python 2.5)

Silverlight is a sandboxed browser plugin for creating rich client-side web applications. It runs on Windows and Mac OSX, supporting Firefox, IE and Safari (with support for more browsers on the way). Nokia S60 and Windows Mobile support have also been announced.

There is a Mono version called Moonlight, which runs on Linux (supporting Firefox). This is now officially backed by Microsoft who are making the media codecs, the test suite and the full specification available to the Mono team. Initially it will target Firefox on Linux, but eventually will run on multiple browsers everywhere that Mono runs.

Version 1 of Silverlight focusses on media streaming and is programmed with Javascript. Version 2, which is still in beta, ships with a cut down version of the CLR (the core of the .NET framework). It can be programmed with C# or any of the DLR languages which includes IronPython.

All the examples I show here require Silverlight 2.0 Beta 1.

What Does Silverlight Offer

  • A video player!
  • A user interface based on Windows Presentation Foundation
  • 'Deep zoom' and adaptive streaming
  • Client side storage (1MB per app but you can request more)
  • A rich set of APIs (JSON, XML, threading, sockets)
  • Access to the browser DOM and Javascript
  • Performance (IronPython run in Silverlight outperforms traditional Javascript by a couple of orders of magnitude)
  • Python!!

It isn't just Python that you can program Silverlight with. The dynamic languages currently available (from Microsoft) for Silverlight are IronPython, IronRuby and managed JScript. Why managed JScript? Managed Javascript is ECMAScript compliant (ECMAScript 3.0) - so code written AJAX style with traditional Javascript can be ported over to run in Silverlight, and run much faster. Really well integrated with the rest of the platform.

These languages can also interoperate with the traditional .NET languages. They can use classes created from C# /VB code without wrappers. To the dynamic languages they are natural objects just as much as ones they have created themselves.

There are several ways that dynamic applications can use Silverlight:

  • The Silverlight control is the main user interface on the web page
  • The Silverlight control occupies only part of the page (like flash) and optionally interacts with Javascript and HTML in the page. You can even embed several controls in a page.
  • The Silverlight control is completely hidden and acts as a calculation engine that runs in the background
  • A fullscreen mode

One major difference between Silverlight and Adobe Flex/AIR is that there is currently no way to use Silverlight to create applications that are separate from the browser (well the Mono guys have done this with Moonlight).

Silverlight separates presentation from code (design from development), through XAML. This is an XML markup for creating user interfaces, including theming interfaces and defining animations. This is intended to be created by tools like Expression Blend (currently in free beta). There is also a version for Mono called 'Lunar Eclipse' under development. We will be looking at how to create user interfaces, using the fancy new controls for Silverlight 2, either by working with XAML from IronPython or directly from code. We'll also explore interacting with the browser DOM and (normal) Javascript.

First we'll look at the structure of an IronPython & Silverlight application.

For buying techie books, science fiction, computer hardware or the latest gadgets: visit The Voidspace Amazon Store. If you're looking for a new techie job, try the Voidspace Tech Job Board. This is part of the Hidden Network of technology and programming jobs.

Hosted by Webfaction

Return to Top

Page rendered with rest2web the Site Builder

Last edited Sat Mar 22 01:15:41 2008.


Counter...


Voidspace: Cyberpunk, Technology, Fiction and More
Search this Site:
 
Web Site

IronPython in ActionIronPython in Action

Blogads

Follow me on:

Twitter

Pownce

Jaiku

Del.icio.us

Shared Feeds

Tech Jobs

Hidden Network

Tech Jobs Board

Hosting for an agile web