diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2002-12-26 21:09:39 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2002-12-26 21:09:39 (GMT) |
commit | 6dd561bdfd532f63d5013ab88d3feb7dc5c8cd3f (patch) | |
tree | 81337261a1d4a1c358d7f75dcb1198b5a2dcb3dc /Mac/Lib/macfsn.py | |
parent | 315e9bebcd990fd93dcba056851bc806d1f2af47 (diff) | |
download | cpython-6dd561bdfd532f63d5013ab88d3feb7dc5c8cd3f.zip cpython-6dd561bdfd532f63d5013ab88d3feb7dc5c8cd3f.tar.gz cpython-6dd561bdfd532f63d5013ab88d3feb7dc5c8cd3f.tar.bz2 |
Integrated macfsn into macfs, and made the Standard File calls return the
correct FSSpec implementations.
Diffstat (limited to 'Mac/Lib/macfsn.py')
-rw-r--r-- | Mac/Lib/macfsn.py | 162 |
1 files changed, 0 insertions, 162 deletions
diff --git a/Mac/Lib/macfsn.py b/Mac/Lib/macfsn.py deleted file mode 100644 index 8f3203c..0000000 --- a/Mac/Lib/macfsn.py +++ /dev/null @@ -1,162 +0,0 @@ -"""StandardFile compatability module: implement macfs StandardFile -API calls with Navigation Services""" -import macfs -import struct -from Carbon import Res -try: - import Nav -except ImportError: - Nav = None - -_curfolder = None -_movablemodal = 1 - -def _mktypelist(typelist): - # Workaround for OSX typeless files: - if 'TEXT' in typelist and not '\0\0\0\0' in typelist: - typelist = typelist + ('\0\0\0\0',) - if not typelist: - return None - data = 'Pyth' + struct.pack("hh", 0, len(typelist)) - for type in typelist: - data = data+type - return Res.Handle(data) - -def _StandardGetFile(*typelist): - return apply(_PromptGetFile, (None,)+typelist) - -def _PromptGetFile(prompt, *typelist): - args = {} - flags = 0x56 - typehandle = _mktypelist(typelist) - if typehandle: - args['typeList'] = typehandle - else: - flags = flags | 0x01 - if prompt: - args['message'] = prompt - args['preferenceKey'] = 'PyMC' - if _movablemodal: - args['eventProc'] = None - args['dialogOptionFlags'] = flags - _handleSetFolder(args) - try: - rr = Nav.NavChooseFile(args) - good = 1 - except Nav.error, arg: - if arg[0] != -128: # userCancelledErr - raise Nav.error, arg - good = 0 - fss = None - else: - if rr.selection: - fss = rr.selection[0] - else: - fss = None - good = 0 -## if typehandle: -## typehandle.DisposeHandle() - return fss, good - -def _StandardPutFile(prompt, default=None): - args = {} - flags = 0x07 - if prompt: - args['message'] = prompt - args['preferenceKey'] = 'PyMC' - if _movablemodal: - args['eventProc'] = None - if default: - args['savedFileName'] = default - args['dialogOptionFlags'] = flags - _handleSetFolder(args) - try: - rr = Nav.NavPutFile(args) - good = 1 - except Nav.error, arg: - if arg[0] != -128: # userCancelledErr - raise Nav.error, arg - good = 0 - fss = None - else: - fss = rr.selection[0] - return fss, good - -def _SetFolder(folder): - global _curfolder - if _curfolder: - rv = _curfolder - else: - rv = None - _curfolder = macfs.FSSpec(folder) - return rv - -def _handleSetFolder(args): - global _curfolder - if not _curfolder: - return - import aepack - fss = macfs.FSSpec(_curfolder) - aedesc = aepack.pack(fss) - args['defaultLocation'] = aedesc - _curfolder = None - -def _GetDirectory(prompt=None): - args = {} - flags = 0x17 - if prompt: - args['message'] = prompt - args['preferenceKey'] = 'PyMC' - if _movablemodal: - args['eventProc'] = None - args['dialogOptionFlags'] = flags - _handleSetFolder(args) - try: - rr = Nav.NavChooseFolder(args) - good = 1 - except Nav.error, arg: - if arg[0] != -128: # userCancelledErr - raise Nav.error, arg - good = 0 - fss = None - else: - fss = rr.selection[0] - return fss, good - -def _install(): - macfs.StandardGetFile = StandardGetFile - macfs.PromptGetFile = PromptGetFile - macfs.StandardPutFile = StandardPutFile - macfs.SetFolder = SetFolder - macfs.GetDirectory = GetDirectory - -if Nav and Nav.NavServicesAvailable(): - StandardGetFile = _StandardGetFile - PromptGetFile = _PromptGetFile - StandardPutFile = _StandardPutFile - SetFolder = _SetFolder - GetDirectory = _GetDirectory - _install() -else: - from macfs import StandardGetFile, PromptGetFile, StandardPutFile, SetFolder, GetDirectory - - -if __name__ == '__main__': - print 'Testing StandardGetFile' - fss, ok = StandardGetFile() - print '->', fss, ok - print 'Testing StandardGetFile("TEXT")' - fss, ok = StandardGetFile("TEXT") - print '->', fss, ok - print 'Testing PromptGetFile' - fss, ok = PromptGetFile("prompt") - print '->', fss, ok - print 'Testing StandardPutFile("the prompt", "default")' - fss, ok = StandardPutFile("the prompt", "default") - print '->', fss, ok - print 'Testing GetDirectory("another prompt")' - fss, ok = GetDirectory("Another prompt") - print '->', fss, ok - import sys - sys.exit(1) - |