The I have only glanced at evilphilip's stuff once out of curiosity, but c_void_p appears to be a straightforward wrapper, and the initial diff is mostly about setting up the app menu (which I think should be kept or toggled as a preference, since well-behaved Cocoa apps take the trouble to put up something on the menu bar).
The third bit (quartz) appears to be merely added cleanups. My Quartz is a little rusty, but those feel like they ought to be required. R. On Jun 15, 2012, at 23:07 , Winston Wolff wrote: > FYI, I'm trying a merge of evilphillip-cocoa-ctypes2 into pyglet. There are > 16 files updated and three files with conflicts: > - pyglet/app/cocoa.py > - pyglet/image/codecs/quartz.py > - pyglet/window/cocoa/__init__.py > > They don't look too bad but I think it would be better if someone more > familiar with the code tried to fix it. Below are snippets to give you an > idea of what we're up against. > > ================ > pyglet/app/cocoa.py > ================ > > class CocoaEventLoop(PlatformEventLoop): > > def __init__(self): > super(CocoaEventLoop, self).__init__() > # Prepare the default application. > self.NSApp = NSApplication.sharedApplication() > # Create an autorelease pool for menu creation and finishLaunching > <<<<<<< local > pool = NSAutoreleasePool.alloc().init() > self._create_application_menu() > NSApp().setActivationPolicy_(0) # Mac OS X 10.6 > NSApp().finishLaunching() > NSApp().activateIgnoringOtherApps_(True) > # Then get rid of the pool when we're done. > del pool > > def _create_application_menu(self): > # Sets up a menu and installs a "quit" item so that we can use > # Command-Q to exit the application. > # See > http://cocoawithlove.com/2010/09/minimalist-cocoa-programming.html > # This could also be done much more easily with a NIB. > menubar = NSMenu.alloc().init() > appMenuItem = NSMenuItem.alloc().init() > menubar.addItem_(appMenuItem) > NSApp().setMainMenu_(menubar) > appMenu = NSMenu.alloc().init() > processName = NSProcessInfo.processInfo().processName() > hideItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( > "Hide " + processName, "hide:", "h") > appMenu.addItem_(hideItem) > appMenu.addItem_(NSMenuItem.separatorItem()) > quitItem = NSMenuItem.alloc().initWithTitle_action_keyEquivalent_( > "Quit " + processName, "terminate:", "q") > appMenu.addItem_(quitItem) > appMenuItem.setSubmenu_(appMenu) > ======= > self.pool = NSAutoreleasePool.alloc().init() > create_menu() > self.NSApp.setActivationPolicy_(NSApplicationActivationPolicyRegular) > self.NSApp.finishLaunching() > self.NSApp.activateIgnoringOtherApps_(True) >>>>>>>> other > > > > ===================== > pyglet/image/codecs/quartz.py > ======================== > > class QuartzImageDecoder(ImageDecoder): > def get_file_extensions(self): > # Quartz can actually decode many more formats, but these are the most > common. > return [ '.bmp', '.cur', '.gif', '.ico', '.jp2', '.jpg', '.jpeg', > '.pcx', '.png', '.tga', '.tif', '.tiff', '.xbm', '.xpm' ] > > def get_animation_file_extensions(self): > return ['.gif'] > > def _get_pyglet_ImageData_from_source_at_index(self, sourceRef, index): > <<<<<<< local > imageRef = Quartz.CGImageSourceCreateImageAtIndex(sourceRef, index, > None) > > ======= > imageRef = c_void_p(quartz.CGImageSourceCreateImageAtIndex(sourceRef, > index, None)) > >>>>>>>> other > # Regardless of the internal format of the image (L, LA, RGB, RGBA, > etc) > # we just automatically convert everything to an RGBA format. > format = 'RGBA' > <<<<<<< local > rgbColorSpace = Quartz.CGColorSpaceCreateDeviceRGB() > ======= > rgbColorSpace = c_void_p(quartz.CGColorSpaceCreateDeviceRGB()) >>>>>>>> other > bitsPerComponent = 8 > <<<<<<< local > width = Quartz.CGImageGetWidth(imageRef) > height = Quartz.CGImageGetHeight(imageRef) > ======= > width = quartz.CGImageGetWidth(imageRef) > height = quartz.CGImageGetHeight(imageRef) >>>>>>>> other > bytesPerRow = 4 * width > > # Create a buffer to store the RGBA formatted data. > bufferSize = height * bytesPerRow > buffer = (c_byte * bufferSize)() > > # Create a bitmap context for the RGBA formatted data. > <<<<<<< local > bitmap = Quartz.CGBitmapContextCreate(buffer, > width, height, > bitsPerComponent, > bytesPerRow, > rgbColorSpace, > > Quartz.kCGImageAlphaPremultipliedLast) > > ======= > # Note that premultiplied alpha is required: > # http://developer.apple.com/library/mac/#qa/qa1037/_index.html > bitmap = c_void_p(quartz.CGBitmapContextCreate(buffer, > width, height, > bitsPerComponent, > bytesPerRow, > rgbColorSpace, > > kCGImageAlphaPremultipliedLast)) > >>>>>>>> other > # Write the image data into the bitmap. > <<<<<<< local > Quartz.CGContextDrawImage(bitmap, Quartz.CGRectMake(0,0,width, > height), imageRef) > > del bitmap, imageRef, rgbColorSpace > ======= > quartz.CGContextDrawImage(bitmap, NSMakeRect(0,0,width,height), > imageRef) > > quartz.CGImageRelease(imageRef) > quartz.CGContextRelease(bitmap) > quartz.CGColorSpaceRelease(rgbColorSpace) >>>>>>>> other > > pitch = bytesPerRow > return ImageData(width, height, format, buffer, -pitch) > > -- > You received this message because you are subscribed to the Google Groups > "pyglet-users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/pyglet-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "pyglet-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/pyglet-users?hl=en.
