當前位置: 首頁>>代碼示例>>Python>>正文


Python Res.Error方法代碼示例

本文整理匯總了Python中Carbon.Res.Error方法的典型用法代碼示例。如果您正苦於以下問題:Python Res.Error方法的具體用法?Python Res.Error怎麽用?Python Res.Error使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Carbon.Res的用法示例。


在下文中一共展示了Res.Error方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: writePlistToResource

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [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) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:21,代碼來源:plistlib.py

示例2: findtemplate

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [as 別名]
def findtemplate(template=None):
    """Locate the applet template along sys.path"""
    if MacOS.runtimemodel == 'macho':
        return None
    if not template:
        template=TEMPLATE
    for p in sys.path:
        file = os.path.join(p, template)
        try:
            file, d1, d2 = Carbon.File.FSResolveAliasFile(file, 1)
            break
        except (Carbon.File.Error, ValueError):
            continue
    else:
        raise BuildError, "Template %r not found on sys.path" % (template,)
    file = file.as_pathname()
    return file 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:19,代碼來源:buildtools.py

示例3: close

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [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 
開發者ID:gltn,項目名稱:stdm,代碼行數:23,代碼來源:macUtils.py

示例4: open_pathname

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [as 別名]
def open_pathname(pathname, verbose=0):
    """Open a resource file given by pathname, possibly decoding an
    AppleSingle file"""
    # No resource fork. We may be on OSX, and this may be either
    # a data-fork based resource file or a AppleSingle file
    # from the CVS repository.
    try:
        refno = Res.FSOpenResourceFile(pathname, u'', 1)
    except Res.Error, arg:
        if arg[0] != -199:
            # -199 is "bad resource map"
            raise 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:14,代碼來源:macresource.py

示例5: resource_pathname

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [as 別名]
def resource_pathname(pathname, verbose=0):
    """Return the pathname for a resource file (either DF or RF based).
    If the pathname given already refers to such a file simply return it,
    otherwise first decode it."""
    # No resource fork. We may be on OSX, and this may be either
    # a data-fork based resource file or a AppleSingle file
    # from the CVS repository.
    try:
        refno = Res.FSOpenResourceFile(pathname, u'', 1)
    except Res.Error, arg:
        if arg[0] != -199:
            # -199 is "bad resource map"
            raise 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:15,代碼來源:macresource.py

示例6: close

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [as 別名]
def close(self):
		if self.resref <> None:
			try:
				Res.CloseResFile(self.resref)
			except Res.Error:
				pass
			self.resref = None 
開發者ID:gltn,項目名稱:stdm,代碼行數:9,代碼來源:fondLib.py

示例7: MyOpenResFile

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [as 別名]
def MyOpenResFile(path):
	mode = 1  # read only
	try:
		resref = Res.FSOpenResFile(path, mode)
	except Res.Error:
		# try data fork
		resref = Res.FSOpenResourceFile(path, u'', mode)
	return resref 
開發者ID:gltn,項目名稱:stdm,代碼行數:10,代碼來源:macUtils.py

示例8: getSFNTResIndices

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [as 別名]
def getSFNTResIndices(path):
	"""Determine whether a file has a resource fork or not."""
	try:
		resref = MyOpenResFile(path)
	except Res.Error:
		return []
	Res.UseResFile(resref)
	numSFNTs = Res.Count1Resources('sfnt')
	Res.CloseResFile(resref)
	return range(1, numSFNTs + 1) 
開發者ID:gltn,項目名稱:stdm,代碼行數:12,代碼來源:macUtils.py

示例9: copyres

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [as 別名]
def copyres(input, output, skiptypes, skipowner, progress=None):
    ctor = None
    alltypes = []
    Res.UseResFile(input)
    ntypes = Res.Count1Types()
    progress_type_inc = 50/ntypes
    for itype in range(1, 1+ntypes):
        type = Res.Get1IndType(itype)
        if type in skiptypes:
            continue
        alltypes.append(type)
        nresources = Res.Count1Resources(type)
        progress_cur_inc = progress_type_inc/nresources
        for ires in range(1, 1+nresources):
            res = Res.Get1IndResource(type, ires)
            id, type, name = res.GetResInfo()
            lcname = string.lower(name)

            if lcname == OWNERNAME and id == 0:
                if skipowner:
                    continue # Skip this one
                else:
                    ctor = type
            size = res.size
            attrs = res.GetResAttrs()
            if progress:
                progress.label("Copy %s %d %s"%(type, id, name))
                progress.inc(progress_cur_inc)
            res.LoadResource()
            res.DetachResource()
            Res.UseResFile(output)
            try:
                res2 = Res.Get1Resource(type, id)
            except MacOS.Error:
                res2 = None
            if res2:
                if progress:
                    progress.label("Overwrite %s %d %s"%(type, id, name))
                    progress.inc(0)
                res2.RemoveResource()
            res.AddResource(type, id, name)
            res.WriteResource()
            attrs = attrs | res.GetResAttrs()
            res.SetResAttrs(attrs)
            Res.UseResFile(input)
    return alltypes, ctor 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:48,代碼來源:buildtools.py

示例10: need

# 需要導入模塊: from Carbon import Res [as 別名]
# 或者: from Carbon.Res import Error [as 別名]
def need(restype, resid, filename=None, modname=None):
    """Open a resource file, if needed. restype and resid
    are required parameters, and identify the resource for which to test. If it
    is available we are done. If it is not available we look for a file filename
    (default: modname with .rsrc appended) either in the same folder as
    where modname was loaded from, or otherwise across sys.path.

    Returns the refno of the resource file opened (or None)"""

    if modname is None and filename is None:
        raise ArgumentError, "Either filename or modname argument (or both) must be given"

    if type(resid) is type(1):
        try:
            h = Res.GetResource(restype, resid)
        except Res.Error:
            pass
        else:
            return None
    else:
        try:
            h = Res.GetNamedResource(restype, resid)
        except Res.Error:
            pass
        else:
            return None

    # Construct a filename if we don't have one
    if not filename:
        if '.' in modname:
            filename = modname.split('.')[-1] + '.rsrc'
        else:
            filename = modname + '.rsrc'

    # Now create a list of folders to search
    searchdirs = []
    if modname == '__main__':
        # If we're main we look in the current directory
        searchdirs = [os.curdir]
    if modname in sys.modules:
        mod = sys.modules[modname]
        if hasattr(mod, '__file__'):
            searchdirs = [os.path.dirname(mod.__file__)]
    searchdirs.extend(sys.path)

    # And look for the file
    for dir in searchdirs:
        pathname = os.path.join(dir, filename)
        if os.path.exists(pathname):
            break
    else:
        raise ResourceFileNotFoundError, filename

    refno = open_pathname(pathname)

    # And check that the resource exists now
    if type(resid) is type(1):
        h = Res.GetResource(restype, resid)
    else:
        h = Res.GetNamedResource(restype, resid)
    return refno 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:63,代碼來源:macresource.py


注:本文中的Carbon.Res.Error方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。