Python objc.lookUpClass() Examples
The following are 8
code examples of objc.lookUpClass().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
objc
, or try the search function
.
Example #1
Source File: _static.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 6 votes |
def _setup(): NSDictionary = _objc.lookUpClass("NSDictionary") NSMutableDictionary = _objc.lookUpClass("NSMutableDictionary") def CFDictionaryCreate( allocator, keys, values, numValues, keyCallbacks, valueCallbacks ): assert keyCallbacks is None assert valueCallbacks is None keys = list(keys)[:numValues] values = list(values)[:numValues] return NSDictionary.dictionaryWithDictionary_(dict(zip(keys, values))) def CFDictionaryCreateMutable(allocator, capacity, keyCallbacks, valueCallbacks): assert keyCallbacks is None assert valueCallbacks is None return NSMutableDictionary.dictionary() return CFDictionaryCreate, CFDictionaryCreateMutable
Example #2
Source File: misc.py From fontgoggles with Apache License 2.0 | 5 votes |
def ClassNameIncrementer(clsName, bases, dct): orgName = clsName counter = 0 while True: try: objc.lookUpClass(clsName) except objc.nosuchclass_error: break counter += 1 clsName = orgName + str(counter) return type(clsName, bases, dct)
Example #3
Source File: HT_LetterSpacer_script.py From HTLetterspacer with GNU General Public License v3.0 | 5 votes |
def setG(self, layer): if layer.isKindOfClass_(objc.lookUpClass("GSControlLayer")): return self.output = '\\' + layer.parent.name + '\\\n' + self.output self.layerID = layer.associatedMasterId self.master = self.font.masters[self.layerID] self.glyph = layer.parent self.layer = layer self.category = layer.parent.category self.subCategory = layer.parent.subCategory self.script = layer.parent.script self.engine.reference = self.glyph.name exception = self.findException() if (exception): self.engine.factor = exception[3] item = exception[4] if item != '*': self.engine.reference = item self.engine.newWidth = False # check reference layer existance and contours if self.font.glyphs[self.engine.reference]: self.referenceLayer = self.font.glyphs[self.engine.reference].layers[self.layerID] if len(self.referenceLayer.paths) < 1: self.output += "WARNING: The reference glyph declared (" + self.engine.reference + ") doesn't have contours. Glyph " + self.layer.parent.name + " was spaced uses its own vertical range.\n" self.referenceLayer = self.layer else: self.referenceLayer = self.layer self.output += "WARNING: The reference glyph declared (" + self.engine.reference + ") doesn't exist. Glyph " + self.layer.parent.name + " was spaced uses its own vertical range.\n"
Example #4
Source File: _static.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 5 votes |
def _setup(): NSArray = _objc.lookUpClass("NSArray") NSMutableArray = _objc.lookUpClass("NSMutableArray") def CFArrayCreate(allocator, values, numvalues, callbacks): assert callbacks is None return NSArray.alloc().initWithArray_(values[:numvalues]) def CFArrayCreateMutable(allocator, capacity, callbacks): assert callbacks is None return NSMutableArray.alloc().init() return CFArrayCreate, CFArrayCreateMutable
Example #5
Source File: _static.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 5 votes |
def _setup(): NSSet = _objc.lookUpClass("NSSet") NSMutableSet = _objc.lookUpClass("NSMutableSet") def CFSetCreate(allocator, values, numvalues, callbacks): assert callbacks is None return NSSet.alloc().initWithArray_(values[:numvalues]) def CFSetCreateMutable(allocator, capacity, callbacks): assert callbacks is None return NSMutableSet.alloc().init() return CFSetCreate, CFSetCreateMutable
Example #6
Source File: _static.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 5 votes |
def CFSTR(strval): return _objc.lookUpClass("NSString").stringWithString_(strval)
Example #7
Source File: _lazyimport.py From MIA-Dictionary-Addon with GNU General Public License v3.0 | 4 votes |
def __getattr__(self, name): if name == "__all__": # Load everything immediately value = self.__calc_all() self.__dict__[name] = value return value # First try parent module, as if we had done # 'from parents import *' for p in self.__parents: try: value = getattr(p, name) except AttributeError: pass else: self.__dict__[name] = value if "__all__" in self.__dict__: del self.__dict__["__all__"] return value if not _name_re.match(name): # Name is not a valid identifier and cannot # match. raise AttributeError(name) # Check if the name is a constant from # the metadata files try: value = self.__get_constant(name) except AttributeError: pass else: self.__dict__[name] = value if "__all__" in self.__dict__: del self.__dict__["__all__"] return value # Then check if the name is class try: value = lookUpClass(name) except nosuchclass_error: pass else: self.__dict__[name] = value if "__all__" in self.__dict__: del self.__dict__["__all__"] return value # Finally give up and raise AttributeError raise AttributeError(name)
Example #8
Source File: notification.py From douban.fm with MIT License | 4 votes |
def send_OS_X_notify(title, content, img_path): '''发送Mac桌面通知''' try: from Foundation import ( NSDate, NSUserNotification, NSUserNotificationCenter) from AppKit import NSImage import objc except ImportError: logger.info('failed to init OSX notify!') return def swizzle(cls, SEL, func): old_IMP = getattr(cls, SEL, None) if old_IMP is None: old_IMP = cls.instanceMethodForSelector_(SEL) def wrapper(self, *args, **kwargs): return func(self, old_IMP, *args, **kwargs) new_IMP = objc.selector(wrapper, selector=old_IMP.selector, signature=old_IMP.signature) objc.classAddMethod(cls, SEL.encode(), new_IMP) def swizzled_bundleIdentifier(self, original): # Use iTunes icon for notification return 'com.apple.itunes' swizzle(objc.lookUpClass('NSBundle'), 'bundleIdentifier', swizzled_bundleIdentifier) notification = NSUserNotification.alloc().init() notification.setTitle_(title) notification.setSubtitle_(content) notification.setInformativeText_('') notification.setUserInfo_({}) if img_path is not None: image = NSImage.alloc().initWithContentsOfFile_(img_path) # notification.setContentImage_(image) notification.set_identityImage_(image) notification.setDeliveryDate_( NSDate.dateWithTimeInterval_sinceDate_(0, NSDate.date()) ) NSUserNotificationCenter.defaultUserNotificationCenter().\ scheduleNotification_(notification) logger.info('send notify success!')