On 11.8.2010 19:11, Andrew Evans wrote:
Ok well it doesn't look like my event handlers are even being called

this is what I did

    def KeyDown_Control(self, s, e):
        if e.Key == Key.Right:
            print "Right Arrow"
#self.canvas.SetLeft(self.ship, self.canvas.GetLeft(self.ship) + velocity)
        elif e.Key == Key.Left:
            print "Left Arrow"
#self.canvas.SetLeft(self.ship, self.canvas.GetLeft(self.ship) - velocity)
        elif e.Key == Key.Up:
            print "Up Arrow"
#self.canvas.SetTop(self.ship, self.canvas.GetTop(self.ship) - velocity)
        elif e.Key == Key.Down:
            print "Down Arrow"
#self.canvas.SetTop(self.ship, self.canvas.GetTop(self.ship) + velocity)

So assuming that's the issue which is likely than it would be this line

# This line should be something different Not sure what to use instead of this
        self.ship.KeyDown += KeyEventHandler(self.KeyDown_Control)

What about
self.ship.KeyDown += self.KeyDown_Control

--
-- Lukas



Which I assumed all this time

Any ideas what it should be?

*cheers

Andrew

On Wed, Aug 11, 2010 at 9:37 AM, Michael Foord <fuzzy...@voidspace.org.uk <mailto:fuzzy...@voidspace.org.uk>> wrote:

    On 11/08/2010 17:34, Andrew Evans wrote:
    Hello I am running IronPython 2.7A and trying to debug a
    Silverlight app. I am trying to figure out why my ship doesn't
    move when I press the Arrow keys.

    here is the complete source minus most imports :D
    Put some debugging in (append text to an html div) to see if your
    event handlers are being fired. That would my first step.

    Michael


    Any ideas

    from System.Windows.Input import *


    velocity = 10

    class Gui():
        def __init__(self):

            self.grid = Grid()
            self.canvas = Canvas(Background =
    SolidColorBrush(Colors.White))
            self.canvas.Width = 640
            self.canvas.Height = 432
            self.bgImage = Image(
                Source = BitmapImage(Uri("images/background.jpg",
    UriKind.Relative))
                )
            self.canvas.SetTop(self.bgImage, 132)
            self.canvas.SetLeft(self.bgImage, 0)
    #        self.textblock = TextBlock()
    ##        self.textblock.FontSize = 24
    ##        self.textblock.Text = 'This Really Works!!'
    ##        self.canvas.Children.Add(self.textblock)

            self.ship = Image(
                Source = BitmapImage(Uri("images/ship.png",
    UriKind.Relative))
                )

            self.canvas.SetTop(self.ship, 75)
            self.canvas.SetLeft(self.ship, 25)

            CompositionTarget.Rendering += EventHandler(self.ShootBG)
    ##        self.GenerateStarField(350)

            self.canvas.Children.Add(self.bgImage)

            self.canvas.Children.Add(self.ship)
            self.grid.Children.Add(self.canvas)
            Application.Current.RootVisual = self.grid
            # This line should be something different Not sure what
    to use instead of this
            self.ship.KeyDown += KeyEventHandler(self.KeyDown_Control)


        def ShootBG(self, s, e):
            self.canvas.SetLeft(self.bgImage,
    self.canvas.GetLeft(self.bgImage) - 1)
            if self.canvas.GetLeft(self.bgImage) < -2110:
                self.canvas.SetLeft(self.bgImage, 0)

        def KeyDown_Control(self, s, e):
            if e.Key == Key.Right:
                self.canvas.SetLeft(self.ship,
    self.canvas.GetLeft(self.ship) + velocity)
            elif e.Key == Key.Left:
                self.canvas.SetLeft(self.ship,
    self.canvas.GetLeft(self.ship) - velocity)
            elif e.Key == Key.Up:
                self.canvas.SetTop(self.ship,
    self.canvas.GetTop(self.ship) - velocity)
            elif e.Key == Key.Down:
                self.canvas.SetTop(self.ship,
    self.canvas.GetTop(self.ship) + velocity)

    gui = Gui()
    gui


    _______________________________________________
    Users mailing list
    Users@lists.ironpython.com <mailto:Users@lists.ironpython.com>
    http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


-- http://www.ironpythoninaction.com/
    http://www.voidspace.org.uk/blog

    READ CAREFULLY. By accepting and reading this email you agree, on behalf of 
your employer, to release me from all obligations and waivers arising from any 
and all NON-NEGOTIATED agreements, licenses, terms-of-service, shrinkwrap, 
clickwrap, browsewrap, confidentiality, non-disclosure, non-compete and 
acceptable use policies (”BOGUS AGREEMENTS”) that I have entered into with your 
employer, its partners, licensors, agents and assigns, in perpetuity, without 
prejudice to my ongoing rights and privileges. You further represent that you 
have the authority to release me from any BOGUS AGREEMENTS on behalf of your 
employer.



    _______________________________________________
    Users mailing list
    Users@lists.ironpython.com <mailto:Users@lists.ironpython.com>
    http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to