 you have the code you are testing with so far?.
b.bum
From: "Steven D. Majewski" <sdm7g@...>
Date: 2000-12-20 17:38:08 -0500
To: pyobjc-dev@...
Subject: [Pyobjc-dev] working code examples ?
List-Id: python<->ObjC module dev discussion
<pyobjc-dev.lists.sourceforge.net>
MMDF-Warning: Parse error in original version of preceding line at
mail.virginia.edu
List-Post: <mailto:pyobjc-dev@...>
X-BeenThere: pyobjc-dev@...
List-Unsubscribe:
<>,<mailto:pyobjc-dev-request@...?subject=unsubscribe>
List-Help:
<mailto:pyobjc-dev-request@...?subject=help>
X-Mailman-Version: 2.0
List-Archive: <>
List-Subscribe:
<>,<mailto:pyobjc-dev-request@...?subject=subscribe>
BTW: Does anyone have any examples of code that actually works
under Mac OSX ?
I can get a window with a button to pop up (starting from some
example code from one of the older snapshots on codefab.com --
LBW.py -- "little button window" ) but none of the "application"
stuff works -- i.e. I can't get it to quit from the button.
BTW: a few notes for those trying to get started:
import ObjC
rt = ObjC.runtime
# You need to create an autorelease pool to avoid all of those annoying
# 'no pool -- just leaking' warning messages:
POOL = rt.NSAutoreleasePool
p = POOL()
# and if you want to access AppKit classes from the runtime,
# you have to load that bundle:
rt.NSBundle.bundleWithPath_('/System/Library/Frameworks/AppKit.framework').load()
... and if you're testing out some code and actually want to see what
happens to your window while you're in the python interpreter in a
terminal.app window, you can make your AppKit window a floating window
with setLevel:
win.setLevel_ (3)
-- Steve Majewski <sdm7g@...>
_______________________________________________
Pyobjc-dev mailing list
Pyobjc-dev@...
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 <sdm7g@...>
#
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()
There's been a discussion thread on macosx-dev@... on
how to get all of the methods of a class. ( I'ld like to give
pyobjc classes the same sort of introspection capabilities that
normal python objects have. )
I got some objc code from Pierre Thibault (on that list) that
implements some introspection classes for obj-c. ( It doesn't
seem to get all of the methods from all of the categories -- which
is part of the ongoing discussion in that thread. )
If he publicly releases that code, I'll make the framework and
my python wrapper code available. In any case, I'ld like to see
some similar functionality built into pyobjc. ( I'm used to using
dir() and __doc__ to figure out how to use python modules -- it
was a bit confusing to find that all pyobjc classes seem to have
the same three attributes: ['Class', 'isClass', 'isInstance'], and
nothing else. ( The runtime checks that the class responds to the
selector you give it, but it can't tell you all of the selectors. )
-- Steve Majewski <sdm7g@...>
ToDo's:
[1] make a todo list.
[2] Get a snapshot of Python2.0 with the objc patches online
as well as a pyobjc snapshot on sourceforge.
[3] documentation, documentation, documentation...
[4] examples, examples, examples...
[5] Fix NSProxy/OC_PythonObject problems.
[6] start a module of useful utility and wrapper functions, for example:
rt = ObjC.runtime # abbreviations
def LoadBundle( path ):
Bundle = rt.NSBundle
bundle = Bundle.bundleWithPath_( path )
bundle.load()
return bundle
used as:
AppKit = LoadBundle( '/System/Library/Frameworks/AppKit.framework')
( maybe also a more abbreviated NSAutoreleasePool creation -- it
would be handy for interactive use . What else? )
-- Steve Majewski <sdm7g@...>
On Wed, 20 Dec 2000, Bill Bumgarner wrote:
> Do you have the code you are testing with so far?
It's pretty chopped up at the moment -- which is why I was
asking if anyone had a better sample. I've got sections that
weren't working commented out, but I need to retest some of that
code with the new build. I've started -- which is why I added the
note about loading the AppKit bundle -- my old version had that
linked in. etc. etc.
>.
>
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
-- Steve Majewski