Re: [Pyobjc-dev] method swizzing
Brought to you by:
ronaldoussoren
From: Jason F. <ja...@th...> - 2009-05-22 16:49:16
|
On Fri, May 22, 2009 at 8:51 AM, Daniel Ashbrook <an...@cc...> wrote: > I'm trying to make my program log every event that happens. I'm > probably doing it wrong. What I'm trying is: > > oldIMP = NSResponder.instanceMethodForSelector_('mouseDown:') > newIMP = objc.selector(lambda self, e: NSLog('%s: %s'%(self,e)), > selector=oldIMP.selector, signature=oldIMP.signature) > objc.classAddMethod(NSResponder, 'mouseDown:', newIMP) > > This works great - but only for clicking in places on the window that > don't already do anything. When I click on a NSButton, for example, I > don't get anything logged. > > I can go through and do the above for every subclass of NSResponder in > my program, but that gets a little bit pesky, especially because it > looks like I'd have to separately do it for things like the headers of > NSTableViews and so forth. > > Is there a better way? Swizzling sendEvent: in NSApplication might work better, as I think everything will go through that before being dispatched to a responder. Jason |