[Python-checkins] python/dist/src/Mac/Lib macfs.py,1.3,1.4 macfsn.py,1.7,NONE

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Thu, 26 Dec 2002 13:09:41 -0800


Update of /cvsroot/python/python/dist/src/Mac/Lib
In directory sc8-pr-cvs1:/tmp/cvs-serv12734

Modified Files:
	macfs.py 
Removed Files:
	macfsn.py 
Log Message:
Integrated macfsn into macfs, and made the Standard File calls return the
correct FSSpec implementations.


Index: macfs.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Lib/macfs.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** macfs.py	26 Dec 2002 20:46:54 -0000	1.3
--- macfs.py	26 Dec 2002 21:09:39 -0000	1.4
***************
*** 3,6 ****
--- 3,10 ----
  """
  import sys
+ import struct
+ import Carbon.Res
+ import Carbon.File
+ import Nav
  
  # First step: ensure we also emulate the MACFS module, which contained
***************
*** 12,17 ****
  from Carbon.Files import *
  from Carbon.Folders import *
- # Another method:
- from Carbon.Folder import FindFolder
  
  # For some obscure historical reason these are here too:
--- 16,19 ----
***************
*** 20,28 ****
  smAllScripts = -3
  
- 
- import Carbon.File
  # The old name of the error object:
  error = Carbon.File.Error
  
  class FSSpec(Carbon.File.FSSpec):
  	def as_fsref(self):
--- 22,32 ----
  smAllScripts = -3
  
  # The old name of the error object:
  error = Carbon.File.Error
  
+ #
+ # The various objects macfs used to export. We override them here, because some
+ # of the method names are subtly different.
+ #
  class FSSpec(Carbon.File.FSSpec):
  	def as_fsref(self):
***************
*** 73,77 ****
  		
  from Carbon.File import FInfo
! 	
  FSSpecType = FSSpec
  FSRefType = FSRef
--- 77,82 ----
  		
  from Carbon.File import FInfo
! 
! # Backward-compatible type names:
  FSSpecType = FSSpec
  FSRefType = FSRef
***************
*** 79,82 ****
--- 84,88 ----
  FInfoType = FInfo
  
+ # Global functions:
  def ResolveAliasFile(fss, chain=1):
  	fss, isdir, isalias = Carbon.File.ResolveAliasFile(fss, chain)
***************
*** 95,98 ****
  	return Alias(Carbon.File.NewAliasMinimalFromFullPath(path, '', ''))
  	
! # Finally, install nav services
! import macfsn
\ No newline at end of file
--- 101,231 ----
  	return Alias(Carbon.File.NewAliasMinimalFromFullPath(path, '', ''))
  	
! # Another global function:
! from Carbon.Folder import FindFolder
! 
! #
! # Finally the old Standard File routine emulators.
! #
! 
! _movablemodal = 0
! _curfolder = None
! 
! 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 Carbon.Res.Handle(data)
! 	
! def StandardGetFile(*typelist):
! 	"""Ask for an input file, optionally specifying 4-char file types that are
! 	allowable"""
! 	return apply(PromptGetFile, (None,)+typelist)
! 	
! def PromptGetFile(prompt, *typelist):
! 	"""Ask for an input file giving the user a prompt message. Optionally you can
! 	specifying 4-char file types that are allowable"""
! 	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 = FSSpec(rr.selection[0])
! 		else:
! 			fss = None
! 			good = 0
! ##	if typehandle:
! ##		typehandle.DisposeHandle()
! 	return fss, good
! 
! def StandardPutFile(prompt, default=None):
! 	"""Ask the user for an output file, with a prompt. Optionally you cn supply a
! 	default output filename"""
! 	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 = FSSpec(rr.selection[0])
! 	return fss, good
! 	
! def SetFolder(folder):
! 	global _curfolder
! 	if _curfolder:
! 		rv = _curfolder
! 	else:
! 		rv = None
! 	_curfolder = FSSpec(folder)
! 	return rv
! 	
! def _handleSetFolder(args):
! 	global _curfolder
! 	if not _curfolder:
! 		return
! 	import aepack
! 	fss = _curfolder
! 	aedesc = aepack.pack(fss)
! 	args['defaultLocation'] = aedesc
! 	_curfolder = None
! 	
! def GetDirectory(prompt=None):
! 	"""Ask the user to select a folder. Optionally you can give a prompt."""
! 	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 = FSSpec(rr.selection[0])
! 	return fss, good
! 	

--- macfsn.py DELETED ---