[Pyobjc-dev] problem accessing outlet
Brought to you by:
ronaldoussoren
From: Steven D. A. <st...@ne...> - 2002-10-29 06:42:55
|
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. 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' ) def __init__( self ): print "hello!" self.text.setStringValue_( "Hello World!" ) def sayIt( self ): self.text.setStringValue_( "Hello World, I am here!" ) sys.exit( AppKit.NSApplicationMain(sys.argv) ) 8. Build the project; if the project was called HelloWorld, you'll have a program called HelloWorld.app. When I build and run the program, the window comes up with the form elements I put in place. I can click the button (which is supposed to make an NSTextField say "hello world"), but nothing happens. In the run window of Project Builder, I see the following messages: foo 2002-10-29 01:36:19.450 pysample[784] Could not connect the action sayIt: to target of class HelloWorld 2002-10-29 01:36:19.672 pysample[784] Can't open input server /Library/InputManagers/Menu Extra Enabler Note that it printed the "foo" that I put in my program, above! However, the "hello" that I print in __init__ never gets displayed. So apparently my file is being processed by no instance of HelloWorld is ever being created -- which may explain why it couldn't connect sayIt to my class. So my question is why am I getting the results I'm getting instead of a correct connection to the sayIt method? steve -- |