[IronPython] Silverlight code need help (Repost)

Andrew Evans andrew.canit at gmail.com
Tue Jan 12 21:57:56 CET 2010


HAHA ya my browser is whats wrong :-P

Did I ever tell you are awesome btw :-P Did you want me to email you the app
or is this way fine?

#Begin Code#


from System import *
from System.Windows import Application
from System.Windows.Controls import MediaElement
from System.Windows.Controls import Button, Orientation, StackPanel, Slider,
Image, TextBlock
from System import Uri, UriKind
from System.Windows.Media.Imaging import BitmapImage
from System.Windows.Threading import *
from System import TimeSpan
from System.Windows.Media import MediaElementState
#from System.Net import WebClient




class Gui():
    def __init__(self):
        #stack panel
        self.main = StackPanel()

        #sub stack panel
        self.layer1 = StackPanel()
        self.layer1.Orientation = Orientation.Horizontal

        #buttons
        self.stopB = Button(
            Width = 25,
            Height = 20,
            Content = Image(
                Source = BitmapImage(Uri("images/stop.jpg",
UriKind.Relative))
                )
            )
        self.pauseB = Button(
            Width = 25,
            Height = 20,
            Content = Image(
                Source = BitmapImage(Uri("images/pause.jpg",
UriKind.Relative))
                )
            )
        self.playB = Button(
            Width = 25,
            Height = 20,
            Content = Image(
                Source = BitmapImage(Uri("images/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 = 190
        self.myslide.MouseLeftButtonUp += self.lbup
        self.myslide.MouseLeftButtonDown += self.lbdown
        self.txtvidstatus = TextBlock()

        #add a volume slider
        self.volumeslide = Slider()
        self.volumeslide.Width = 100
        self.volumeslide.ValueChanged += self.vidvol

        # 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)
        self.layer1.Children.Add(self.volumeslide)
        self.layer1.Children.Add(self.txtvidstatus)

        # 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.video.AutoPlay = True

        self.timer = DispatcherTimer()
        self.timer.Interval = TimeSpan.FromMilliseconds(500)
        self.timer.Tick += self.MyTimeToTick
        self.timer.Start()

        # 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

    #Functions

    def vidvol(self, s, e):
        self.video.Volume = self.volumeslide.Value

    def lbdown(self, s, e):
        self.IsVideoScrubberLocked = True

    def lbup(self, s, e):
        if self.video.NaturalDuration.TimeSpan.TotalSeconds > 0 and not
self.IsVideoScrubberLocked:
             self.myslide.Value = self.video.Position.TotalSeconds /
self.video.NaturalDuration.TimeSpan.TotalSeconds

    def MyTimeToTick(self, s, e):
        if self.video.NaturalDuration.TimeSpan.TotalSeconds > 0:
            self.txtvidstatus.Text = String.Format("{0:00}:{1:00}",
                                                self.video.Position.Minutes,
                                                self.video.Position.Seconds)
            self.percentComplete = self.video.Position.TotalSeconds /
self.video.NaturalDuration.TimeSpan.TotalSeconds
            self.myslide.Value = self.percentComplete


    def videoChanged(self, s, e):
        if self.video.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


#End code #


On Tue, Jan 12, 2010 at 11:47 AM, Jimmy Schementi <
Jimmy.Schementi at microsoft.com> wrote:

> Haha, when in doubt blame your browser =P …
>
>
>
> It’s most likely an issue with your code. Feel free to send me your updated
> code and I can check things out.
>
>
>
> *From:* users-bounces at lists.ironpython.com [mailto:
> users-bounces at lists.ironpython.com] *On Behalf Of *Andrew Evans
> *Sent:* Tuesday, January 12, 2010 8:55 AM
> *To:* Discussion of IronPython
> *Subject:* Re: [IronPython] Silverlight code need help (Repost)
>
>
>
> There seems to be a Flaw in my code
>
> It seems the movie is finished before the slider reaches the end of its
> length.
>
> Any suggestions?
>
> Or is there something wrong with my browser?
>
> _______________________________________________
> 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/20100112/50003b2a/attachment.html>


More information about the Ironpython-users mailing list