Hi all,
I attach an example of a workaround for the problem.
Cheers,
Giles
--
Giles Thomas
Resolver Systems
[EMAIL PROTECTED]
We're hiring! http://www.resolversystems.com/jobs/
Giles Thomas wrote:
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
import sys
sys.LoadAssemblyByName("System.Windows.Forms")
from System.Windows.Forms import *
class ClickListener:
def trigger(self, source, args):
print "clickListener called: ", self.trigger
clickListener = ClickListener()
def pseudoMethod(source, args):
clickListener.trigger(source, args)
print "Checking method equality: ", pseudoMethod == pseudoMethod
triggerButton = Button(Text = "Trigger")
triggerButton.Dock = DockStyle.Top
triggerButton.Click += pseudoMethod
removeButton = Button(Text = "Remove")
removeButton.Dock = DockStyle.Bottom
def remove(source, args):
print "Removing ", pseudoMethod
triggerButton.Click -= pseudoMethod
removeButton.Click += remove
form = Form()
form.Controls.Add(triggerButton)
form.Controls.Add(removeButton)
Application.Run(form)
_______________________________________________
users mailing list
users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com