[Pythonmac-SIG] Right init method

Aldo Bergamini aab.lists at nb-a.com
Mon Jul 4 17:01:35 CEST 2005


Dear list,

I have decided to try to practice pyObjC by translating (or trying to..)
the Objective-C examples of Aaron Hillegass' Cocoa Programming for MacOS
X, as I need to get up to date on Cocoa through Python.

I am trying to figure out how to translate the obj-C init method of the
SpeakLine example, chp 4.

The original obj-C is:

- (id)init
{

    [super init]

    NSLog(@"init");

    speechSynth = [[NSSpeechSynthetizer alloc] initWithVoice:nil];

    return self;

}

This is the init method of an application controller class, created
inside InterfaceBuilder..

I tried to translate it as:


class PySayTextAppDelegate(NibClassBuilder.AutoBaseClass):
    #    IB defined outlets
    #    textField
    #    speechSynthetizer
    #
    #    IB defined actions
    #    sayIt_
    #    stopIt_
    
    def __init__(self):
        
        super.__init__(self)
        
        NSLog("init")
        
        self.speechSynth = NSSpeechSynthetizer.alloc().initWithVoice_(nil)


This is a regular Python init method; I do not see the ''init" string in
the Console app . And therefore the synthetizer object is not created.

The same happens for this 'version':

    def init_(self):
        
        super.init_(self)
        
        NSLog("init")
        
        self.speechSynth = NSSpeechSynthetizer.alloc().initWithVoice_(nil)

The last one does 'build' but does not start:

    def init(self):
        
        super.init(self)
        
        NSLog("init")
        
        self.speechSynth = NSSpeechSynthetizer.alloc().initWithVoice_(nil)


Where can I findout how to initialize objects?

Thanks
Aldo




More information about the Pythonmac-SIG mailing list