def rsrcGetCreator(path): if drawer.isCarbon(): import Carbon.File fss = Carbon.File.FSSpec(path) finfo = fss.FSpGetFInfo() creator = finfo.Creator type = finfo.Type else: import macfs f = macfs.FSSpec(path) creator, type = f.GetCreatorType() return creator, type
def rsrcSetCreator(path, creator, type=None): if drawer.isCarbon(): import Carbon.File fss = Carbon.File.FSSpec(path) finfo = fss.FSpGetFInfo() finfo.Creator = creator if type != None: finfo.Type = type fss.FSpSetFInfo(finfo) else: import macfs f = macfs.FSSpec(path) f.SetCreatorType(creator, type)
def _macGetFile(prompt='pick a file', defaultDir=None): carbon = drawer.isCarbon() if carbon: import EasyDialogs path = EasyDialogs.AskFileForOpen(message=prompt) if path == None: return '', 0 else: return path, 1 else: import macfs fsspec, ok = macfs.PromptGetFile(prompt) if ok != 1: return '', 0 # failure path = fsspec.as_pathname() path = drawer.pathScrub(path) return path, 1
def _macGetDirectory(prompt='select a directory'): carbon = drawer.isCarbon() if carbon: import EasyDialogs path = EasyDialogs.AskFolder(message=prompt) if path == None: return '', 0 else: return path, 1 else: import macfs fsspec, ok = macfs.GetDirectory(prompt) if ok != 1: return '', 0 # failure path = fsspec.as_pathname() drawer.pathScrub(path) return path, 1
def _macPutFile(prompt='save a file', defaultName='test.txt', defaultDir=None): carbon = drawer.isCarbon() if carbon: import EasyDialogs path = EasyDialogs.AskFileForSave(message=prompt, savedFileName=defaultName) if path == None: return '', 0 else: return path, 1 else: import macfs fsspec, ok = macfs.PromptPutFile(prompt, defaultName) if ok != 1: return '', 0 path = fsspec.as_pathname() ## check extension, add if missing path = drawer.pathScrub(path) return path, 1
def autoDlgMethod(): """auto-detects which guis are available and selects one used when a dialog method is called without specifying which gui to use. acts as default selector (does _not_ use preference) """ if os.name == 'mac': carbon = drawer.isCarbon() if carbon: # macfs or carbon is available dlgVisualMethod = 'mac' else: #-1 , use text dlgVisualMethod = 'text' elif os.name == 'posix': visMethods = drawer.imageFormats() if 'tk' in visMethods: dlgVisualMethod = 'tk' else: dlgVisualMethod = 'text' else: # all windows flavors visMethods = drawer.imageFormats() if 'tk' in visMethods: dlgVisualMethod = 'tk' else: dlgVisualMethod = 'text' return dlgVisualMethod