-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
thanks for answering!..
I feel pretty stupid for saying this but I dont understand whats
happening when the Bind() function its called...
If I have something like this:
SomeObject.Bind(wx.SOME_EVENT, self.SomeHandler)
I believe that internally the Bind() method its calling the
SomeHandler() method. What I wanna know its how is this being
called?, is it called like this?:
self.SomeHandler(self, SomeObject)
No, I believe that the Bind function is adding an entry to an event
handle table for the object/window/application
Correct, it simply adds to a table of event binding info. The self.SomeHandler is *not* called at the time of the Bind, it is called later when an event happens that matches the table information, (source, ID, type, etc. ) This is what "event-driven programming" is all about. You tell the framework want you want it to do when something happens, and then sit back and wait for the something to happen.
from your reply I believe thats not whats happening, because
otherwise I wouldn't need to use the GetEventObject to get the
object later..
[1]
So, my doubt is, what is that second argument being pass?
The object passed to SomeHandler is constructed at the time time that the event happens, just before the call to SomHandler is made. It is an instance of some class derived from wx.Event and it simply holds information about the event and where it came from. For example for a wx.EVT_KEY_DOWN you'll get a wx.KeyEvent that holds information about the key that was pressed, the current state of the modifier keys, etc. For a wx.EVT_SIZE you'll get an instance of wx.SizeEvent that can give you the new size of the window.
Try doing a "print event" in your handlers to see what you are getting.
[1] Just for the record you won't need to use GetEventObject most of the time, but it is helpful when you may be binding the same handler function for events that may be originating from multiple source objects. For example, if I do:
self.Bind(wx.EVT_BUTTON, self.OnButton)
without telling it which button I want to get events from, then OnButton will be called for *any* button that is within the scope of (children, grandchildren of) the self window.
···
On 4/16/11 3:24 AM, Gadget/Steve wrote:
On 16/04/2011 7:20 AM, PythonJourney wrote:
--
Robin Dunn
Software Craftsman