MSDN Magazine - February 2008 - (Page 20) Using DLRConsole The two ways to get DLRConsole running in your browser are either to just run it from silverlight.net, or run it locally on your own machine. For the purposes of this column, I’ll demonstrate running from Silverlight.net, but if you want to download DLRConsole.zip, browse through the code, and run it on your development machine or a local server, see the sidebar “Running DLRConsole Locally” for some useful tips. To get started, open silverlight.net/ Samples/1.1/DLR-Console/python in your browser. Yes, that’s it! You should see the DLRConsole open in your browser as shown in Figure 1. When DLRConsole loads, you are presented with a Python command prompt, letting you type Python code line-by-line Figure 2 Writing Code in the Console and see its effects either right in the console or in the Silverlight canvas as shown in Figure 2. You can click on the different languages to change the console to that language and see a chunk of sample code in the language you select. Try mixing and matching languages as you type statements, and see how everything you did in one language is available in the other. The XAML tab shows you the XAML code behind the initial Silverlight Canvas pane (see Figure 3). You can edit it or add to it, and then update the canvas by pressing the Ctrl+Enter keys. The Python Code tab shows you a chunk of Python code that will produce a blue background with text that changes color when you hover over it. Again, you’ll need to press the Ctrl+Enter keys to execute this code, for the first time and Figure 3 The XAML Pane after you make any changes. The About tab just links to the DynamWpf.py is a Python file that defines some helpers for interacting ic Silverlight Web page on CodePlex (codeplex.com/dynamicsilverlight). with WPF, such as a LoadXaml(url): Now that you’ve seen what DLRConsole can do, let’s take a look at what files make up DLRConsole, and how it all works. Figure 4 lists the source files included in the DLRConsole download. The files Index.htm, Silverlight.js, and CreateSilverlight.js are used to initialize Silverlight. Though these files are important, I’m not going to discuss them here. You can find a deeper discussion about the basic Silverlight project setup at silverlight.net/QuickStarts/ Start/CreateProject.aspx. Inside the Code def LoadXaml(url): uri = MakeUri(url) request = System.Windows.Browser.Net.BrowserHttpWebRequest(uri) response = request.GetResponse() reader = System.IO.StreamReader(response.GetResponseStream()) xaml = reader.ReadToEnd () reader.Close() return XamlReader.Load(xaml) This method actually downloads the provided URL and returns the result of XamlReader.Load. DLRConsole.xaml loads DLRConsole.py and then calls the 20 msdnmagazine CLR Inside Out http://silverlight.net/Samples/1.1/DLR-Console/python http://silverlight.net/Samples/1.1/DLR-Console/python http://codeplex.com/dynamicsilverlight http://silverlight.net/QuickStarts/Start/CreateProject.aspx http://silverlight.net/QuickStarts/Start/CreateProject.aspx
For optimal viewing of this digital publication, please enable JavaScript and then refresh the page. If you would like to try to load the digital publication without using Flash Player detection, please click here.