Commit e7ee17c5 authored by Jack Jansen's avatar Jack Jansen

Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now

used everywhere).
parent 85233bf7
import macfs
import marshal import marshal
import types import types
from Carbon import Folder
from MACFS import kOnSystemDisk from Carbon import Folders
class PrefObject: class PrefObject:
...@@ -71,8 +70,7 @@ class PrefFile(PrefObject): ...@@ -71,8 +70,7 @@ class PrefFile(PrefObject):
prefdict[key] = value prefdict[key] = value
marshal.dump(prefdict, open(self.__path, 'wb')) marshal.dump(prefdict, open(self.__path, 'wb'))
try: try:
fss = macfs.FSSpec(macfs.FSRef(self.__path)) MacOS.SetCreatorAndType(self.__path, self.__creator, 'pref')
fss.SetCreatorType(self.__creator, 'pref')
except: except:
pass pass
...@@ -98,9 +96,8 @@ def GetPrefs(prefname, creator = 'Pyth'): ...@@ -98,9 +96,8 @@ def GetPrefs(prefname, creator = 'Pyth'):
if _prefscache.has_key(prefname): if _prefscache.has_key(prefname):
return _prefscache[prefname] return _prefscache[prefname]
# Find the preferences folder and our prefs file, create if needed. # Find the preferences folder and our prefs file, create if needed.
vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0) fsr = Folder.FSFindFolder(Folders.kOnSystemDisk, 'pref', 1)
prefsfolder_fss = macfs.FSSpec((vrefnum, dirid, '')) prefsfolder = fsr.as_pathname()
prefsfolder = macfs.FSRef(prefsfolder_fss).as_fsspec().as_pathname()
path = os.path.join(prefsfolder, prefname) path = os.path.join(prefsfolder, prefname)
head, tail = os.path.split(path) head, tail = os.path.split(path)
# make sure the folder(s) exist # make sure the folder(s) exist
......
...@@ -83,7 +83,6 @@ def main(): ...@@ -83,7 +83,6 @@ def main():
stats = pstats.Stats(i) stats = pstats.Stats(i)
browser = ProfileBrowser(stats) browser = ProfileBrowser(stats)
else: else:
import macfs
filename = EasyDialogs.AskFileForOpen(message='Profiler data') filename = EasyDialogs.AskFileForOpen(message='Profiler data')
if not filename: sys.exit(0) if not filename: sys.exit(0)
stats = pstats.Stats(filename) stats = pstats.Stats(filename)
......
...@@ -322,9 +322,7 @@ class BrowserWidget(W.CustomList): ...@@ -322,9 +322,7 @@ class BrowserWidget(W.CustomList):
editor.select() editor.select()
return return
elif os.path.exists(value) and os.path.isfile(value): elif os.path.exists(value) and os.path.isfile(value):
import macfs if MacOS.GetCreatorAndType(value)[1] in ('TEXT', '\0\0\0\0'):
fss = macfs.FSSpec(value)
if fss.GetCreatorType()[1] == 'TEXT':
W.getapplication().openscript(value) W.getapplication().openscript(value)
def itemrepr(self, (key, value, arrow, indent), str = str, double_repr = double_repr, def itemrepr(self, (key, value, arrow, indent), str = str, double_repr = double_repr,
......
...@@ -85,7 +85,6 @@ class ConsoleTextWidget(W.EditText): ...@@ -85,7 +85,6 @@ class ConsoleTextWidget(W.EditText):
self._inputstart = selstart self._inputstart = selstart
def domenu_save_as(self, *args): def domenu_save_as(self, *args):
import macfs
filename = EasyDialogs.AskFileForSave(message='Save console text as:', filename = EasyDialogs.AskFileForSave(message='Save console text as:',
savedFileName='console.txt') savedFileName='console.txt')
if not filename: if not filename:
...@@ -93,7 +92,7 @@ class ConsoleTextWidget(W.EditText): ...@@ -93,7 +92,7 @@ class ConsoleTextWidget(W.EditText):
f = open(filename, 'wb') f = open(filename, 'wb')
f.write(self.get()) f.write(self.get())
f.close() f.close()
fss.SetCreatorType(W._signature, 'TEXT') MacOS.SetCreatorAndType(filename, W._signature, 'TEXT')
def write(self, text): def write(self, text):
self._buf = self._buf + text self._buf = self._buf + text
...@@ -242,7 +241,6 @@ class OutputTextWidget(W.EditText): ...@@ -242,7 +241,6 @@ class OutputTextWidget(W.EditText):
def domenu_save_as(self, *args): def domenu_save_as(self, *args):
title = self._parentwindow.gettitle() title = self._parentwindow.gettitle()
import macfs
filename = EasyDialogs.AskFileForSave(message='Save %s text as:' % title, filename = EasyDialogs.AskFileForSave(message='Save %s text as:' % title,
savedFileName=title + '.txt') savedFileName=title + '.txt')
if not filename: if not filename:
...@@ -250,7 +248,7 @@ class OutputTextWidget(W.EditText): ...@@ -250,7 +248,7 @@ class OutputTextWidget(W.EditText):
f = open(filename, 'wb') f = open(filename, 'wb')
f.write(self.get()) f.write(self.get())
f.close() f.close()
fss.SetCreatorType(W._signature, 'TEXT') MacOS.SetCreatorAndType(filename, W._signature, 'TEXT')
def domenu_cut(self, *args): def domenu_cut(self, *args):
self.domenu_copy(*args) self.domenu_copy(*args)
......
import re import re
import W import W
import macfs
import os import os
import MacPrefs import MacPrefs
import MacOS import MacOS
......
...@@ -4,14 +4,13 @@ import W ...@@ -4,14 +4,13 @@ import W
import Wtraceback import Wtraceback
from Wkeys import * from Wkeys import *
import macfs
import MACFS
import MacOS import MacOS
import EasyDialogs import EasyDialogs
from Carbon import Win from Carbon import Win
from Carbon import Res from Carbon import Res
from Carbon import Evt from Carbon import Evt
from Carbon import Qd from Carbon import Qd
from Carbon import File
import os import os
import imp import imp
import sys import sys
...@@ -19,6 +18,8 @@ import string ...@@ -19,6 +18,8 @@ import string
import marshal import marshal
import re import re
smAllScripts = -3
if hasattr(Win, "FrontNonFloatingWindow"): if hasattr(Win, "FrontNonFloatingWindow"):
MyFrontWindow = Win.FrontNonFloatingWindow MyFrontWindow = Win.FrontNonFloatingWindow
else: else:
...@@ -61,8 +62,7 @@ class Editor(W.Window): ...@@ -61,8 +62,7 @@ class Editor(W.Window):
f = open(path, "rb") f = open(path, "rb")
text = f.read() text = f.read()
f.close() f.close()
fss = macfs.FSSpec(path) self._creator, filetype = MacOS.GetCreatorAndType(path)
self._creator, filetype = fss.GetCreatorType()
else: else:
raise IOError, "file '%s' does not exist" % path raise IOError, "file '%s' does not exist" % path
self.path = path self.path = path
...@@ -134,7 +134,7 @@ class Editor(W.Window): ...@@ -134,7 +134,7 @@ class Editor(W.Window):
try: try:
resref = Res.FSpOpenResFile(self.path, 3) resref = Res.FSpOpenResFile(self.path, 3)
except Res.Error: except Res.Error:
Res.FSpCreateResFile(self.path, self._creator, 'TEXT', MACFS.smAllScripts) Res.FSpCreateResFile(self.path, self._creator, 'TEXT', smAllScripts)
resref = Res.FSpOpenResFile(self.path, 3) resref = Res.FSpOpenResFile(self.path, 3)
try: try:
data = Res.Resource(marshal.dumps(self.settings)) data = Res.Resource(marshal.dumps(self.settings))
...@@ -389,8 +389,7 @@ class Editor(W.Window): ...@@ -389,8 +389,7 @@ class Editor(W.Window):
fp = open(self.path, 'wb') # open file in binary mode, data has '\r' line-endings fp = open(self.path, 'wb') # open file in binary mode, data has '\r' line-endings
fp.write(data) fp.write(data)
fp.close() fp.close()
fss = macfs.FSSpec(self.path) MacOS.SetCreatorAndType(self.path, self._creator, 'TEXT')
fss.SetCreatorType(self._creator, 'TEXT')
self.getsettings() self.getsettings()
self.writewindowsettings() self.writewindowsettings()
self.editgroup.editor.changed = 0 self.editgroup.editor.changed = 0
...@@ -419,8 +418,8 @@ class Editor(W.Window): ...@@ -419,8 +418,8 @@ class Editor(W.Window):
app.makeopenwindowsmenu() app.makeopenwindowsmenu()
if hasattr(app, 'makescriptsmenu'): if hasattr(app, 'makescriptsmenu'):
app = W.getapplication() app = W.getapplication()
fss, fss_changed = app.scriptsfolder.Resolve() fsr, changed = app.scriptsfolder.FSResolveAlias(None)
path = fss.as_pathname() path = fsr.as_pathname()
if path == self.path[:len(path)]: if path == self.path[:len(path)]:
W.getapplication().makescriptsmenu() W.getapplication().makescriptsmenu()
...@@ -546,14 +545,8 @@ class Editor(W.Window): ...@@ -546,14 +545,8 @@ class Editor(W.Window):
interp_path = os.path.join(sys.exec_prefix, "bin", "python") interp_path = os.path.join(sys.exec_prefix, "bin", "python")
file_path = self.path file_path = self.path
if not os.path.exists(interp_path): if not os.path.exists(interp_path):
# This "can happen" if we are running IDE under MacPython. Try # This "can happen" if we are running IDE under MacPython-OS9.
# the standard location. raise W.AlertError, "Can't find command-line Python"
interp_path = "/Library/Frameworks/Python.framework/Versions/2.3/bin/python"
try:
fsr = macfs.FSRef(interp_path)
except macfs.Error:
raise W.AlertError, "Can't find command-line Python"
file_path = macfs.FSRef(macfs.FSSpec(self.path)).as_pathname()
cmd = '"%s" "%s" ; exit' % (interp_path, file_path) cmd = '"%s" "%s" ; exit' % (interp_path, file_path)
t = Terminal.Terminal() t = Terminal.Terminal()
t.do_script(with_command=cmd) t.do_script(with_command=cmd)
...@@ -1368,8 +1361,10 @@ def EditorDefaultSettings(): ...@@ -1368,8 +1361,10 @@ def EditorDefaultSettings():
def resolvealiases(path): def resolvealiases(path):
try: try:
return macfs.ResolveAliasFile(path)[0].as_pathname() fsr, d1, d2 = File.FSResolveAliasFile(path, 1)
except (macfs.error, ValueError), (error, str): path = fsr.as_pathname()
return path
except (File.Error, ValueError), (error, str):
if error <> -120: if error <> -120:
raise raise
dir, file = os.path.split(path) dir, file = os.path.split(path)
......
...@@ -7,9 +7,10 @@ import Wapplication ...@@ -7,9 +7,10 @@ import Wapplication
import W import W
import os import os
import sys import sys
import macfs
import MacOS import MacOS
import EasyDialogs import EasyDialogs
from Carbon import File
from Carbon import Files
if MacOS.runtimemodel == 'macho': if MacOS.runtimemodel == 'macho':
ELIPSES = '...' ELIPSES = '...'
...@@ -23,6 +24,10 @@ def runningOnOSX(): ...@@ -23,6 +24,10 @@ def runningOnOSX():
value = gestalt("menu") & gestaltMenuMgrAquaLayoutMask value = gestalt("menu") & gestaltMenuMgrAquaLayoutMask
return not not value return not not value
def getmodtime(file):
file = File.FSRef(file)
catinfo, d1, d2, d3 = file.FSGetCatalogInfo(Files.kFSCatInfoContentMod)
return catinfo.contentModDate
class PythonIDE(Wapplication.Application): class PythonIDE(Wapplication.Application):
...@@ -125,21 +130,21 @@ class PythonIDE(Wapplication.Application): ...@@ -125,21 +130,21 @@ class PythonIDE(Wapplication.Application):
prefs = self.getprefs() prefs = self.getprefs()
try: try:
fss, fss_changed = macfs.RawAlias(prefs.scriptsfolder).Resolve() fsr, d = File.Alias(rawdata=prefs.scriptsfolder).FSResolveAlias(None)
self.scriptsfolder = fss.NewAlias() self.scriptsfolder = fsr.FSNewAliasMinimal()
except: except:
path = os.path.join(os.getcwd(), ":Mac:IDE scripts") path = os.path.join(os.getcwd(), "Mac", "IDE scripts")
if not os.path.exists(path): if not os.path.exists(path):
path = os.path.join(os.getcwd(), "Scripts") path = os.path.join(os.getcwd(), "Scripts")
if not os.path.exists(path): if not os.path.exists(path):
os.mkdir(path) os.mkdir(path)
f = open(os.path.join(path, "Place your scripts here"+ELIPSES), "w") f = open(os.path.join(path, "Place your scripts here"+ELIPSES), "w")
f.close() f.close()
fss = macfs.FSSpec(path) fsr = File.FSRef(path)
self.scriptsfolder = fss.NewAlias() self.scriptsfolder = fsr.FSNewAliasMinimal()
self.scriptsfoldermodtime = fss.GetDates()[1] self.scriptsfoldermodtime = getmodtime(fsr)
else: else:
self.scriptsfoldermodtime = fss.GetDates()[1] self.scriptsfoldermodtime = getmodtime(fsr)
prefs.scriptsfolder = self.scriptsfolder.data prefs.scriptsfolder = self.scriptsfolder.data
self._scripts = {} self._scripts = {}
self.scriptsmenu = None self.scriptsmenu = None
...@@ -153,9 +158,9 @@ class PythonIDE(Wapplication.Application): ...@@ -153,9 +158,9 @@ class PythonIDE(Wapplication.Application):
def suspendresume(self, onoff): def suspendresume(self, onoff):
if onoff: if onoff:
fss, fss_changed = self.scriptsfolder.Resolve() fsr, changed = self.scriptsfolder.FSResolveAlias(None)
modtime = fss.GetDates()[1] modtime = getmodtime(fsr)
if self.scriptsfoldermodtime <> modtime or fss_changed: if self.scriptsfoldermodtime <> modtime or changed:
self.scriptsfoldermodtime = modtime self.scriptsfoldermodtime = modtime
W.SetCursor('watch') W.SetCursor('watch')
self.makescriptsmenu() self.makescriptsmenu()
...@@ -171,12 +176,12 @@ class PythonIDE(Wapplication.Application): ...@@ -171,12 +176,12 @@ class PythonIDE(Wapplication.Application):
if type(docs) <> type([]): if type(docs) <> type([]):
docs = [docs] docs = [docs]
for doc in docs: for doc in docs:
fss, a = doc.Resolve() fsr, a = doc.FSResolveAlias(None)
path = fss.as_pathname() path = fsr.as_pathname()
self.opendoc(path) self.opendoc(path)
def opendoc(self, path): def opendoc(self, path):
fcreator, ftype = macfs.FSSpec(path).GetCreatorType() fcreator, ftype = MacOS.GetCreatorAndType(path)
if ftype == 'TEXT': if ftype == 'TEXT':
self.openscript(path) self.openscript(path)
elif ftype == '\0\0\0\0' and path[-3:] == '.py': elif ftype == '\0\0\0\0' and path[-3:] == '.py':
...@@ -191,11 +196,11 @@ class PythonIDE(Wapplication.Application): ...@@ -191,11 +196,11 @@ class PythonIDE(Wapplication.Application):
Splash.about() Splash.about()
def do_setscriptsfolder(self, *args): def do_setscriptsfolder(self, *args):
fss = EasyDialogs.AskFolder(message="Select Scripts Folder", fsr = EasyDialogs.AskFolder(message="Select Scripts Folder",
wanted=macfs.FSSpec) wanted=File.FSRef)
if fss: if fsr:
prefs = self.getprefs() prefs = self.getprefs()
alis = fss.NewAlias() alis = fsr.FSNewAliasMinimal()
prefs.scriptsfolder = alis.data prefs.scriptsfolder = alis.data
self.scriptsfolder = alis self.scriptsfolder = alis
self.makescriptsmenu() self.makescriptsmenu()
...@@ -246,8 +251,8 @@ class PythonIDE(Wapplication.Application): ...@@ -246,8 +251,8 @@ class PythonIDE(Wapplication.Application):
self.scriptsmenu = FrameWork.Menu(self.menubar, "Scripts") self.scriptsmenu = FrameWork.Menu(self.menubar, "Scripts")
#FrameWork.MenuItem(self.scriptsmenu, "New script", None, self.domenu_new) #FrameWork.MenuItem(self.scriptsmenu, "New script", None, self.domenu_new)
#self.scriptsmenu.addseparator() #self.scriptsmenu.addseparator()
fss, fss_changed = self.scriptsfolder.Resolve() fsr, d1 = self.scriptsfolder.FSResolveAlias(None)
self.scriptswalk(fss.as_pathname(), self.scriptsmenu) self.scriptswalk(fsr.as_pathname(), self.scriptsmenu)
def makeopenwindowsmenu(self): def makeopenwindowsmenu(self):
for i in range(len(self.openwindowsmenu.items)): for i in range(len(self.openwindowsmenu.items)):
......
...@@ -8,6 +8,7 @@ import traceback ...@@ -8,6 +8,7 @@ import traceback
from types import * from types import *
from Carbon import Menu; MenuToolbox = Menu; del Menu from Carbon import Menu; MenuToolbox = Menu; del Menu
import macresource import macresource
from Carbon import File
if hasattr(Win, "FrontNonFloatingWindow"): if hasattr(Win, "FrontNonFloatingWindow"):
MyFrontWindow = Win.FrontNonFloatingWindow MyFrontWindow = Win.FrontNonFloatingWindow
...@@ -273,7 +274,7 @@ class Application(FrameWork.Application): ...@@ -273,7 +274,7 @@ class Application(FrameWork.Application):
if done.has_key(top): if done.has_key(top):
return return
done[top] = 1 done[top] = 1
import os, macfs, string import os, string
try: try:
names = os.listdir(top) names = os.listdir(top)
except os.error: except os.error:
...@@ -285,11 +286,11 @@ class Application(FrameWork.Application): ...@@ -285,11 +286,11 @@ class Application(FrameWork.Application):
if name == "CVS": if name == "CVS":
continue continue
try: try:
fss, isdir, isalias = macfs.ResolveAliasFile(name) fsr, isdir, isalias = File.FSResolveAliasFile(name, 1)
except: except:
# maybe a broken alias # maybe a broken alias
continue continue
path = fss.as_pathname() path = fsr.as_pathname()
if done.has_key(path): if done.has_key(path):
continue continue
name = string.strip(name) name = string.strip(name)
...@@ -301,7 +302,7 @@ class Application(FrameWork.Application): ...@@ -301,7 +302,7 @@ class Application(FrameWork.Application):
submenu = FrameWork.SubMenu(menu, name) submenu = FrameWork.SubMenu(menu, name)
self.scriptswalk(path, submenu, done) self.scriptswalk(path, submenu, done)
else: else:
creator, type = fss.GetCreatorType() creator, type = MacOS.GetCreatorAndType(path)
if type == 'TEXT': if type == 'TEXT':
if name[-3:] == '.py': if name[-3:] == '.py':
name = name[:-3] name = name[:-3]
......
...@@ -3,7 +3,7 @@ from Carbon import Qd ...@@ -3,7 +3,7 @@ from Carbon import Qd
from Carbon import Win from Carbon import Win
from Carbon import Qt, QuickTime from Carbon import Qt, QuickTime
import W import W
import macfs from Carbon import File
from Carbon import Evt, Events from Carbon import Evt, Events
_moviesinitialized = 0 _moviesinitialized = 0
...@@ -33,14 +33,9 @@ class Movie(W.Widget): ...@@ -33,14 +33,9 @@ class Movie(W.Widget):
if self.movie: if self.movie:
#self.GetWindow().InvalWindowRect(self.movie.GetMovieBox()) #self.GetWindow().InvalWindowRect(self.movie.GetMovieBox())
Qd.PaintRect(self.movie.GetMovieBox()) Qd.PaintRect(self.movie.GetMovieBox())
if type(path_or_fss) == type(''): path = File.pathname(path)
path = path_or_fss
fss = macfs.FSSpec(path)
else:
path = path_or_fss.as_pathname()
fss = path_or_fss
self.movietitle = os.path.basename(path) self.movietitle = os.path.basename(path)
movieResRef = Qt.OpenMovieFile(fss, 1) movieResRef = Qt.OpenMovieFile(path_or_fss, 1)
self.movie, dummy, dummy = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive) self.movie, dummy, dummy = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
self.moviebox = self.movie.GetMovieBox() self.moviebox = self.movie.GetMovieBox()
self.calcmoviebox() self.calcmoviebox()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment