本文整理汇总了Python中Carbon.Res.Get1Resource方法的典型用法代码示例。如果您正苦于以下问题:Python Res.Get1Resource方法的具体用法?Python Res.Get1Resource怎么用?Python Res.Get1Resource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon.Res
的用法示例。
在下文中一共展示了Res.Get1Resource方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writePlistToResource
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Get1Resource [as 别名]
def writePlistToResource(rootObject, path, restype='plst', resid=0):
"""Write 'rootObject' as a plst resource to the resource fork of path.
"""
warnings.warnpy3k("In 3.x, writePlistToResource is removed.", stacklevel=2)
from Carbon.File import FSRef, FSGetResourceForkName
from Carbon.Files import fsRdWrPerm
from Carbon import Res
plistData = writePlistToString(rootObject)
fsRef = FSRef(path)
resNum = Res.FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdWrPerm)
Res.UseResFile(resNum)
try:
Res.Get1Resource(restype, resid).RemoveResource()
except Res.Error:
pass
res = Res.Resource(plistData)
res.AddResource(restype, resid, '')
res.WriteResource()
Res.CloseResFile(resNum)
示例2: __init__
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Get1Resource [as 别名]
def __init__(self, path = None):
self.version = 1
self.fragments = []
self.path = path
if path is not None and os.path.exists(path):
currentresref = Res.CurResFile()
resref = Res.FSpOpenResFile(path, 1)
Res.UseResFile(resref)
try:
try:
data = Res.Get1Resource('cfrg', 0).data
except Res.Error:
raise Res.Error, "no 'cfrg' resource found", sys.exc_traceback
finally:
Res.CloseResFile(resref)
Res.UseResFile(currentresref)
self.parse(data)
if self.version != 1:
raise error, "unknown 'cfrg' resource format"
示例3: dataFromFile
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Get1Resource [as 别名]
def dataFromFile(pathOrFSSpec, nameOrID="", resType='NFNT'):
from Carbon import Res
resref = Res.FSOpenResFile(pathOrFSSpec, 1) # readonly
try:
Res.UseResFile(resref)
if not nameOrID:
# just take the first in the file
res = Res.Get1IndResource(resType, 1)
elif type(nameOrID) == types.IntType:
res = Res.Get1Resource(resType, nameOrID)
else:
res = Res.Get1NamedResource(resType, nameOrID)
theID, theType, name = res.GetResInfo()
data = res.data
finally:
Res.CloseResFile(resref)
return data
示例4: readPlistFromResource
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Get1Resource [as 别名]
def readPlistFromResource(path, restype='plst', resid=0):
"""Read plst resource from the resource fork of path.
"""
warnings.warnpy3k("In 3.x, readPlistFromResource is removed.",
stacklevel=2)
from Carbon.File import FSRef, FSGetResourceForkName
from Carbon.Files import fsRdPerm
from Carbon import Res
fsRef = FSRef(path)
resNum = Res.FSOpenResourceFile(fsRef, FSGetResourceForkName(), fsRdPerm)
Res.UseResFile(resNum)
plistData = Res.Get1Resource(restype, resid).data
Res.CloseResFile(resNum)
return readPlistFromString(plistData)
示例5: readLWFN
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Get1Resource [as 别名]
def readLWFN(path, onlyHeader=0):
"""reads an LWFN font file, returns raw data"""
resRef = Res.FSOpenResFile(path, 1) # read-only
try:
Res.UseResFile(resRef)
n = Res.Count1Resources('POST')
data = []
for i in range(501, 501 + n):
res = Res.Get1Resource('POST', i)
code = ord(res.data[0])
if ord(res.data[1]) <> 0:
raise T1Error, 'corrupt LWFN file'
if code in [1, 2]:
if onlyHeader and code == 2:
break
data.append(res.data[2:])
elif code in [3, 5]:
break
elif code == 4:
f = open(path, "rb")
data.append(f.read())
f.close()
elif code == 0:
pass # comment, ignore
else:
raise T1Error, 'bad chunk code: ' + `code`
finally:
Res.CloseResFile(resRef)
data = string.join(data, '')
assertType1(data)
return data