[IronPython] Events

Dino Viehland dinov at exchange.microsoft.com
Fri Feb 2 12:41:29 PST 2007


One thing I'll point out is we have no direct support for this in IronPython today.  But our events are all dispatched using an EventDispatcher class (see ReflectedMembers.cs, EventDispatcher is an inner class of ReflectedEvent).

This class registers a single event against the underlying .NET event and when the event is fired the dispatcher dispatches to all of the registered handlers.  At this point in the code it would be possible to add a try/catch and remove the current dispatcher if it threw.

We'd obviously have to think about this before making it a language feature but if you wanted to customize your version of IronPython to handle this it should be fairly trivial.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Michael Foord
Sent: Friday, February 02, 2007 6:13 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Events

Kasper Tanggaard wrote:
> Hello all,
>
> This is my first post, and I'm not that used to mailinglists, so I do
> apologize if it goes wrong :). I'm using IronPython as scripting in my
> application, and I already love it! I would like for my users to write
> methods which they can hook up as events to the controls already in
> the application. This works fine, but what if the user messes up? I
> would like to be able to remove user assigned events from within the
> application, since I've seen that done with other scripting components
> back in the good old Delphi days. Is this possible with IronPython? If
> not, is it possible to do with a piece of Python code which the user
> can execute if something goes wrong? I hope someone can help me here :)
Hello Kasper,

In IronPython events are added using '+=' :

def onClick(sender, event):
   print 'clicked'

button.Click += onClick

To remove it you do:

button.Click -= onClick

Perhaps you could create your own interface for adding to events, which
keeps track of everything added and allows you to remove them easily ?

I'm not sure if event handlers are simply collections, there may be a
away of examining them to see what is in there.

I hope this is helpful.

Michael
http://www.voidspace.org.uk/python/articles.shtml

>
> Kind regards,
>
> Kasper
>
> _________________________________________________________________
> Få 250 MB gratis lagerplads på MSN Hotmail:  http://www.hotmail.com
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition.
> Version: 7.1.411 / Virus Database: 268.17.19/663 - Release Date: 01/02/2007
>
>


--
Michael Foord
Resolver Systems
michael.foord at resolversystems.com

Office address:     17a Clerkenwell Road, London EC1M 5RD, UK
Registered address: 843 Finchley Road, London NW11 8NA, UK

Resolver Systems Limited is registered in England and Wales as company number 5467329.
VAT No. GB 893 5643 79

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


More information about the users mailing list