MSDN Magazine - February 2008 - (Page 23) Figure 6 Mouseover Events import wpf canvas.Background = wpf.BlueBrush r = wpf.TextBlock() r.Text = “Touch Me” canvas.Children.Add(r) r.FontSize = 60 wpf.SetPosition(r, 40, 60) def light(s, e): s.Foreground = wpf.SolidColorBrush(wpf.Colors.White) def dark(s, e): s.Foreground = wpf.SolidColorBrush(wpf.Colors.Black) r.MouseEnter += light r.MouseLeave += dark js> a = 2 + 2 4.0 py> b = a * 2 py> b 8.0 js> function times10(n) { js| return n * 10 js| } py> times10(5) 50.0 To accomplish this, just click the language you want to program in and it changes the console prompt, syntax coloring, and, of course, the language. This works by telling the console to set its language, which delegates to the Editor: def SetLanguage(self, name): self.le = GetEngine(name) self.Engine = self.CurrentEngine = self.le.engine self.TokenCategorizer = self.Engine.LanguageProvider.GetTokenCategorizer() When typing in any of these examples, This may not seem very practical at first, did you notice a little box pop up when you but it enables code-reuse like never before typed a class or object name followed by a by giving developers the freedom to code period? DLRConsole supports something in their favorite language, but not limit the the team likes to call “code-sense.” It’s not use of their code based on the implemenquite as advanced as the Visual Studio® tation language. Arguably, developers are IntelliSense® feature—this is a sample, most creative when writing in their favorite after all—but it still helps a great deal at language, so this may even help improve finding out what methods or properties the quality of software. you have available to you on a given object (see Figure 7). Start Playing Now! With this, you can use the up/down DLRConsole enables you to explore arrow keys to select which element you Silverlight, as well as dynamic languages, want, and then press Enter to select it and Figure 7 “Code-sense” Autocompletion with minimal commitment—you don’t continue typing. To see how it works, let’s even need to install any software beyond look at the HandleKey method again: Silverlight. What better way to start experimenting than in someone else’s hosted sandbox? def HandleKey(self, key): if key.Text == ‘\n’: Keep your eyes open for a new release of dynamic language inself.DoInput(key.Ctrl) tegration in Silverlight, as well as new and updated versions of our elif key.Text == ‘.’: self.DoCompletions() Silverlight dynamic language samples from codeplex.com/dynamicsilelif key.Name == ‘Up’ and self.Caret.line == 0: verlight. The next version should also include support for IronRuby, self.DoHistory() else: which you can download today from www.ironruby.net. And, as always, Editor.HandleKey(self, key) you can download IronPython from codeplex.com/ironpython. If you That’s a rather nice feature for just a little more than 100 lines are interested in more Silverlight samples, you can find plenty of of Python code. fun and interesting ones in the Silverlight Community Gallery: sil- From Python to JScript verlight.net/community/communitygallery.aspx. ■ As I mentioned before, DLRConsole supports multiple DLR languages, and the currently released bits show support for Python and JScript. Since all these languages are built on-top of the DLR, they are not only integrated with .NET but can they also share declarations across languages. This demonstrates sharing variables and methods between Python and JScript: Send your questions and comments to clrinout@microsoft.com. Jimmy Schementi is a Program Manager on the Dynamic Languages team at Microsoft. He’s focused on making Silverlight application-authoring a fun and productive experience with dynamic languages, such as Ruby and Python, and building a community around those languages. You can contact Jimmy at http://jimmy.schementi.com. CLR Inside Out february2008 23 http://codeplex.com/dynamicsilverlight http://codeplex.com/dynamicsilverlight http://www.ironruby.net http://codeplex.com/ironpython http://silverlight.net/community/communitygallery.aspx http://silverlight.net/community/communitygallery.aspx http://jimmy.schementi.com
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.