[Pyobjc-dev] method swizzing
Brought to you by:
ronaldoussoren
|
From: Daniel A. <an...@cc...> - 2009-05-22 14:54:44
|
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?
dan
|