def test_add_for_class(self): self.assertNotIn("MyObject", convenience.CLASS_METHODS) methods = [('info', lambda self: self.description())] try: objc.addConvenienceForClass("MyObject", methods) self.assertEqual(convenience.CLASS_METHODS["MyObject"], methods) finally: if 'MyObject' in convenience.CLASS_METHODS: del convenience.CLASS_METHODS["MyObject"]
def test_add_for_class(self): self.assertNotIn("MyObject", convenience.CLASS_METHODS) methods = [ ('info', lambda self: self.description()) ] try: objc.addConvenienceForClass("MyObject", methods) self.assertEqual(convenience.CLASS_METHODS["MyObject"], tuple(methods)) finally: if 'MyObject' in convenience.CLASS_METHODS: del convenience.CLASS_METHODS["MyObject"]
def _setup_conveniences(): def fontdescriptor_get(self, key, default=None): value = self.objectForKey_(key) if value is None: return default return value def fontdescriptor_getitem(self, key, default=None): value = self.objectForKey_(key) if value is None: raise KeyError(key) return value objc.addConvenienceForClass('NSFontDescriptor', ( ('__getitem__', fontdescriptor_getitem), ('get', fontdescriptor_get), ))
def _CW8021XProfile__eq__(self, other): if not isinstance(other, type(self)): return False return self.isEqualToProfile_(other) def _CW8021XProfile__ne__(self, other): if not isinstance(other, type(self)): return True return not self.isEqualToProfile_(other) objc.addConvenienceForClass('CW8021XProfile', ( ('__eq__', _CW8021XProfile__eq__), ('__ne__', _CW8021XProfile__ne__), )) def _CWChannel__eq__(self, other): if not isinstance(other, type(self)): return False return self.isEqualToChannel_(other) def _CWChannel__ne__(self, other): if not isinstance(other, type(self)): return True return not self.isEqualToChannel_(other)
def CIVector__getitem__(self, idx): if isinstance(idx, slice): start, stop, step = idx.indices(self.count()) return [self[i] for i in range(start, stop, step)] if idx < 0: new = self.count() + idx if new < 0: raise IndexError(idx) idx = new return self.valueAtIndex_(idx) objc.addConvenienceForClass('CIVector', ( ('__len__', lambda self: self.count()), ('__getitem__', CIVector__getitem__), )) objc.addConvenienceForClass('CIContext', ( ('__getitem__', lambda self, key: self.objectForKey_(key)), ('__setitem__', lambda self, key, value: self.setObject_forKey_(value, key)), )) objc.addConvenienceForClass('CIContextImpl', ( ('__getitem__', lambda self, key: self.objectForKey_(key)), ('__setitem__', lambda self, key, value: self.setObject_forKey_(value, key)), )) objc.addConvenienceForBasicSequence('QCStructure', True)
def NSMOsetValue_ForKey_(self, name, value): try: first = _first_python(self.__class__) if first is not None: super(first, self).setValue_forKey_(value, name) else: self.setValue_forKey_(value, name) except KeyError as msg: NSObject.__setattr__(self, name, value) def NSMOgetValueForKey_(self, name): try: first = _first_python(self.__class__) if first is not None: return super(first, self).valueForKey_(name) else: return self.valueForKey_(name) except KeyError as msg: raise AttributeError(name) if os.uname()[2] < '13.' or True: addConvenienceForClass('NSManagedObject', ( ('__setattr__', NSMOsetValue_ForKey_), ('__getattr__', NSMOgetValueForKey_), ))
""" Python mapping for the Foundation framework. This module does not contain docstrings for the wrapped code, check Apple's documentation for details on how to use these functions and classes. """ import sys import objc import CoreFoundation from Foundation import _metadata from Foundation._inlines import _inline_list_ objc.addConvenienceForClass("NSAttributedString", (("__len__", lambda self: self.length()),)) # XXX objc.addConvenienceForBasicMapping("NSMergeConflict", True) objc.addConvenienceForBasicMapping("NSUbiquitousKeyValueStore", False) objc.addConvenienceForBasicMapping("NSUserDefaults", False) def _setup_conveniences(): NSNull = objc.lookUpClass("NSNull") def nscache_getitem(self, key): value = self.objectForKey_(key) if value is None: raise KeyError(key) elif value is NSNull.null(): return None
import objc def __len__(self): return self.length() def __getitem__(self, idx): if isinstance(idx, slice): raise ValueError(idx) return self.indexAtPosition_(idx) def __add__(self, value): return self.indexPathByAddingIndex_(value) objc.addConvenienceForClass( "NSIndexPath", (("__len__", __len__), ("__getitem__", __getitem__), ("__add__", __add__)), )
def _setup_conveniences(): NSNull = objc.lookUpClass("NSNull") def nscache_getitem(self, key): value = self.objectForKey_(key) if value is None: raise KeyError(key) elif value is NSNull.null(): return None else: return value def nscache_get(self, key, default=None): value = self.objectForKey_(key) if value is None: return default elif value is NSNull.null(): return None return value def nscache_setitem(self, key, value): if value is None: value = NSNull.null() self.setObject_forKey_(value, key) objc.addConvenienceForClass( "NSCache", ( ("__getitem__", nscache_getitem), ("get", nscache_get), ("__setitem__", nscache_setitem), ("__delitem__", lambda self, key: self.removeObjectForKey_(key)), ("clear", lambda self: self.removeAllObjects()), ), ) def hash_add(self, value): if value is None: value = NSNull.null() self.addObject_(value) def hash_contains(self, value): if value is None: value = NSNull.null() return self.containsObject_(value) def hash_remove(self, value): if value is None: value = NSNull.null() self.removeObject_(value) def hash_pop(self): value = self.anyObject() self.removeObject_(value) if value is NSNull.null(): return None else: return value objc.addConvenienceForClass( "NSHashTable", ( ("__len__", lambda self: self.count()), ("clear", lambda self: self.removeAllObjects()), ("__iter__", lambda self: iter(self.objectEnumerator())), ("add", hash_add), ("remove", hash_remove), ("__contains__", hash_contains), ("pop", hash_pop), ), ) objc.addConvenienceForClass("NSIndexPath", (("__len__", lambda self: self.count()), )) if sys.maxsize > 2**32: NSNotFound = 0x7FFFFFFFFFFFFFFF else: NSNotFound = 0x7FFFFFFF def indexset_iter(self): value = self.firstIndex() while value != NSNotFound: yield value value = self.indexGreaterThanIndex_(value) def indexset_reversed(self): value = self.lastIndex() while value != NSNotFound: yield value value = self.indexLessThanIndex_(value) NSIndexSet = objc.lookUpClass("NSIndexSet") def indexset_eq(self, other): if not isinstance(other, NSIndexSet): return False return self.isEqualToIndexSet_(other) def indexset_ne(self, other): if not isinstance(other, NSIndexSet): return True return not self.isEqualToIndexSet_(other) def indexset_contains(self, value): try: return self.containsIndex_(value) except ValueError: return False objc.addConvenienceForClass( "NSIndexSet", ( ("__len__", lambda self: self.count()), ("__iter__", indexset_iter), ("__reversed__", indexset_reversed), ("__eq__", indexset_eq), ("__ne__", indexset_ne), ("__contains__", indexset_contains), ), ) # Add 'update', '-=', '+=' objc.addConvenienceForClass( "NSMutableIndexSet", ( ("clear", lambda self: self.removeAllIndexes()), ("add", lambda self, value: self.addIndex_(value)), ("remove", lambda self, value: self.removeIndex_(value)), ), ) objc.addConvenienceForClass( "NSLocale", (("__getitem__", lambda self, key: self.objectForKey_(key)), ))
def _setup_conveniences(): NSNull = objc.lookUpClass('NSNull') def nscache_getitem(self, key): value = self.objectForKey_(key) if value is None: raise KeyError(key) elif value is NSNull.null(): return None def nscache_get(self, key, default=None): value = self.objectForKey_(key) if value is None: return default elif value is NSNull.null(): return None return value def nscache_setitem(self, key, value): if value is None: value = NSNull.null() self.setObject_forKey_(value, key) objc.addConvenienceForClass('NSCache', ( ('__getitem__', nscache_getitem), ('get', nscache_get), ('__setitem__', nscache_setitem), ('__delitem__', lambda self, key: self.removeObject_(key)), ('clear', lambda self, key: self.removeAllObjects()), )) def hash_add(self, value): if value is None: value = NSNull.null() self.addObject_(value) def hash_contains(self): if value is None: value = NSNull.null() return self.containsObject_(value) def hash_add(self, value): if value is None: value = NSNull.null() self.removeObject_(value) def hash_pop(self): value = self.anyObject() self.removeObject_(value) return value # XXX: add more of the set interface objc.addConvenienceForClass('NSHashTable', ( ('__len__', lambda self: self.count()), ('clear', lambda self, key: self.removeAllObjects()), ('__iter__', lambda self: iter(self.objectEnumerator())), ('add', lambda self, value: hash_add), ('remove', lambda self, value: hash_remove), ('__contains__', lambda self, value: hash_contains), ('pop', hash_pop), )) def charset_contains(self, value): try: return self.characterIsMember_(value) except ValueErorr: # Wrong type return False objc.addConvenienceForClass('NSCharacterSet', ( ('__len__', lambda self: self.count()), ('__contains__', charset_contains), )) # XXX: add full set interface (even if other value can only be a set) #objc.addConvenienceForClass('NSMutableCharacterSet', ( # XXX: add __new__, __getitem__ and __iter__ as well objc.addConvenienceForClass('NSIndexPath', (('__len__', lambda self: self.count()), )) if sys.maxsize > 2**32: NSNotFound = 0x7fffffffffffffff else: NSNotFound = 0x7fffffff def indexset_iter(self): value = self.firstIndex() while value != NSNotFound: yield value value = self.indexGreaterThanIndex_(value) def indexset_reversed(self): value = self.lastIndex() while value != NSNotFound: yield value value = self.indexLessThanIndex_(value) NSIndexSet = objc.lookUpClass('NSIndexSet') def indexset_eq(self, other): if not isinstance(other, NSIndexSet): return False return self.isEqualToIndexSet_(other) def indexset_ne(self, other): if not isinstance(other, NSIndexSet): return True return not self.isEqualToIndexSet_(other) def indexset_contains(self, value): try: return self.containsIndex_(value) except ValueError: return False # XXX: Add __new__ objc.addConvenienceForClass('NSIndexSet', ( ('__len__', lambda self: self.count()), ('__iter__', indexset_iter), ('__reversed__', indexset_reversed), ('__eq__', indexset_eq), ('__ne__', indexset_ne), ('__contains__', indexset_contains), )) # Add 'update', '-=', '+=' objc.addConvenienceForClass('NSMutableIndexSet', ( ('clear', lambda self: self.removeAllIndexes()), ('add', lambda self, value: self.addIndex_(value)), ('remove', lambda self, value: self.removeIndex_(value)), )) objc.addConvenienceForClass( 'NSLocale', (('__getitem__', lambda self, key: self.objectForKey_(key)), ))
def _CW8021XProfile__eq__(self, other): if not isinstance(other, type(self)): return False return self.isEqualToProfile_(other) def _CW8021XProfile__ne__(self, other): if not isinstance(other, type(self)): return True return not self.isEqualToProfile_(other) objc.addConvenienceForClass( "CW8021XProfile", (("__eq__", _CW8021XProfile__eq__), ("__ne__", _CW8021XProfile__ne__)), ) def _CWChannel__eq__(self, other): if not isinstance(other, type(self)): return False return self.isEqualToChannel_(other) def _CWChannel__ne__(self, other): if not isinstance(other, type(self)): return True return not self.isEqualToChannel_(other)
import objc def __len__(self): return self.length() def __getitem__(self, idx): if isinstance(idx, slice): raise ValueError(idx) return self.indexAtPosition_(idx) def __add__(self, value): return self.indexPathByAddingIndex_(value) objc.addConvenienceForClass("NSIndexPath", [ ('__len__', __len__), ('__getitem__', __getitem__), ('__add__', __add__), ])
implementation in this file). """ __all__ = () from objc import addConvenienceForClass from Foundation import NSObject def NSMOsetValue_ForKey_(self, name, value): try: if '__objc_python_subclass__' in self.__class__.__dict__: super(self.__class__, self).setValue_forKey_(value, name) else: self.setValue_forKey_(value, name) except KeyError, msg: NSObject.__setattr__(self, name, value) def NSMOgetValueForKey_(self, name): try: if '__objc_python_subclass__' in self.__class__.__dict__: return super(self.__class__, self).valueForKey_(name) else: return self.valueForKey_(name) except KeyError, msg: raise AttributeError(name) addConvenienceForClass('NSManagedObject', ( ('__setattr__', NSMOsetValue_ForKey_), ('__getattr__', NSMOgetValueForKey_), ))
from CoreWLAN import _metadata, _CoreWLAN def _CW8021XProfile__eq__(self, other): if not isinstance(other, type(self)): return False return self.isEqualToProfile_(other) def _CW8021XProfile__ne__(self, other): if not isinstance(other, type(self)): return True return not self.isEqualToProfile_(other) objc.addConvenienceForClass('CW8021XProfile', ( ('__eq__', _CW8021XProfile__eq__), ('__ne__', _CW8021XProfile__ne__), )) def _CWChannel__eq__(self, other): if not isinstance(other, type(self)): return False return self.isEqualToChannel_(other) def _CWChannel__ne__(self, other): if not isinstance(other, type(self)): return True return not self.isEqualToChannel_(other)
# XXX: addConvenienceFor... should be metadata def CIVector__getitem__(self, idx): if isinstance(idx, slice): start, stop, step = idx.indices(self.count()) return [self[i] for i in range(start, stop, step)] if idx < 0: new = self.count() + idx if new < 0: raise IndexError(idx) idx = new return self.valueAtIndex_(idx) objc.addConvenienceForClass('CIVector', ( ('__len__', lambda self: self.count()), ('__getitem__', CIVector__getitem__), )) objc.addConvenienceForClass('CIContext', ( ('__getitem__', lambda self, key: self.objectForKey_(key)), ('__setitem__', lambda self, key, value: self.setObject_forKey_(value, key)), )) objc.addConvenienceForClass('CIContextImpl', ( ('__getitem__', lambda self, key: self.objectForKey_(key)), ('__setitem__', lambda self, key, value: self.setObject_forKey_(value, key)), )) objc.addConvenienceForBasicSequence('QCStructure', True)
def CIVector__getitem__(self, idx): if isinstance(idx, slice): start, stop, step = idx.indices(self.count()) return [self[i] for i in range(start, stop, step)] if idx < 0: new = self.count() + idx if new < 0: raise IndexError(idx) idx = new return self.valueAtIndex_(idx) objc.addConvenienceForClass( "CIVector", (("__len__", lambda self: self.count()), ("__getitem__", CIVector__getitem__)), ) objc.addConvenienceForClass( "CIContext", ( ("__getitem__", lambda self, key: self.objectForKey_(key)), ("__setitem__", lambda self, key, value: self.setObject_forKey_(value, key)), ), ) objc.addConvenienceForClass( "CIContextImpl", ( ("__getitem__", lambda self, key: self.objectForKey_(key)), ("__setitem__", lambda self, key, value: self.setObject_forKey_(value, key)),
''' Python mapping for the ScriptingBridge framework. This module does not contain docstrings for the wrapped code, check Apple's documentation for details on how to use these functions and classes. ''' import sys import objc import Foundation from ScriptingBridge import _metadata from ScriptingBridge._ScriptingBridge import * sys.modules['ScriptingBridge'] = mod = objc.ObjCLazyModule('ScriptingBridge', "com.apple.ScriptingBridge", objc.pathForFramework("/System/Library/Frameworks/ScriptingBridge.framework"), _metadata.__dict__, None, { '__doc__': __doc__, '__path__': __path__, 'objc': objc, }, ( Foundation,)) # Override the default behaviour of the bridge to ensure that we # make the minimal amount of AppleScript calls. import objc objc.addConvenienceForClass('SBElementArray', [ ('__iter__', lambda self: iter(self.objectEnumerator())), ])
""" Python mapping for the Foundation framework. This module does not contain docstrings for the wrapped code, check Apple's documentation for details on how to use these functions and classes. """ import sys import CoreFoundation import Foundation._Foundation import objc from Foundation import _metadata from Foundation._inlines import _inline_list_ objc.addConvenienceForClass("NSAttributedString", (("__len__", lambda self: self.length()), )) objc.addConvenienceForBasicMapping("NSMergeConflict", True) objc.addConvenienceForBasicMapping("NSUbiquitousKeyValueStore", False) objc.addConvenienceForBasicMapping("NSUserDefaults", False) def _setup_conveniences(): NSNull = objc.lookUpClass("NSNull") def nscache_getitem(self, key): value = self.objectForKey_(key) if value is None: raise KeyError(key) elif value is NSNull.null():
''' Python mapping for the Foundation framework. This module does not contain docstrings for the wrapped code, check Apple's documentation for details on how to use these functions and classes. ''' import sys import objc import CoreFoundation from Foundation import _metadata from Foundation._inlines import _inline_list_ objc.addConvenienceForClass('NSAttributedString', (('__len__', lambda self: self.length()), )) # XXX objc.addConvenienceForBasicMapping('NSMergeConflict', True) objc.addConvenienceForBasicMapping('NSUbiquitousKeyValueStore', False) objc.addConvenienceForBasicMapping('NSUserDefaults', False) def _setup_conveniences(): NSNull = objc.lookUpClass('NSNull') def nscache_getitem(self, key): value = self.objectForKey_(key) if value is None: raise KeyError(key) elif value is NSNull.null():
def _setup_conveniences(): NSNull = objc.lookUpClass("NSNull") def nscache_getitem(self, key): value = self.objectForKey_(key) if value is None: raise KeyError(key) elif value is NSNull.null(): return None def nscache_get(self, key, default=None): value = self.objectForKey_(key) if value is None: return default elif value is NSNull.null(): return None return value def nscache_setitem(self, key, value): if value is None: value = NSNull.null() self.setObject_forKey_(value, key) objc.addConvenienceForClass( "NSCache", ( ("__getitem__", nscache_getitem), ("get", nscache_get), ("__setitem__", nscache_setitem), ("__delitem__", lambda self, key: self.removeObject_(key)), ("clear", lambda self, key: self.removeAllObjects()), ), ) def hash_add(self, value): if value is None: value = NSNull.null() self.addObject_(value) def hash_contains(self): if value is None: value = NSNull.null() return self.containsObject_(value) def hash_add(self, value): if value is None: value = NSNull.null() self.removeObject_(value) def hash_pop(self): value = self.anyObject() self.removeObject_(value) return value # XXX: add more of the set interface objc.addConvenienceForClass( "NSHashTable", ( ("__len__", lambda self: self.count()), ("clear", lambda self, key: self.removeAllObjects()), ("__iter__", lambda self: iter(self.objectEnumerator())), ("add", lambda self, value: hash_add), ("remove", lambda self, value: hash_remove), ("__contains__", lambda self, value: hash_contains), ("pop", hash_pop), ), ) def charset_contains(self, value): try: return self.characterIsMember_(value) except ValueErorr: # Wrong type return False objc.addConvenienceForClass( "NSCharacterSet", (("__len__", lambda self: self.count()), ("__contains__", charset_contains)) ) # XXX: add full set interface (even if other value can only be a set) # objc.addConvenienceForClass('NSMutableCharacterSet', ( # XXX: add __new__, __getitem__ and __iter__ as well objc.addConvenienceForClass("NSIndexPath", (("__len__", lambda self: self.count()),)) if sys.maxsize > 2 ** 32: NSNotFound = 0x7FFFFFFFFFFFFFFF else: NSNotFound = 0x7FFFFFFF def indexset_iter(self): value = self.firstIndex() while value != NSNotFound: yield value value = self.indexGreaterThanIndex_(value) def indexset_reversed(self): value = self.lastIndex() while value != NSNotFound: yield value value = self.indexLessThanIndex_(value) NSIndexSet = objc.lookUpClass("NSIndexSet") def indexset_eq(self, other): if not isinstance(other, NSIndexSet): return False return self.isEqualToIndexSet_(other) def indexset_ne(self, other): if not isinstance(other, NSIndexSet): return True return not self.isEqualToIndexSet_(other) def indexset_contains(self, value): try: return self.containsIndex_(value) except ValueError: return False # XXX: Add __new__ objc.addConvenienceForClass( "NSIndexSet", ( ("__len__", lambda self: self.count()), ("__iter__", indexset_iter), ("__reversed__", indexset_reversed), ("__eq__", indexset_eq), ("__ne__", indexset_ne), ("__contains__", indexset_contains), ), ) # Add 'update', '-=', '+=' objc.addConvenienceForClass( "NSMutableIndexSet", ( ("clear", lambda self: self.removeAllIndexes()), ("add", lambda self, value: self.addIndex_(value)), ("remove", lambda self, value: self.removeIndex_(value)), ), ) objc.addConvenienceForClass("NSLocale", (("__getitem__", lambda self, key: self.objectForKey_(key)),))
def NSMOsetValue_ForKey_(self, name, value): try: first = _first_python(self.__class__) if first is not None: super(first, self).setValue_forKey_(value, name) else: self.setValue_forKey_(value, name) except KeyError: NSObject.__setattr__(self, name, value) def NSMOgetValueForKey_(self, name): try: first = _first_python(self.__class__) if first is not None: return super(first, self).valueForKey_(name) else: return self.valueForKey_(name) except KeyError: raise AttributeError(name) if os.uname()[2] < "13." or True: addConvenienceForClass( "NSManagedObject", (("__setattr__", NSMOsetValue_ForKey_), ("__getattr__", NSMOgetValueForKey_)), )
from ScriptingBridge import _metadata from ScriptingBridge._ScriptingBridge import * sys.modules["ScriptingBridge"] = mod = objc.ObjCLazyModule( "ScriptingBridge", "com.apple.ScriptingBridge", objc.pathForFramework("/System/Library/Frameworks/ScriptingBridge.framework"), _metadata.__dict__, None, { "__doc__": __doc__, "__path__": __path__, "__loader__": globals().get("__loader__", None), "objc": objc, }, (Foundation,), ) import sys del sys.modules["ScriptingBridge._metadata"] # Override the default behaviour of the bridge to ensure that we # make the minimal amount of AppleScript calls. import objc objc.addConvenienceForClass( "SBElementArray", [("__iter__", lambda self: iter(self.objectEnumerator()))] )