[IronPython] Silverlight code need help (Repost)
Andrew Evans
andrew.canit at gmail.com
Mon Jan 11 22:03:42 CET 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20100111/4e7fc8a9/attachment.html>
More information about the Ironpython-users
mailing list