<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"Balloon Text Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:8.0pt;
        font-family:"Tahoma","sans-serif";}
span.EmailStyle17
        {mso-style-type:personal;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.BalloonTextChar
        {mso-style-name:"Balloon Text Char";
        mso-style-priority:99;
        mso-style-link:"Balloon Text";
        font-family:"Tahoma","sans-serif";}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>You can attach Visual Studio to a running Silverlight process, and breakpoints will be hit in your Silverlight code if you set the debug flag in the HTML page hosting Silverlight:<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'> <param name="initParams" value="<b>debug=true</b>, reportErrors=errorLocation, console=true" /><o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>This only works if VS 2008 SP1 has the Silverlight 3 Tools (<a href="http://www.microsoft.com/downloads/details.aspx?familyid=9442b0f2-7465-417a-88f3-5e7b5409e9dd&displaylang=en">http://www.microsoft.com/downloads/details.aspx?familyid=9442b0f2-7465-417a-88f3-5e7b5409e9dd&displaylang=en</a>) installed, or you’re using VS 2010 (which support Silverlight out-of-the-box).<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>~js<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> Jimmy Schementi <br><b>Sent:</b> Monday, January 11, 2010 1:27 PM<br><b>To:</b> users@lists.ironpython.com<br><b>Subject:</b> RE: [IronPython] Silverlight code need help (Repost)<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>The error you’re probably seeing is “AttributeError: 'Duration' object has no attribute 'CurrentState',” correct (line highlighted below)?. This is because MediaElement.NaturalDuration gives you a System.Windows.Duration object (<a href="http://msdn.microsoft.com/en-us/library/system.windows.duration(VS.95).aspx)">http://msdn.microsoft.com/en-us/library/system.windows.duration(VS.95).aspx)</a>, which in-fact doesn’t have a “CurrentState” member. However, MediaElement has a “CurrentState” member, so I think you intending that line to read “ if self.video. CurrentState == MediaElementState.Playing:”. You’ll also need to add “from System.Windows.Media import MediaElementState” to make sure MediaElementState is available.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Let me know if you have any other issues.<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif"'> users-bounces@lists.ironpython.com [mailto:users-bounces@lists.ironpython.com] <b>On Behalf Of </b>Andrew Evans<br><b>Sent:</b> Monday, January 11, 2010 1:04 PM<br><b>To:</b> users@lists.ironpython.com<br><b>Subject:</b> [IronPython] Silverlight code need help (Repost)<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I am having problems with my code. I am not sure how to debug silverlight. I receive no error messages, but this is what happens. When this app runs it starts for a second then disappears I am not sure where I am going wrong, any ideas? Perhaps in the threading? <br><br>I am not a C# programmer but I am doing my best to find examples to compare to so I can translate into python<br><br><br>I would really appreciate any help *Cheers Andrew<br><br><br>Here is the full code hope that's alright :D<o:p></o:p></p><div><p class=MsoNormal><br><br><br>from System.Windows import Application<br>from System.Windows.Controls import MediaElement<br>from System.Windows.Controls import Button, Orientation, StackPanel, Slider<br>from System import Uri, UriKind <br>from System.Windows.Media.Imaging import BitmapImage<br>from System.Windows.Threading import *<o:p></o:p></p></div><p class=MsoNormal>from System import TimeSpan<br>class Gui():<br> def __init__(self):<br><br> self.main = StackPanel() <br><br> self.layer1 = StackPanel() <br> self.layer1.Orientation = Orientation.Horizontal<br><br> self.stopB = Button()<br> self.stopB.Width = 25<br> self.stopB.Height = 20<br> self.stopB.Content = BitmapImage(Uri("stop.jpg", UriKind.Relative))<br><br> self.pauseB = Button()<br> self.pauseB.Width = 25<br> self.pauseB.Height = 20<br> self.pauseB.Content = BitmapImage(Uri("pause.jpg", UriKind.Relative))<br> <br> self.playB = Button()<br> self.playB.Width = 25<br> self.playB.Height = 20<br> self.playB.Content = BitmapImage(Uri("play.jpg", UriKind.Relative))<br> <br> # Assign Buttons to Functions<br> self.stopB.Click += self.StopPlay<br> self.pauseB.Click += self.PausePlay<br> self.playB.Click += self.StartPlay<o:p></o:p></p><div><p class=MsoNormal><br><br> #add a video slider<br> self.myslide = Slider()<br> self.myslide.Width = 250<br> <o:p></o:p></p></div><p class=MsoNormal> # Add buttons to sub stack panel<br> self.layer1.Children.Add(self.<o:p></o:p></p><div id=":3a"><p class=MsoNormal>stopB)<br> self.layer1.Children.Add(self.pauseB)<o:p></o:p></p><div><p class=MsoNormal><br> self.layer1.Children.Add(self.myslide)<o:p></o:p></p></div><p class=MsoNormal> self.layer1.Children.Add(self.playB)<br><br> # create new sub stack panel<br> self.layer2 = StackPanel()<br> self.layer2.Orientation = Orientation.Vertical<o:p></o:p></p><div><p class=MsoNormal><br><br> #create Media Element<br> self.video = MediaElement()<o:p></o:p></p></div><p class=MsoNormal> self.source = Uri("counter.wmv", UriKind.Relative)<br> self.video.Volume = 0.4<br> self.video.Source = self.source<br> self.video.Width = 450<br> self.video.Height = 400<br> self.video.CurrentStateChanged += self.videoChanged<br><br> self.timer = DispatcherTimer()<br> self.timer.Interval = TimeSpan.FromMilliseconds(45)<br> self.timer.Tick += self.MyTimeToTick<br> <br><br><br> # Add media Element to Sub Stack panel<br> self.layer2.Children.Add(self.video)<br><br> # Add sub stack panels to place holde stack panel<br> self.main.Children.Add(self.layer1)<br> self.main.Children.Add(self.layer2)<br><br> # Load the UI<br> Application.Current.RootVisual = self.main <o:p></o:p></p><div><p class=MsoNormal><br> def MyTimeToTick(self, s, e):<br><span style='color:red'> </span><span style='color:black'>if self.video.NaturalDuration.TimeSpan.TotalSeconds > 0:<br></span> self.myslide.Value = self.video.Position.TotalSeconds / self.video.NaturalDuration.TimeSpan.TotalSeconds<br><br><br> def videoChanged(self, s, e):<o:p></o:p></p></div><p class=MsoNormal><span style='color:red'> <span style='background:yellow;mso-highlight:yellow'>if self.video.NaturalDuration.CurrentState == MediaElementState.Playing:</span><o:p></o:p></span></p><div><p class=MsoNormal><br> self.timer.Start()<br> else:<br> self.timer.Stop()<br>##<br>## <o:p></o:p></p></div><p class=MsoNormal> def StopPlay(self, s, e):<br> # stop the video<br> self.video.Stop()<br> <br> def PausePlay(self, s, e):<br> #pause the video<br> self.video.Pause()<br> <br> def StartPlay(self, s, e):<br> #play the video<br> self.video.Play()<br><br>gui = Gui()<br>gui<o:p></o:p></p></div></div></div></div></body></html>