[Pyobjc-dev] Casting to CGWindowID
Brought to you by:
ronaldoussoren
|
From: Matt W. <ma...@in...> - 2008-01-05 11:15:30
|
Hi there, I'm using the default PyObjC on Leopard. I've used PyObjC before--very happy with it, thanks! To learn more, I've been attempting to port SonOfGrab to Python. It uses some new- to-10.5 window server methods that I want to get familiar with: http://developer.apple.com/samplecode/SonOfGrab/index.html What I'm being stumped by is making an array that consists of CGWindowID types (CGWindowID is a uint32_t), rather than NSNumber. It's probably really simple, I know, but I can't see it in the docs (and my Google-fu is poor today): how do I force a number - in Python - to get cast as uint32_t when it's given to Obj C, instead of an NSNumber? (I've put a little more info below.) thanks, Matt # My Python code is: windowIds = [w[kWindowIDKey].unsignedIntValue() for w in sortedSelection] The equivalent Obj C code is: // Now we Collect the CGWindowIDs from the sorted selection CGWindowID *windowIDs = calloc([sortedSelection count], sizeof(CGWindowID)); int i = 0; for(NSMutableDictionary *entry in sortedSelection) { windowIDs[i++] = [[entry objectForKey:kWindowIDKey] unsignedIntValue]; } // CGWindowListCreateImageFromArray expect a CFArray of *CGWindowID*, not CGWindowID wrapped in a CF/NSNumber // Hence we typecast our array above (to avoid the compiler warning) and use NULL CFArray callbacks // (because CGWindowID isn't a CF type) to avoid retain/release. CFArrayRef windowIDsArray = CFArrayCreate(kCFAllocatorDefault, (const void**)windowIDs, [sortedSelection count], NULL); free(windowIDs); -- from http://developer.apple.com/samplecode/SonOfGrab/listing2.html |