Re: [Pyobjc-dev] @selector(mymethod:) with pyobjc?
Brought to you by:
ronaldoussoren
From: Bob I. <bo...@re...> - 2005-01-20 20:17:31
|
On Jan 20, 2005, at 14:50, Ryan Wilcox wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > Bob Ippolito wrote: > > | menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( > | unicode(a), "mioMetodo:", "") > > When do you pass the function object, and when do you pass a string > with > the function name? > > Although, yes, my earlier example, at the very least, should have read: > > menuItem = NSMenuItem.......( unicode(a), self.mioMetodo_ "" ) > #assuming mioMetodo exists in self > > > Because I know that passing the function object has worked for me in > the > past... You can never pass a function object. You must pass a selector. You can either pass the selector by name (as in 'mioMetodo:') or by object reference (MyClass.mioMetodo_ or myInstance.mioMetodo_), but it MUST be a selector. If you pass it a selector object, it will only use the name of that selector, since Objective-C separates target from selector (does not use bound methods) where Python doesn't (uses bound methods). You might think these are function (or method) objects, but they're not, because whenever you subclass an Objective-C class, the "metaclass" will mutate your class dict and change them to selectors. -bob |