Re: [Pyobjc-dev] working code examples ?
Brought to you by:
ronaldoussoren
|
From: Steven D. M. <sd...@mi...> - 2000-12-23 03:26:45
|
On Wed, 20 Dec 2000, Steven D. Majewski wrote:
> On Wed, 20 Dec 2000, Bill Bumgarner wrote:
>
> > Do you have the code you are testing with so far?
>
> I am doing the setTarget: setAction: calls.
> I'm not using IB, but maybe I still need to define a delegate --
> the error I'm getting is:
>
> Error 1011 in _sendFinishLaunchingNotification
>
I've cleaned up the code a bit. (Enclosed Below).
If run normally from python, it displays the window, but doesn't respond
to a button down, prints the above error message, and gets stuck in the
run loop so I have to kill the process from another terminal window.
However, I've discovered that if I run it from python under gdb, it
works properly: I can grab and move the window and on button down,
it exits the run-loop and gives me a python prompt!
Any clues ???
% gdb python
(gdb) run
...
>>> import LBW
>>> LBW.run()
-- Steve Majewski
#!/usr/local/bin/python
#
# Heavily modified following an example by Lele Gaifax
# that no longer works under OSX.
# This seems to work under 'gdb python', but not without the debugger. (?)
#
# -- Steve Majewski <sd...@Vi...>
#
from time import sleep
def run():
import ObjC
rt = ObjC.runtime
POOL = rt.NSAutoreleasePool
p = POOL()
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_ ('Little.Button.Window')
win.setLevel_ (3) # floating window
but = rt.NSButton.alloc().initWithFrame_ (((10.0, 10.0), (80.0, 80.0)))
win.contentView().addSubview_ (but)
but.setBezelStyle_( 4 )
but.setTarget_ (NSApp)
but.setAction_ ('stop:')
but.setEnabled_ ( 1 )
win.display()
# win.makeKeyAndOrderFront_ (NSApp) ## This doesn't seem to work
win.orderFrontRegardless() ## but this one does
for i in range(5): ## testing: change button hilight display
but.highlight_( i % 2 )
win.display()
sleep(1)
NSApp.run()
if __name__ == '__main__' : run()
|