IronPython2.0がRC1になったのでテスト。
もう、namespace関連の変更はないと思いたい。

Silverlight2.0 で動作を確認したIronPythonをダウンロードし実行するプログラム。

クライアント側の参照設定で以下を追加。(C:\IronPython-2.0\Silverlight\binのdll)
IronPython.dll
IronPython.Modules.dll
Microsoft.Scripting.dll
Microsoft.Scripting.Core.dll
ファイルバージョンは2.0.31005.0 (2008/10/20)

作成されたSilverlightApplication_PythonDownload.xapファイルは1.2メガ。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using IronPython.Hosting;
using IronPython.Runtime;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;

namespace SilverlightApplication_PythonDownload
{
public partial class Page: UserControl
{
public Page()
{
InitializeComponent();

_globals = _py.Runtime.Globals;

_globals.SetVariable("Page", this );

DownloadScript_Execute( "init.py");
}

ScriptEngine _py = Python.CreateEngine();
ScriptScope _globals;

/// <summary>
/// download script file and execute.
/// </summary>
/// <param name="scFileName"></param>
void DownloadScript_Execute( string scFileName )
{
this.Cursor = Cursors.Wait;

try
{
WebClient wc = new WebClient();
wc.DownloadStringCompleted += (seder, e ) =>
{
string src = e.Result;
ScriptExec( src );

this.Cursor = Cursors.Arrow;
};

Uri uri = new Uri( System.Windows.Browser.HtmlPage.Document.DocumentUri, scFileName);
wc.DownloadStringAsync( uri );
}
catch( Exception ex)
{
string err = ex.Message;
}
finally
{

}
}

/// <summary>
/// execute script.
/// </summary>
/// <param name="src"></param>
/// <returns></returns>
object ScriptExec( string src )
{
ScriptSource sc = _py.CreateScriptSourceFromString( src, SourceCodeKind.Statements );
return sc.Execute( _globals );
}
}
}

init.pyは以下。


import clr

clr.AddReference("System")
clr.AddReference("System.Windows")

btn = Page.FindName( "btn1" ) #


Page.xamlは以下。

<UserControl x:Class="SilverlightApplication_PythonDownload.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" Background="White">
<Button Width="200" Height="30" x:Name="btn1"></Button>
</Grid>
</UserControl>