[Pythonmac-SIG] Re: [Pyobjc-dev] @selector(mymethod:) with pyobjc?

Bob Ippolito bob at redivi.com
Thu Jan 20 19:56:05 CET 2005


On Jan 20, 2005, at 10:43, Just van Rossum wrote:

> whamoo wrote:
>
>> I'm writing an application with dinamic menu (NSMenu - NSMenuItem),
>> but i've some problem with this function:
>> [[NSMenuItem alloc] initWithTitle:action:keyEquivalent:]
>>
>> I want to pass to "action:" a function of my class, in objc i must use
>> this code @selector(mioMetodo:)
>> In Python how to translate this?
>>
>> menuitem =
>> NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(str(a), "Here
>> the code" , "")
>
> menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
>            str(a), "mioMetodo:" , "")

menuitem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_(
	unicode(a), "mioMetodo:", "")

Note that you need to name your method mioMetodo_ -- it needs to match 
that selector (replacing colons by underscores).  This should be 
documented in the PyObjC introduction.

-bob



More information about the Pythonmac-SIG mailing list