Re: [Pyobjc-dev] HelloWorld.py (demo code)
Brought to you by:
ronaldoussoren
From: Bill B. <bb...@co...> - 2001-04-06 20:46:07
|
Very nice! Very, very cool.... a HUGE bit of progress here. Add an Examples/ directory to the sourceforge repository (if it isn't already there) and shove this into the examples. I'll have to resurrect my services provider. b.bum On Friday, April 6, 2001, at 04:15 PM, Steven D. Majewski wrote: > # HelloWorld.py > # > # You have to run this script from the command line with > # the full pathname for python: > # /usr/local/bin/python HelloWorld.py > # > # or else run from DropShell or gdb. Anything else and you will get a: > # Error 1011 in _sendFinishLaunchingNotification > # and it wont work. > # > # -- Steve Majewski <sd...@Vi...> > # > > import pyobjc > from time import sleep > > rt = pyobjc.runtime > > def main(): > > pool = rt.NSAutoreleasePool() > # Load Application Framework: > rt.NSBundle.bundleWithPath_( > '/System/Library/Frameworks/AppKit.framework').load() > > NSApp = rt.NSApplication.sharedApplication() > > win = rt.NSWindow.alloc() > frame = ((200.0, 300.0), (250.0, 100.0)) > win.initWithContentRect_styleMask_backing_defer_ (frame, 15, 2, 0) > win.setTitle_ ('HelloWorld') > win.setLevel_ (3) # floating window > > hel = rt.NSButton.alloc().initWithFrame_ (((10.0, 10.0), (80.0, > 80.0))) > win.contentView().addSubview_ (hel) > hel.setBezelStyle_( 4 ) > hel.setTitle_( 'Hello!' ) > > beep = rt.NSSound.alloc() > beep.initWithContentsOfFile_byReference_( > '/System/Library/Sounds/tink.aiff', 1 ) > hel.setSound_( beep ) > > bye = rt.NSButton.alloc().initWithFrame_ (((100.0, 10.0), (80.0, > 80.0))) > win.contentView().addSubview_ (bye) > bye.setBezelStyle_( 4 ) > bye.setTarget_ (NSApp) > bye.setAction_ ('stop:') > bye.setEnabled_ ( 1 ) > bye.setTitle_( 'Goobye!' ) > > adios = rt.NSSound.alloc() > adios.initWithContentsOfFile_byReference_( > '/System/Library/Sounds/Basso.aiff', 1 ) > bye.setSound_( adios ) > > win.display() > # win.makeKeyAndOrderFront_ (NSApp) ## This doesn't seem to work > win.orderFrontRegardless() ## but this one does > > NSApp.run() > > > if __name__ == '__main__' : main() |