Re: [Pyobjc-dev] problem accessing outlet
Brought to you by:
ronaldoussoren
From: <bb...@ma...> - 2002-10-29 13:19:47
|
On Tuesday, October 29, 2002, at 01:42 AM, Steven D. Arnold wrote: > I appreciate the helpful answers I've gotten so far from Ronald and > Bill. I > hate to ask so many questions, but I think I'm very close to a working > Python/Cocoa application. This is extremely valuable feedback -- every question helps us to understand where we need to provide better documentation or better examples. > I've done as I said in a previous post: > > 1. Start PB, create Cocoa app > 2. Open resources, double-click the IB icon > 3. Create a subclass of NSObject, in my case HelloWorld > 4. Create an outlet called "text" which is the NSTextField intended to > display the "Hello World" message > 5. Create an action called "sayIt" which is wired to a button on the > form > 6. Modify main.m to look exactly as described in Ronald's TableModel2 > project > 7. Create a file Main.py which is in the "Other Sources" in my project. > This file looks like this: > > import sys > import os.path > > sys.path.insert( 0, os.path.join( sys.path[ 0 ], "pyobjc" ) ) > > import objc > import Foundation > import AppKit > print "foo" > > class HelloWorld(Foundation.NSObject): > __slots__ = ( 'text' ) For an outlet, replace the above line with this: text = objc.IBOutlet('text') I wonder if there is a way to remove this requirement? I'll have to investigate the whole IBConnection stuff -- I just did a boat load of custom IB work (converting NIB files from NS 3.3 -> OS X) and the APIs are still fresh. > def __init__( self ): > print "hello!" > self.text.setStringValue_( "Hello World!" ) This should just be init() and it should return self. However... For initialization from a NIB file, implement awakeFromNib() -- there are cases where the object might be instantiated before the NIB is loaded (NIB loading takes a significant hunk of time -- lazy loading the NIB for a piece of UI that the user may not use can increase perceived performance). From the currency example: def awakeFromNib(self): print "awakeFromNib" # Provide some defaults for the user... self.dollarField.setFloatValue_(2.0) self.rateField.setFloatValue_(3.0) > def sayIt( self ): > self.text.setStringValue_( "Hello World, I am here!" ) An action method takes a single argument, the sender of the action. So, this should be: def sayIt_( self, sender ): self.text.setStringValue_( "Hello World, I am here!" ) b.bum |