1''' 2Python mapping for the CoreFoundation framework. 3 4This module does not contain docstrings for the wrapped code, check Apple's 5documentation for details on how to use these functions and classes. 6''' 7 8import objc as _objc 9 10from CoreFoundation._inlines import _inline_list_ 11 12 13__bundle__ = _objc.initFrameworkWrapper("CoreFoundation", 14 frameworkIdentifier="com.apple.CoreFoundation", 15 frameworkPath=_objc.pathForFramework( 16 "/System/Library/Frameworks/CoreFoundation.framework"), 17 globals=globals(), 18 scan_classes=False, 19 inlineTab=_inline_list_) 20 21from CoreFoundation._CoreFoundation import * 22 23# 24# 'Emulation' for CFArray contructors 25# 26def _setup(): 27 NSArray = objc.lookUpClass('NSArray') 28 NSMutableArray = objc.lookUpClass('NSMutableArray') 29 30 def CFArrayCreate(allocator, values, numvalues, callbacks): 31 assert callbacks is None 32 return NSArray.alloc().initWithArray_(values[:numvalues]) 33 34 def CFArrayCreateMutable(allocator, capacity, callbacks): 35 assert callbacks is None 36 return NSMutableArray.alloc().init() 37 38 return CFArrayCreate, CFArrayCreateMutable 39 40 41CFArrayCreate, CFArrayCreateMutable = _setup() 42 43 44# CFDictionary emulation functions 45 46def _setup(): 47 NSDictionary = objc.lookUpClass('NSDictionary') 48 NSMutableDictionary = objc.lookUpClass('NSMutableDictionary') 49 def CFDictionaryCreate(allocator, keys, values, numValues, 50 keyCallbacks, valueCallbacks): 51 assert keyCallbacks is None 52 assert valueCallbacks is None 53 54 keys = list(keys)[:numValues] 55 values = list(values)[:numValues] 56 57 return NSDictionary.dictionaryWithDictionary_(dict(zip(keys, values))) 58 59 def CFDictionaryCreateMutable(allocator, capacity, keyCallbacks, valueCallbacks): 60 assert keyCallbacks is None 61 assert valueCallbacks is None 62 63 return NSMutableDictionary.dictionary() 64 65 return CFDictionaryCreate, CFDictionaryCreateMutable 66 67CFDictionaryCreate, CFDictionaryCreateMutable = _setup() 68 69 70 71# CFSet emulation functions 72 73def _setup(): 74 NSSet = objc.lookUpClass('NSSet') 75 NSMutableSet = objc.lookUpClass('NSMutableSet') 76 77 def CFSetCreate(allocator, values, numvalues, callbacks): 78 assert callbacks is None 79 return NSSet.alloc().initWithArray_(values[:numvalues]) 80 81 def CFSetCreateMutable(allocator, capacity, callbacks): 82 assert callbacks is None 83 return NSMutableSet.alloc().init() 84 85 return CFSetCreate, CFSetCreateMutable 86 87CFSetCreate, CFSetCreateMutable = _setup() 88 89kCFTypeArrayCallBacks = None 90kCFTypeDictionaryKeyCallBacks = None 91kCFTypeDictionaryValueCallBacks = None 92kCFTypeSetCallBacks = None 93 94 95# 96# Implementation of a number of macro's in the CFBundle API 97# 98 99def CFCopyLocalizedString(key, comment): 100 return CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), None) 101 102def CFCopyLocalizedStringFromTable(key, tbl, comment): 103 return CFBundleCopyLocalizedString(CFBundleGetMainBundle(), (key), (key), (tbl)) 104 105def CFCopyLocalizedStringFromTableInBundle(key, tbl, bundle, comment): 106 return CFBundleCopyLocalizedString((bundle), (key), (key), (tbl)) 107 108def CFCopyLocalizedStringWithDefaultValue(key, tbl, bundle, value, comment): 109 return CFBundleCopyLocalizedString((bundle), (key), (value), (tbl)) 110 111 112 113def CFSTR(strval): 114 return objc.lookUpClass('NSString').stringWithString_(strval) 115