Python Programming, news on the Voidspace Python Projects and all things techie.

Silverlight 2 and Dynamic Silverlight

emoticon:cross One of the big announcements of the Microsoft Mix 08 conference in Las Vegas, that has just finished, was Silverlight 2. Silverlight 2 is the version of the browser plugin previously known as 1.1, and is now out of alpha and into beta!

Silverlight 2 comes with the 'core-clr' (a sandboxed version of the .NET runtime), and can be programmed with C#, VB.NET and dynamic languages like IronPython and IronRuby. The reason that I am talking about this several days after the news broke is that I am speaking on Silverlight at PyCon 2008 (in a few days time) and have been busy converting my examples to run on Silverlight 2!

The shiny new controls for Silverlight 2

So the all new Silverlight is mainly good, but a slightly mixed bag. Here's the lowdown:

The Good

  • New controls

    At last some decent controls for creating user interfaces (see the screenshot above) - and they're pretty good ones too. They're based on the WPF UI model. Although they're not identical you can share code and XAML between Silverlight and desktop apps.

  • Nokia S60 Platform to be supported

  • New APIs

    Threading, sockets, cross-domain server requests and web services. The beta is also more stable than the alpha and less prone to crashing.

  • Deep Zoom

    This is based on the phenomenally impressive 'Seadragon' technology that Microsoft bought in; and have now integrated into Silverlight. The have also included 'adaptive streaming' that can stream audio/video media into Silverlight at a rate determined by the available bandwidth and CPU.

  • IronRuby is now available for Silverlight!

    I'm sure this will please somebody. Wink

  • Some simplification

    The way you embed a Silverlight control in a web page has changed and become slightly simpler. No need for extra Javascript files and XAML files if you don't want to use them. Unfortunately this is offset by the changes in dynamic application packaging...

The Bad

  • IronPython is no longer included by default

    Actually this is a mixed blessing. It means that the IronPython version you can use with Silverlight is no longer tied to the version included in the release (and IronPython gets updated regularly) - but you have to include the IronPython assemblies in the download for your dynamic applications.

  • Godawful new application packaging system

    Dynamic applications for Silverlight 2 must be sent from the server as a single zipfile (with the extension '.xap'). The zipfile has to contain the IronPython assemblies, the main application file (app.py) plus any XAML files and Python files you import. You also need an XML manifest file that describes any assemblies your application uses (very 'enterprisey').

    These '.xap' files can be created by a custom packaging tool called chiron, which can also serve applications from the filesystem before you package them.

    Including the IronPython assemblies in every application makes even the simplest Dynamic Silverlight application painfully large. In answer to this point in a comment on his blog, John Lam replied: "Depending on how you configure your app, you can download the DSL dependencies (DLR + IronRuby) in a separate XAP that comes from one of our servers (this isn't working yet). So your XAP becomes something like 2K in that case. It will also be cached in your browser cache so it is a one-time download.". So this story will get better...

  • The new controls are an addon

    The new controls are great, but to use most of them you need to include extra assemblies in your application. The good news is that the sources and tests for the new controls are available. (Tests!)

  • Long list of API changes

    There is an awful lot that has changed, including some of the key classes for working with Silverlight.

  • Moonlight doesn't yet support Silverlight 2 [1] - so no Silverlight 2 for Linux yet.

Basic Example

Here's the 'minimal' IronPython example application for Silverlight 2. The application is a single Python file (app.py) containing:

from System.Windows import Application
from System.Windows.Controls import Canvas, TextBlock

canvas = Canvas()
textblock = TextBlock()
textblock.FontSize = 24
textblock.Text = 'Hello world from IronPython'
canvas.Children.Add(textblock)

Application.Current.RootVisual = canvas

Of course you also need to include the IronPython assemblies and an XML manifest file in your 'xap' file. Razz

For more you will have to attend my talk at PyCon or buy IronPython in Action... I'll update my Silverlight Pages after the talk.

Resources

And Finally

A side note about PyCon. Registration has now closed, with over a 1000 people registered - making this the biggest PyCon ever (and my second) by a long way. We're seeing new people join the Python community; ominously including Zed Shaw who very publicly burnt his bridges with the Ruby community and is now coming to PyCon! The Crowdvine PyCon 08 Site is also fun.

Python is doing well in other areas as well. The UK Computer Weekly printed magazine has an article (page 46) entitled "Python is worth getting to grips with" and says it is "now the seventh most popular programming language". The latest O'Reilly Radar State of the Computer Book Market also shows Python doing well. It lists Python in the "Mid-Minor Programming Languages" category (10,000 - 64,999 units sold in 2007).

So the news in this category is that Python has swapped places with Perl as the leader of the category. Perl had seven fewer titles make it into the Top 3000 while Python saw an additional 8 make the list. Powershell came out of nowhere and surpassed all the other groupings to make this list.

Before dancing too much, note that Ruby is in the next category up, mid-major languages (along with VB, SQL, ActionScript, and VBA). Smile

[1]Interestingly, the Mono team has preciously said that they have no interest in developing WPF support for Mono (although they are implementing WCF and other parts of .NET 3 / 3.5). Implementing Silverlight 2 will require quite a lot of work in this direction.

Like this post? Digg it or Del.icio.us it.

Posted by Fuzzyman on 2008-03-11 16:57:15 | |

Categories: , , Tags: , , , ,


Hosted by Webfaction

Counter...