[IronPython] Issues with methods as event handlers?
Giles Thomas
giles.thomas at resolversystems.com
Fri Feb 3 11:52:40 CET 2006
Dino,
That makes sense, thanks for the clarification.
Regards,
Giles
--
Giles Thomas
Resolver Systems
giles.thomas at resolversystems.com
We're hiring! http://www.resolversystems.com/jobs/
Dino Viehland wrote:
> Another option that should work is:
>
> class ClickListener:
> def trigger(self, source, args):
> print "..."
>
> a = ClickListener()
> b = a.trigger
>
> triggerButton.Click += b
>
> triggerButton.Click -= b
>
>
> What you're experiencing is the fact that trigger is actually just a callable object. When you do a.trigger you get a new bound method object that is different from the bound method object you get back when you do the -=.
>
> We should see if there's a way for us to fix this to match expecations so I'll go ahead and make sure we get the bug filed.
>
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Giles Thomas
> Sent: Wednesday, February 01, 2006 11:10 AM
> To: Discussion of IronPython
> Subject: [IronPython] Issues with methods as event handlers?
>
> Hi all,
>
> When we use bound methods as Windows Forms event handlers, we can't
> detach them. Functions work OK.
>
> To see the problem, run up the attached button_method.py using
> IronPythonConsole; if you click on the "Trigger" button, you'll see a
> log message in the console saying that the trigger method has been
> called. Click on the "Remove" button to remove the event handler, and
> then click on the "Trigger" button again - you'll still get the log
> message. So the event handler was not detached correctly.
>
> By contrast, if you do the same thing using button_function.py, you will
> see that once you have clicked on "Remove", the "Trigger" button's
> handler will be correctly detached, so further clicks on that button
> will not generate log messages.
>
> We've tested against beta 2, beta 1, and 0.9.5 (which latter doesn't
> display the button labels but otherwise behaves as described above).
>
> Hope this helps someone :-)
>
>
> Cheers,
>
> Giles
More information about the Ironpython-users
mailing list