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
--
Giles Thomas
Resolver Systems
[EMAIL PROTECTED]
We're hiring! http://www.resolversystems.com/jobs/
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()
print "Checking method equality: ", clickListener.trigger ==
clickListener.trigger
triggerButton = Button(Text = "Trigger")
triggerButton.Dock = DockStyle.Top
triggerButton.Click += clickListener.trigger
removeButton = Button(Text = "Remove")
removeButton.Dock = DockStyle.Bottom
def remove(source, args):
print "Removing ", clickListener.trigger
triggerButton.Click -= clickListener.trigger
removeButton.Click += remove
form = Form()
form.Controls.Add(triggerButton)
form.Controls.Add(removeButton)
Application.Run(form)
import sys
sys.LoadAssemblyByName("System.Windows.Forms")
from System.Windows.Forms import *
def click(source, args):
print "clickListener called: ", click
print "Checking method equality: ", click == click
triggerButton = Button(Text = "Trigger")
triggerButton.Dock = DockStyle.Top
triggerButton.Click += click
removeButton = Button(Text = "Remove")
removeButton.Dock = DockStyle.Bottom
def remove(source, args):
print "Removing ", click
triggerButton.Click -= click
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