[IronPython] Delegates

Dino Viehland dinov at exchange.microsoft.com
Wed Feb 6 19:09:08 CET 2008


You need to match the signature of Application.Idle.  But once you have the right signature += should work.  It looks like Idle is just an EventHandler so:

def MyIdle(self, sender, eventArgs):
                self.Invalidate()

Application.Idle += self.MyIdle

Should work.  And to make it more like the C# version you can use a lambda:

Application.Idle += lambda sender, ea: self.Invalidate()




From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Herny Johnson
Sent: Wednesday, February 06, 2008 9:56 AM
To: users at lists.ironpython.com
Subject: [IronPython] Delegates

I'm trying to put Xna on a Windows Form and the best idea that I've found so far was at http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/WinForms-Series-1_3A00_--Graphics-Device.aspx.  In a nut shell it's quite easy to translate the C# code to IronPython to see if it will actually work for IronPython.  That is until the C# code:

C#
    // Hook the idle event to constantly redraw our animation.
    Application.Idle += delegate { Invalidate(); };

This makes it so the Xna control that you create it constantly redrawn, not just every button click or other event.  This code is found in the SpinningTriangleControl.cs of the zip

file if you want to see more of how it works.



My question is how do I create a delegate or equivalent in IronPython?  I've tried using System.Delegate, but I'm not sure how to use it correctly.  Also I've tried just using

Application.Idle += self.Invalidate (called or uncalled) and that doesn't work.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20080206/26e889bc/attachment.html>


More information about the Ironpython-users mailing list