[pyobjc] NSAutorelease support

Steven D. Majewski sdm7g at minsky.med.virginia.edu
Wed Nov 8 16:48:56 EST 2000


On Wed, 8 Nov 2000, Bill Bumgarner wrote:

> 
> - autorelease pools
> 
> I would much rather see support for autorelease pools as a call to the ObjC module.
> 
> I.e.
> 
> ObjC.pushReleasePool()
> ObjC.popReleasePool()
> 

I think this would be The Right Thing. Right now, I'm just taking
the path of least resistance while I bootstrap my understanding of
how it all works.  

 
> Appkit:
> 
> We will have to throw together a boostrapper that configures a mainBundle such  
> that it has the appropriate property lists and such.... I think there was a  
> discussion of doing wrapperless appkit apps on the osx-dev mailing list very  
> recently.

I had wondered (worried) about this earlier: it would be great to be able
to use InterfaceBuilder with Python, but I hoped that didn't mean you
couldn't also do it all programatically without GUI tools. ( As on 
current MacOS<10: you can use & load Resources, or you can define objects
procedurally. ) 

I cribbed the following code from Pete French <pete at toybox.twisted.org.uk>
post to <macosx-dev at omnigroup.com>, filled in the missing bits and 
turned his comments into Comments. Compiled and built without any
nibs or bundles, it does demonstrate it's possible. I would guess that
there's some pyobjc code that assumes that there is a bundle to load.  

-- Steve Majewski <sdm7g at Virginia.EDU>


#include <AppKit/AppKit.h>

main()
{

  NSAutoreleasePool *outer_pool;
  NSApplication *NSApp;
  NSWindow *theWindow;
  NSRect content_rect = { {100.0,100.0},{400,300} };

// For starters I make an application object and an outer autorelease
// pool for the program:

        outer_pool = [NSAutoreleasePool new];
        NSApp = [[NSApplication sharedApplication] retain];

// Then we create a window... (content rect is something sensible)

        theWindow = [[NSWindow alloc] initWithContentRect:content_rect
                styleMask:(NSTitledWindowMask |
NSMiniaturizableWindowMask)
                backing:NSBackingStoreRetained defer:NO];
        [theWindow setReleasedWhenClosed:YES];

// Send it to the front and fill it with grey

        [theWindow makeKeyAndOrderFront:nil];
        [[theWindow contentView] lockFocus];
        [[theWindow contentView] allocateGState];
        [[NSColor grayColor] set];
        NSRectFill((NSRect) {
                { 1, 1 },
                { content_rect.size.width , content_rect.size.height }
        } );
        [[theWindow contentView] unlockFocus];


        sleep(100);
}






More information about the Python-list mailing list