本文整理汇总了Python中Carbon.Res.Resource方法的典型用法代码示例。如果您正苦于以下问题:Python Res.Resource方法的具体用法?Python Res.Resource怎么用?Python Res.Resource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Carbon.Res
的用法示例。
在下文中一共展示了Res.Resource方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: writePlistToResource
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Resource [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: mkalias
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Resource [as 别名]
def mkalias(src, dst, relative=None):
"""Create a finder alias"""
srcfsr = File.FSRef(src)
# The next line will fail under unix-Python if the destination
# doesn't exist yet. We should change this code to be fsref-based.
dstdir, dstname = os.path.split(dst)
if not dstdir: dstdir = os.curdir
dstdirfsr = File.FSRef(dstdir)
if relative:
relativefsr = File.FSRef(relative)
# ik mag er geen None in stoppen :-(
alias = File.FSNewAlias(relativefsr, srcfsr)
else:
alias = srcfsr.FSNewAliasMinimal()
dstfsr, dstfss = Res.FSCreateResourceFile(dstdirfsr, unicode(dstname),
File.FSGetResourceForkName())
h = Res.FSOpenResourceFile(dstfsr, File.FSGetResourceForkName(), 3)
resource = Res.Resource(alias.data)
resource.AddResource('alis', 0, '')
Res.CloseResFile(h)
dstfinfo = dstfss.FSpGetFInfo()
dstfinfo.Flags = dstfinfo.Flags|0x8000 # Alias flag
dstfss.FSpSetFInfo(dstfinfo)
示例3: close
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Resource [as 别名]
def close(self):
if self.closed:
return
Res.UseResFile(self.resref)
try:
res = Res.Get1NamedResource('sfnt', self.fullname)
except Res.Error:
pass
else:
res.RemoveResource()
res = Res.Resource(self.file.getvalue())
if self.res_id is None:
self.res_id = Res.Unique1ID('sfnt')
res.AddResource('sfnt', self.res_id, self.fullname)
res.ChangedResource()
self.createFond()
del self.ttFont
Res.CloseResFile(self.resref)
self.file.close()
self.closed = 1
示例4: writeLWFN
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Resource [as 别名]
def writeLWFN(path, data):
Res.FSpCreateResFile(path, "just", "LWFN", 0)
resRef = Res.FSOpenResFile(path, 2) # write-only
try:
Res.UseResFile(resRef)
resID = 501
chunks = findEncryptedChunks(data)
for isEncrypted, chunk in chunks:
if isEncrypted:
code = 2
else:
code = 1
while chunk:
res = Res.Resource(chr(code) + '\0' + chunk[:LWFNCHUNKSIZE - 2])
res.AddResource('POST', resID, '')
chunk = chunk[LWFNCHUNKSIZE - 2:]
resID = resID + 1
res = Res.Resource(chr(5) + '\0')
res.AddResource('POST', resID, '')
finally:
Res.CloseResFile(resRef)
示例5: writeLWFN
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Resource [as 别名]
def writeLWFN(path, data):
# Res.FSpCreateResFile was deprecated in OS X 10.5
Res.FSpCreateResFile(path, "just", "LWFN", 0)
resRef = Res.FSOpenResFile(path, 2) # write-only
try:
Res.UseResFile(resRef)
resID = 501
chunks = findEncryptedChunks(data)
for isEncrypted, chunk in chunks:
if isEncrypted:
code = 2
else:
code = 1
while chunk:
res = Res.Resource(bytechr(code) + '\0' + chunk[:LWFNCHUNKSIZE - 2])
res.AddResource('POST', resID, '')
chunk = chunk[LWFNCHUNKSIZE - 2:]
resID = resID + 1
res = Res.Resource(bytechr(5) + '\0')
res.AddResource('POST', resID, '')
finally:
Res.CloseResFile(resRef)
示例6: __init__
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Resource [as 别名]
def __init__(self, signature='Pyth', ic=None):
if ic:
self.ic = ic
else:
self.ic = icglue.ICStart(signature)
if hasattr(self.ic, 'ICFindConfigFile'):
self.ic.ICFindConfigFile()
self.h = Res.Resource('')
示例7: mergecfmfiles
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Resource [as 别名]
def mergecfmfiles(srclist, dst, architecture = 'fat'):
"""Merge all files in srclist into a new file dst.
If architecture is given, only code fragments of that type will be used:
"pwpc" for PPC, "m68k" for cfm68k. This does not work for "classic"
68k code, since it does not use code fragments to begin with.
If architecture is None, all fragments will be used, enabling FAT binaries.
"""
srclist = list(srclist)
for i in range(len(srclist)):
srclist[i] = Carbon.File.pathname(srclist[i])
dst = Carbon.File.pathname(dst)
dstfile = open(dst, "wb")
rf = Res.FSpOpenResFile(dst, 3)
try:
dstcfrg = CfrgResource()
for src in srclist:
srccfrg = CfrgResource(src)
for frag in srccfrg.fragments:
if frag.architecture == 'pwpc' and architecture == 'm68k':
continue
if frag.architecture == 'm68k' and architecture == 'pwpc':
continue
dstcfrg.append(frag)
frag.copydata(dstfile)
cfrgres = Res.Resource(dstcfrg.build())
Res.UseResFile(rf)
cfrgres.AddResource('cfrg', 0, "")
finally:
dstfile.close()
rf = Res.CloseResFile(rf)
示例8: createFond
# 需要导入模块: from Carbon import Res [as 别名]
# 或者: from Carbon.Res import Resource [as 别名]
def createFond(self):
fond_res = Res.Resource("")
fond_res.AddResource('FOND', self.res_id, self.fullname)
from fontTools import fondLib
fond = fondLib.FontFamily(fond_res, "w")
fond.ffFirstChar = 0
fond.ffLastChar = 255
fond.fondClass = 0
fond.fontAssoc = [(0, 0, self.res_id)]
fond.ffFlags = 20480 # XXX ???
fond.ffIntl = (0, 0)
fond.ffLeading = 0
fond.ffProperty = (0, 0, 0, 0, 0, 0, 0, 0, 0)
fond.ffVersion = 0
fond.glyphEncoding = {}
if self.familyname == self.psname:
fond.styleIndices = (1,) * 48 # uh-oh, fondLib is too dumb.
else:
fond.styleIndices = (2,) * 48
fond.styleStrings = []
fond.boundingBoxes = None
fond.ffFamID = self.res_id
fond.changed = 1
fond.glyphTableOffset = 0
fond.styleMappingReserved = 0
# calc:
scale = 4096.0 / self.ttFont['head'].unitsPerEm
fond.ffAscent = scale * self.ttFont['hhea'].ascent
fond.ffDescent = scale * self.ttFont['hhea'].descent
fond.ffWidMax = scale * self.ttFont['hhea'].advanceWidthMax
fond.ffFamilyName = self.familyname
fond.psNames = {0: self.psname}
fond.widthTables = {}
fond.kernTables = {}
cmap = self.ttFont['cmap'].getcmap(1, 0)
if cmap:
names = {}
for code, name in cmap.cmap.items():
names[name] = code
if self.ttFont.has_key('kern'):
kern = self.ttFont['kern'].getkern(0)
if kern:
fondkerning = []
for (left, right), value in kern.kernTable.items():
if names.has_key(left) and names.has_key(right):
fondkerning.append((names[left], names[right], scale * value))
fondkerning.sort()
fond.kernTables = {0: fondkerning}
if self.ttFont.has_key('hmtx'):
hmtx = self.ttFont['hmtx']
fondwidths = [2048] * 256 + [0, 0] # default width, + plus two zeros.
for name, (width, lsb) in hmtx.metrics.items():
if names.has_key(name):
fondwidths[names[name]] = scale * width
fond.widthTables = {0: fondwidths}
fond.save()