[Pythonmac-SIG] Umpteen styles of Aqua UI programming - need examples

bill fancher fancher@pacbell.net
Tue, 15 Jan 2002 15:33:17 -0800


On Tuesday, January 15, 2002, at 04:31  AM, Jack Jansen wrote:

> How about picking a single simple example, like Apple's own currency 
> converter
> example, and building that with all the various toolkits we have, so 
> that we
> can all see what the advantages and drawbacks of the various methods 
> are?

For ASS/OSA Python: select "New Project" in PB and choose "Python 
Application". In your new project, double-click "Main.nib" to start IB.

In IB, drag three NSTextFields and an NSButton to your window. Add 
labels, image, tab order support as in Apple example. Select 
"AppleScript" from the pulldown in the NSButton Info window and check 
"clicked" and "Application.applescript". Give the fields some names (I 
used "rate", "amount" and "result".) Drop an NSNumberFormatter on each 
field to let Cocoa handle input validation and numeric conversion.

In PB, enter the following in "Application.applescript":

def clicked(theObject):
	w = theObject.super_view
	rate = w.text_field['rate'].contents._value
	amount = w.text_field['amount'].contents._value
	w.text_field['result'].contents =  rate * amount

Click "Build". Done.

Some advantages: Uses standard Apple supported tools. Leverages ASK. 
Easy to combine Python, C, Objc, C++ in the same project. 
Interapplication communication is trivial. Python HTML documentation 
accessible from PB.

Fringe benefits: OSA component enables Python 
scripting/recording/execution in Script Editor and other OSA aware apps. 
Use Script Editor to create applets or droplets. Use Standard Additions 
for UI. (Maybe you don't need all the power of PB/IB. This is yet 
another route to basic Aqua UI.)

Some drawbacks: Not standalone; apps require OSA component and Python 
framework. Not cross-platform. Communicates with interface via 
AppleEvents, which have a fair amount of overhead. Tools currently 
AppleScript-centric. No debugger support yet.

--
bill