Thread: [Pyobjc-dev] CurrencyConverter for XCode/IB 3.0
Brought to you by:
ronaldoussoren
From: Steve S. <sst...@ma...> - 2008-05-01 02:30:38
|
Sorry if this is a dumb question, I'm recently resubscribed to the list and didn't find anything about my question it in the archives. So... I'm using XCode/IB 3.0. I want to make the CurrencyConverter example code as clean as possible by removing all the no-longer-necessary cruft. In the code below, I've eliminated a ton of imports, and removed the Nibclassbuilder references. I _think_ I had to add the objc.ivar calls that were handled by the Nibclassbuilder but I'd love to be enlightened if there's a better way to do it. I'm a little confused since the comments reference 'ivar' calls that were not in the actual code. When I put them in, I stopped getting errors related to the ivars not existing. At this point, the code fails with: TypeError: Use class methods to instantiate new Objective-C objects Console says: 4/30/08 10:25:20 PM CurrencyConverter[9877] CurrencyConverterObjC Error An unexpected error has occurred during execution of the main script TypeError: Use class methods to instantiate new Objective-C objects 4/30/08 10:26:14 PM com.apple.launchd[113] ([0x0-0x3f13f1].org.pythonmac.unspecified.CurrencyConverter[9877]) Exited with exit code: 255 when trying to create the self.converter (is it an IBOutlet?) Any help would be greatly appreciated. I'm planning on going through each example, bringing them into an XCode project and de-cruftifying them so that I understand everything that's going on. Sure would be nice to have in the official distribution... Thanks in advance for any assistance. S #------------------------------------------------------------------- import time import sys from Foundation import * from AppKit import * from PyObjCTools import AppHelper class Converter (NSObject): def convertAmount(self, amt, rate): return amt*rate class ConverterController (NSObject): # First define the IB Outlets, the 'ivar' calls below define new # instance variables in the objective-C class (e.g. visible # for introspection in objective-C) dollarField = objc.ivar (u'dollarField') rateField = objc.ivar (u'rateField') converter = Converter() def __init__(self): self.converter = Converter() self = super(ConverterController, self).init() return self def awakeFromNib(self): # Provide some defaults for the user... #self.converter = Converter() self.dollarField.setFloatValue_(2.0) self.rateField.setFloatValue_(3.0) def convert_(self, sender): rate = self.rateField.floatValue() amt = self.dollarField.floatValue() total = self.converter.convertAmount(rate, amt) self.totalField.setFloatValue_(total) self.rateField.selectText_(self) x = NSRunAlertPanel("Calculation Result", "The result is %s"%(total), "OK", None, None) # pass control to AppKit AppHelper.runEventLoop() |
From: Daniel C. <cas...@np...> - 2008-05-01 11:16:36
|
On Wed, 2008-04-30 at 22:30 -0400, Steve Steiner wrote: > TypeError: Use class methods to instantiate new Objective-C objects > You cannot instantiate NSObject classes using the normal Python convention. These are Objective C classes, so you need to do it the Objective C way (NSObject.alloc().init()) Try changing lines like: self.converter = Converter() to self.converter = Converter.alloc().init() -- Daniel Casimiro <cas...@np...> |
From: s s <li...@in...> - 2008-05-02 02:56:13
|
On May 1, 2008, at 7:13 AM, Daniel Casimiro wrote: > > On Wed, 2008-04-30 at 22:30 -0400, Steve Steiner wrote: >> TypeError: Use class methods to instantiate new Objective-C objects >> > > You cannot instantiate NSObject classes using the normal Python > convention. These are Objective C classes, so you need to do it the > Objective C way (NSObject.alloc().init()) > > Try changing lines like: > > self.converter = Converter() > > to > > self.converter = Converter.alloc().init() I knew it was something obvious I was overlooking. Got it working about 2 seconds after I got your message. Thanks for your help! S |
From: s s <li...@in...> - 2008-05-02 03:12:25
|
Thanks to Daniel, I got the CurrencyConverter app running without all the PyObjc 1.x cruft and without inheriting from NibClassBuilder.AutoBaseClass. Unfortunately, I seem to have had to go back to the old days of declaring all ObjC ivars manually: class ConverterController (NSObject): dollarField = objc.ivar (u'dollarField') rateField = objc.ivar (u'rateField') totalField = objc.ivar(u'totalField') converter = objc.ivar(u'converter') i.e. the instance vars don't come over from IB as they did when classes inherited from NibClassBuilder.AutoBaseClass. So, my question is: How would one get the same result as inheriting from NibClassBuilder.AutoBaseClass, in XCode/IB 3.x Thanks in advance for any assistance. S |
From: Orestis M. <or...@or...> - 2008-05-13 23:08:12
|
Hi, can you post somewhere the code? I'm struggling with PyObjC and all the Google results are very old... Regards, -- Orestis Markou or...@or... http://orestis.gr/ On 02 Μαϊ 2008, at 4:12 ΠΜ, s s wrote: > Thanks to Daniel, I got the CurrencyConverter app running without all > the PyObjc 1.x cruft and without inheriting from > NibClassBuilder.AutoBaseClass. > > Unfortunately, I seem to have had to go back to the old days of > declaring all ObjC ivars manually: > > class ConverterController (NSObject): > dollarField = objc.ivar (u'dollarField') > rateField = objc.ivar (u'rateField') > totalField = objc.ivar(u'totalField') > converter = objc.ivar(u'converter') > > i.e. the instance vars don't come over from IB as they did when > classes inherited from NibClassBuilder.AutoBaseClass. > > So, my question is: > > How would one get the same result as inheriting from > NibClassBuilder.AutoBaseClass, in XCode/IB 3.x > > Thanks in advance for any assistance. > > S > > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by the 2008 JavaOne(SM) Conference > Don't miss this year's exciting event. There's still time to save > $100. > Use priority code J8TL2D2. > http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: s s <li...@in...> - 2008-05-13 23:52:17
|
On May 13, 2008, at 7:08 PM, Orestis Markou wrote: > Hi, > > can you post somewhere the code? I'm struggling with PyObjC and all > the Google results are very old... Yes, I had the same problem, at first. I'll put the CurrencyConverter up on my blog and post a link to it to the list. I'm writing quite a bit of stuff about the new ways of doing things that should help anyone struggling with some of the new ways of doing things. S > > > Regards, > -- > Orestis Markou > or...@or... > http://orestis.gr/ > > > > > On 02 Μαϊ 2008, at 4:12 ΠΜ, s s wrote: > >> Thanks to Daniel, I got the CurrencyConverter app running without all >> the PyObjc 1.x cruft and without inheriting from >> NibClassBuilder.AutoBaseClass. >> >> Unfortunately, I seem to have had to go back to the old days of >> declaring all ObjC ivars manually: >> >> class ConverterController (NSObject): >> dollarField = objc.ivar (u'dollarField') >> rateField = objc.ivar (u'rateField') >> totalField = objc.ivar(u'totalField') >> converter = objc.ivar(u'converter') >> >> i.e. the instance vars don't come over from IB as they did when >> classes inherited from NibClassBuilder.AutoBaseClass. >> >> So, my question is: >> >> How would one get the same result as inheriting from >> NibClassBuilder.AutoBaseClass, in XCode/IB 3.x >> >> Thanks in advance for any assistance. >> >> S >> >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference >> Don't miss this year's exciting event. There's still time to save >> $100. >> Use priority code J8TL2D2. >> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone >> _______________________________________________ >> Pyobjc-dev mailing list >> Pyo...@li... >> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2008. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |
From: Orestis M. <or...@or...> - 2008-05-14 23:00:50
|
IME, if you define an IBOutlet rather than an ivar, IB will pick that up on save. Is that what you're referring to? -- Orestis Markou or...@or... http://orestis.gr/ On 14 Μαϊ 2008, at 12:51 ΠΜ, s s wrote: > > > > On May 13, 2008, at 7:08 PM, Orestis Markou wrote: > >> Hi, >> >> can you post somewhere the code? I'm struggling with PyObjC and all >> the Google results are very old... > > Yes, I had the same problem, at first. > > I'll put the CurrencyConverter up on my blog and post a link to it > to the list. > > I'm writing quite a bit of stuff about the new ways of doing things > that should help anyone struggling with some of the new ways of > doing things. > > S > > >> >> >> Regards, >> -- >> Orestis Markou >> or...@or... >> http://orestis.gr/ >> >> >> >> >> On 02 Μαϊ 2008, at 4:12 ΠΜ, s s wrote: >> >>> Thanks to Daniel, I got the CurrencyConverter app running without >>> all >>> the PyObjc 1.x cruft and without inheriting from >>> NibClassBuilder.AutoBaseClass. >>> >>> Unfortunately, I seem to have had to go back to the old days of >>> declaring all ObjC ivars manually: >>> >>> class ConverterController (NSObject): >>> dollarField = objc.ivar (u'dollarField') >>> rateField = objc.ivar (u'rateField') >>> totalField = objc.ivar(u'totalField') >>> converter = objc.ivar(u'converter') >>> >>> i.e. the instance vars don't come over from IB as they did when >>> classes inherited from NibClassBuilder.AutoBaseClass. >>> >>> So, my question is: >>> >>> How would one get the same result as inheriting from >>> NibClassBuilder.AutoBaseClass, in XCode/IB 3.x >>> >>> Thanks in advance for any assistance. >>> >>> S >>> >>> >>> >>> ------------------------------------------------------------------------- >>> This SF.net email is sponsored by the 2008 JavaOne(SM) Conference >>> Don't miss this year's exciting event. There's still time to save >>> $100. >>> Use priority code J8TL2D2. >>> http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone >>> _______________________________________________ >>> Pyobjc-dev mailing list >>> Pyo...@li... >>> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Microsoft >> Defy all challenges. Microsoft(R) Visual Studio 2008. >> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ >> _______________________________________________ >> Pyobjc-dev mailing list >> Pyo...@li... >> https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > |