def _valueToNSObject(value, nstype): '''Convert a string with a type specifier to a native Objective-C NSObject (serializable).''' return { 'string': lambda v: NSString.stringWithUTF8String_(v), 'int': lambda v: NSNumber.numberWithInt_(v), 'float': lambda v: NSNumber.numberWithFloat_(v), 'bool': lambda v: True if v == 'true' else False, 'data': lambda v: NSData.initWithBytes_length_(v, len(v)) }[nstype](value)
def _value_to_nsobject(value, nstype): '''Convert a string with a type specifier to a native Objective-C NSObject (serializable).''' return { 'string': lambda v: NSString.stringWithUTF8String_(v), 'int': lambda v: NSNumber.numberWithInt_(v), 'float': lambda v: NSNumber.numberWithFloat_(v), 'bool': lambda v: True if v == 'true' else False, 'data': lambda v: NSMutableData.dataWithLength_(len(value)).initWithBase64EncodedString_options_(value) }[nstype](value)
def _valueToNSObject(value, nstype): '''Convert a string with a type specifier to a native Objective-C NSObject (serializable).''' return { 'string': lambda v: NSString.stringWithUTF8String_(v), 'int': lambda v: NSNumber.numberWithInt_(v), 'float': lambda v: NSNumber.numberWithFloat_(v), 'bool': lambda v: True if v == 'true' else False, 'data': lambda v: NSData.initWithBytes_length_(v, len(v)) }[nstype](value)
def _value_to_nsobject(value, nstype): '''Convert a string with a type specifier to a native Objective-C NSObject (serializable).''' return { 'string': lambda v: NSString.stringWithUTF8String_(v), 'int': lambda v: NSNumber.numberWithInt_(v), 'float': lambda v: NSNumber.numberWithFloat_(v), 'bool': lambda v: True if v == 'true' else False, 'data': lambda v: NSMutableData.dataWithLength_(len(value)).initWithBase64EncodedString_options_(value) }[nstype](value)
def __setattr__(self, attr, value): # check to see if the attribute has been # deprecated. if so, warn the caller and # update the attribute and value. if attr in self._deprecatedAttributes: newAttr, newValue = ufoLib.convertFontInfoValueForAttributeFromVersion1ToVersion2( attr, value) note = "The %s attribute has been deprecated. Use the new %s attribute." % ( attr, newAttr) warn(note, DeprecationWarning) attr = newAttr value = newValue _baseAttributes = ["_object", "changed", "selected", "getParent"] _renameAttributes = { "openTypeNameManufacturer": "manufacturer", "openTypeNameManufacturerURL": "manufacturerURL", "openTypeNameDesigner": "designer", "openTypeNameDesignerURL": "designerURL", # "openTypeNameLicense": "license", # "openTypeNameLicenseURL": "licenseURL", "fontName": "postscriptFontName", "vendorURL": "manufacturerURL", "uniqueID": "postscriptUniqueID", "otMacName": "openTypeNameCompatibleFullName" } _masterAttributes = [ "postscriptUnderlinePosition", "postscriptUnderlineThickness", "openTypeOS2StrikeoutSize", "openTypeOS2StrikeoutPosition" ] # setting a known attribute if attr in _masterAttributes: if type(value) == type([]): value = NSMutableArray.arrayWithArray_(value) elif type(value) == type(1): value = NSNumber.numberWithInt_(value) elif type(value) == type(1.2): value = NSNumber.numberWithFloat_(value) if attr in _renameAttributes: attr = _renameAttributes[attr] self._object._font.fontMasterAtIndex_( self._object._masterIndex).setValue_forKey_(value, attr) return if attr not in _baseAttributes: try: if type(value) == type([]): value = NSMutableArray.arrayWithArray_(value) elif type(value) == type(1): value = NSNumber.numberWithInt_(value) elif type(value) == type(1.2): value = NSNumber.numberWithFloat_(value) if attr in _renameAttributes: attr = _renameAttributes[attr] self._object._font.setValue_forKey_(value, attr) except: raise AttributeError("Unknown attribute %s." % attr) return elif attr in self.__dict__ or attr in self._baseAttributes: super(BaseInfo, self).__setattr__(attr, value) else: raise AttributeError("Unknown attribute %s." % attr)
def __setattr__(self, attr, value): # check to see if the attribute has been # deprecated. if so, warn the caller and # update the attribute and value. if attr in self._deprecatedAttributes: newAttr, newValue = ufoLib.convertFontInfoValueForAttributeFromVersion1ToVersion2(attr, value) note = "The %s attribute has been deprecated. Use the new %s attribute." % (attr, newAttr) warn(note, DeprecationWarning) attr = newAttr value = newValue _baseAttributes = ["_object", "changed", "selected", "getParent"] _renameAttributes = {"openTypeNameManufacturer": "manufacturer", "openTypeNameManufacturerURL": "manufacturerURL", "openTypeNameDesigner": "designer", "openTypeNameDesignerURL": "designerURL", # "openTypeNameLicense": "license", # "openTypeNameLicenseURL": "licenseURL", "fontName": "postscriptFontName", "vendorURL": "manufacturerURL", "uniqueID": "postscriptUniqueID", "otMacName": "openTypeNameCompatibleFullName" }; _masterAttributes = ["postscriptUnderlinePosition", "postscriptUnderlineThickness", "openTypeOS2StrikeoutSize", "openTypeOS2StrikeoutPosition"] # setting a known attribute if attr in _masterAttributes: if type(value) == type([]): value = NSMutableArray.arrayWithArray_(value) elif type(value) == type(1): value = NSNumber.numberWithInt_(value) elif type(value) == type(1.2): value = NSNumber.numberWithFloat_(value) if attr in _renameAttributes: attr = _renameAttributes[attr] self._object._font.fontMasterAtIndex_(self._object._masterIndex).setValue_forKey_(value, attr) return if attr not in _baseAttributes: try: if type(value) == type([]): value = NSMutableArray.arrayWithArray_(value) elif type(value) == type(1): value = NSNumber.numberWithInt_(value) elif type(value) == type(1.2): value = NSNumber.numberWithFloat_(value) if attr in _renameAttributes: attr = _renameAttributes[attr] self._object._font.setValue_forKey_(value, attr) except: raise AttributeError("Unknown attribute %s." % attr) return elif attr in self.__dict__ or attr in self._baseAttributes: super(BaseInfo, self).__setattr__(attr, value) else: raise AttributeError("Unknown attribute %s." % attr)