Re: [Pythonmac-SIG] Right init method
On Jul 4, 2005, at 9:31 AM, Jacob Kaplan-Moss wrote: > On Jul 4, 2005, at 12:39 PM, Bob Ippolito wrote: > >> Also, READ THE DOCS and examples please, this is most definitely >> covered a thousand times :) >> > > Lighten up, Bob; this isn't explicitly mentioned anywhere -- it > only shows up once in a comment on the intro page (http:// > pyobjc.sourceforge.net/doc/intro.php#objective-c-for-pyobjc-users), > and it's easy to miss (I know I did when I was getting started). > Perhaps this one should be added to the FAQ? It is used in nearly every single example, though. I guess it should be reworded to be more obvious in the docs. -bob ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Right init method
On Jul 4, 2005, at 12:39 PM, Bob Ippolito wrote: > Also, READ THE DOCS and examples please, this is most definitely > covered a thousand times :) Lighten up, Bob; this isn't explicitly mentioned anywhere -- it only shows up once in a comment on the intro page (http:// pyobjc.sourceforge.net/doc/intro.php#objective-c-for-pyobjc-users), and it's easy to miss (I know I did when I was getting started). Perhaps this one should be added to the FAQ? Jacob ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Right init method
On Jul 4, 2005, at 6:23 AM, Jacob Kaplan-Moss wrote: > Aldo -- > > PyObjC classes (that is, Python classes that extend ObjC ones, like > you're trying there) don't use the standard __init__ mechanism (at > least, not in a useful way). They do use the standard alloc/init > mechanism from ObjC, so you're on the right track in your last try: > > >> def init(self): >> super.init(self) >> NSLog("init") >> self.speechSynth = NSSpeechSynthetizer.alloc >> ().initWithVoice_(nil) >> > > The only think you're missing is a "return self" -- ObjC init methods > always return self, so you have to do the same from PyObjC. def init(self): self = super(PySayTextAppDelegate, self).init() return self Also, READ THE DOCS and examples please, this is most definitely covered a thousand times :) -bob ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
Re: [Pythonmac-SIG] Right init method
Aldo -- PyObjC classes (that is, Python classes that extend ObjC ones, like you're trying there) don't use the standard __init__ mechanism (at least, not in a useful way). They do use the standard alloc/init mechanism from ObjC, so you're on the right track in your last try: > def init(self): > super.init(self) > NSLog("init") > self.speechSynth = NSSpeechSynthetizer.alloc > ().initWithVoice_(nil) The only think you're missing is a "return self" -- ObjC init methods always return self, so you have to do the same from PyObjC. Hope that helps, Jacob ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig
[Pythonmac-SIG] Right init method
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 ___ Pythonmac-SIG maillist - Pythonmac-SIG@python.org http://mail.python.org/mailman/listinfo/pythonmac-sig