[IronPython] Silverlight code need help (Repost)

Andrew Evans andrew.canit at gmail.com
Mon Jan 11 23:13:46 CET 2010


WOW ty so much

at least I wasn't to far off :-P

again ty, you saved me from giving up on Silverlight :D


On Mon, Jan 11, 2010 at 1:37 PM, Jimmy Schementi <
Jimmy.Schementi at microsoft.com> wrote:

> 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:
>
>
>
>       <param name="initParams" value="*debug=true*,
> reportErrors=errorLocation, console=true" />
>
>
>
> This only works if VS 2008 SP1 has the Silverlight 3 Tools (
> http://www.microsoft.com/downloads/details.aspx?familyid=9442b0f2-7465-417a-88f3-5e7b5409e9dd&displaylang=en)
> installed, or you’re using VS 2010 (which support Silverlight
> out-of-the-box).
>
>
>
> ~js
>
>
>
> *From:* Jimmy Schementi
> *Sent:* Monday, January 11, 2010 1:27 PM
>
> *To:* users at lists.ironpython.com
> *Subject:* RE: [IronPython] Silverlight code need help (Repost)
>
>
>
> 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 (
> http://msdn.microsoft.com/en-us/library/system.windows.duration(VS.95).aspx)<http://msdn.microsoft.com/en-us/library/system.windows.duration%28VS.95%29.aspx%29>,
> 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.
>
>
>
> Let me know if you have any other issues.
>
>
>
> *From:* users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] *On Behalf Of *Andrew Evans
> *Sent:* Monday, January 11, 2010 1:04 PM
> *To:* users at lists.ironpython.com
> *Subject:* [IronPython] Silverlight code need help (Repost)
>
>
>
> 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?
>
> I am not a C# programmer but I am doing my best to find examples to compare
> to so I can translate into python
>
>
> I would really appreciate any help *Cheers Andrew
>
>
> Here is the full code hope that's alright :D
>
>
>
>
> from System.Windows import Application
> from System.Windows.Controls import MediaElement
> from System.Windows.Controls import Button, Orientation, StackPanel, Slider
> from System import Uri, UriKind
> from System.Windows.Media.Imaging import BitmapImage
> from System.Windows.Threading import *
>
> from System import TimeSpan
> class Gui():
>     def __init__(self):
>
>         self.main = StackPanel()
>
>         self.layer1 = StackPanel()
>         self.layer1.Orientation = Orientation.Horizontal
>
>         self.stopB = Button()
>         self.stopB.Width = 25
>         self.stopB.Height = 20
>         self.stopB.Content = BitmapImage(Uri("stop.jpg", UriKind.Relative))
>
>         self.pauseB = Button()
>         self.pauseB.Width = 25
>         self.pauseB.Height = 20
>         self.pauseB.Content = BitmapImage(Uri("pause.jpg",
> UriKind.Relative))
>
>         self.playB = Button()
>         self.playB.Width = 25
>         self.playB.Height = 20
>         self.playB.Content = BitmapImage(Uri("play.jpg", UriKind.Relative))
>
>         # Assign Buttons to Functions
>         self.stopB.Click += self.StopPlay
>         self.pauseB.Click += self.PausePlay
>         self.playB.Click += self.StartPlay
>
>
>
>         #add a video slider
>         self.myslide = Slider()
>         self.myslide.Width = 250
>
>
>         # Add buttons to sub stack panel
>         self.layer1.Children.Add(self.
>
> stopB)
>         self.layer1.Children.Add(self.pauseB)
>
>
>         self.layer1.Children.Add(self.myslide)
>
>         self.layer1.Children.Add(self.playB)
>
>         # create new sub stack panel
>         self.layer2 = StackPanel()
>         self.layer2.Orientation = Orientation.Vertical
>
>
>
>         #create Media Element
>         self.video = MediaElement()
>
>         self.source = Uri("counter.wmv", UriKind.Relative)
>         self.video.Volume = 0.4
>         self.video.Source = self.source
>         self.video.Width = 450
>         self.video.Height = 400
>         self.video.CurrentStateChanged += self.videoChanged
>
>         self.timer = DispatcherTimer()
>         self.timer.Interval = TimeSpan.FromMilliseconds(45)
>         self.timer.Tick += self.MyTimeToTick
>
>
>
>         # Add media Element to Sub Stack panel
>         self.layer2.Children.Add(self.video)
>
>         # Add sub stack panels to place holde stack panel
>         self.main.Children.Add(self.layer1)
>         self.main.Children.Add(self.layer2)
>
>         # Load the UI
>         Application.Current.RootVisual = self.main
>
>
>     def MyTimeToTick(self, s, e):
>         if self.video.NaturalDuration.TimeSpan.TotalSeconds > 0:
>             self.myslide.Value = self.video.Position.TotalSeconds /
> self.video.NaturalDuration.TimeSpan.TotalSeconds
>
>
>     def videoChanged(self, s, e):
>
>         if self.video.NaturalDuration.CurrentState ==
> MediaElementState.Playing:
>
>
>             self.timer.Start()
>         else:
>             self.timer.Stop()
> ##
> ##
>
>     def StopPlay(self, s, e):
>         # stop the video
>         self.video.Stop()
>
>     def PausePlay(self, s, e):
>         #pause the video
>         self.video.Pause()
>
>     def StartPlay(self, s, e):
>         #play the video
>         self.video.Play()
>
> gui = Gui()
> gui
>
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100111/6803e973/attachment.html>


More information about the Ironpython-users mailing list