The following example was offered up as a demonstration of how
specifying the source of an event in Bind() works when you write
something like this:
aframe.Bind(event, eventHandler, sourceOfEvent)
Here's the code:
···
--------
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
panel = wx.Panel(self)
button = wx.Button(panel, -1, "Close", pos=(130,15), size=(60,40) )
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
def OnCloseMe(self, event):
print "button was clicked"
self.Close(True)
def OnCloseWindow(self, event):
print "window was x'ed out"
self.Destroy()
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()
--------
Yet, the code appears to work exactly the same way when you
don't specify "button" as the source. That doesn't seem like a
very good example to me. The following is the kind of example
I would show someone who wanted to learn what the "source"
parameter in Bind() does:
---------
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
panel = wx.Panel(self)
button1 = wx.Button(panel, -1, "Button1", pos=(130,15), size=(100,40) )
button2 = wx.Button(panel, -1, "Button2", pos=(130,50), size=(100,40) )
self.Bind(wx.EVT_BUTTON, self.OnAnyButtonClick)
#self.Bind(wx.EVT_BUTTON, self.OnButton1Click, button1)
#self.Bind(wx.EVT_BUTTON, self.OnButton2Click, button2)
def OnAnyButtonClick(self, event):
print "Some button was clicked"
def OnButton1Click(self, event):
print "Button1 was clicked"
def OnButton2Click(self, event):
print "Button2 was clicked"
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show()
app.MainLoop()
---------
I would tell them to run that program, then uncomment the two lines
and take a guess at what the new output might be, and then run the
program again.