Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e7ee17c

Browse files
committed
Got rid of macfs and FSSpecs in general (pathnames or FSRefs are now
used everywhere).
1 parent 85233bf commit e7ee17c

9 files changed

Lines changed: 55 additions & 68 deletions

File tree

Mac/Tools/IDE/MacPrefs.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import macfs
21
import marshal
32
import types
4-
5-
from MACFS import kOnSystemDisk
3+
from Carbon import Folder
4+
from Carbon import Folders
65

76
class PrefObject:
87

@@ -71,8 +70,7 @@ def save(self):
7170
prefdict[key] = value
7271
marshal.dump(prefdict, open(self.__path, 'wb'))
7372
try:
74-
fss = macfs.FSSpec(macfs.FSRef(self.__path))
75-
fss.SetCreatorType(self.__creator, 'pref')
73+
MacOS.SetCreatorAndType(self.__path, self.__creator, 'pref')
7674
except:
7775
pass
7876

@@ -98,9 +96,8 @@ def GetPrefs(prefname, creator = 'Pyth'):
9896
if _prefscache.has_key(prefname):
9997
return _prefscache[prefname]
10098
# Find the preferences folder and our prefs file, create if needed.
101-
vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0)
102-
prefsfolder_fss = macfs.FSSpec((vrefnum, dirid, ''))
103-
prefsfolder = macfs.FSRef(prefsfolder_fss).as_fsspec().as_pathname()
99+
fsr = Folder.FSFindFolder(Folders.kOnSystemDisk, 'pref', 1)
100+
prefsfolder = fsr.as_pathname()
104101
path = os.path.join(prefsfolder, prefname)
105102
head, tail = os.path.split(path)
106103
# make sure the folder(s) exist

Mac/Tools/IDE/ProfileBrowser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def main():
8383
stats = pstats.Stats(i)
8484
browser = ProfileBrowser(stats)
8585
else:
86-
import macfs
8786
filename = EasyDialogs.AskFileForOpen(message='Profiler data')
8887
if not filename: sys.exit(0)
8988
stats = pstats.Stats(filename)

Mac/Tools/IDE/PyBrowser.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,7 @@ def openselection(self):
322322
editor.select()
323323
return
324324
elif os.path.exists(value) and os.path.isfile(value):
325-
import macfs
326-
fss = macfs.FSSpec(value)
327-
if fss.GetCreatorType()[1] == 'TEXT':
325+
if MacOS.GetCreatorAndType(value)[1] in ('TEXT', '\0\0\0\0'):
328326
W.getapplication().openscript(value)
329327

330328
def itemrepr(self, (key, value, arrow, indent), str = str, double_repr = double_repr,

Mac/Tools/IDE/PyConsole.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,14 @@ def key(self, char, event):
8585
self._inputstart = selstart
8686

8787
def domenu_save_as(self, *args):
88-
import macfs
8988
filename = EasyDialogs.AskFileForSave(message='Save console text as:',
9089
savedFileName='console.txt')
9190
if not filename:
9291
return
9392
f = open(filename, 'wb')
9493
f.write(self.get())
9594
f.close()
96-
fss.SetCreatorType(W._signature, 'TEXT')
95+
MacOS.SetCreatorAndType(filename, W._signature, 'TEXT')
9796

9897
def write(self, text):
9998
self._buf = self._buf + text
@@ -242,15 +241,14 @@ class OutputTextWidget(W.EditText):
242241

243242
def domenu_save_as(self, *args):
244243
title = self._parentwindow.gettitle()
245-
import macfs
246244
filename = EasyDialogs.AskFileForSave(message='Save %s text as:' % title,
247245
savedFileName=title + '.txt')
248246
if not filename:
249247
return
250248
f = open(filename, 'wb')
251249
f.write(self.get())
252250
f.close()
253-
fss.SetCreatorType(W._signature, 'TEXT')
251+
MacOS.SetCreatorAndType(filename, W._signature, 'TEXT')
254252

255253
def domenu_cut(self, *args):
256254
self.domenu_copy(*args)

Mac/Tools/IDE/PyDocSearch.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import re
22
import W
3-
import macfs
43
import os
54
import MacPrefs
65
import MacOS

Mac/Tools/IDE/PyEdit.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@
44
import Wtraceback
55
from Wkeys import *
66

7-
import macfs
8-
import MACFS
97
import MacOS
108
import EasyDialogs
119
from Carbon import Win
1210
from Carbon import Res
1311
from Carbon import Evt
1412
from Carbon import Qd
13+
from Carbon import File
1514
import os
1615
import imp
1716
import sys
1817
import string
1918
import marshal
2019
import re
2120

21+
smAllScripts = -3
22+
2223
if hasattr(Win, "FrontNonFloatingWindow"):
2324
MyFrontWindow = Win.FrontNonFloatingWindow
2425
else:
@@ -61,8 +62,7 @@ def __init__(self, path = "", title = ""):
6162
f = open(path, "rb")
6263
text = f.read()
6364
f.close()
64-
fss = macfs.FSSpec(path)
65-
self._creator, filetype = fss.GetCreatorType()
65+
self._creator, filetype = MacOS.GetCreatorAndType(path)
6666
else:
6767
raise IOError, "file '%s' does not exist" % path
6868
self.path = path
@@ -134,7 +134,7 @@ def writewindowsettings(self):
134134
try:
135135
resref = Res.FSpOpenResFile(self.path, 3)
136136
except Res.Error:
137-
Res.FSpCreateResFile(self.path, self._creator, 'TEXT', MACFS.smAllScripts)
137+
Res.FSpCreateResFile(self.path, self._creator, 'TEXT', smAllScripts)
138138
resref = Res.FSpOpenResFile(self.path, 3)
139139
try:
140140
data = Res.Resource(marshal.dumps(self.settings))
@@ -389,8 +389,7 @@ def domenu_save(self, *args):
389389
fp = open(self.path, 'wb') # open file in binary mode, data has '\r' line-endings
390390
fp.write(data)
391391
fp.close()
392-
fss = macfs.FSSpec(self.path)
393-
fss.SetCreatorType(self._creator, 'TEXT')
392+
MacOS.SetCreatorAndType(self.path, self._creator, 'TEXT')
394393
self.getsettings()
395394
self.writewindowsettings()
396395
self.editgroup.editor.changed = 0
@@ -419,8 +418,8 @@ def domenu_save_as(self, *args):
419418
app.makeopenwindowsmenu()
420419
if hasattr(app, 'makescriptsmenu'):
421420
app = W.getapplication()
422-
fss, fss_changed = app.scriptsfolder.Resolve()
423-
path = fss.as_pathname()
421+
fsr, changed = app.scriptsfolder.FSResolveAlias(None)
422+
path = fsr.as_pathname()
424423
if path == self.path[:len(path)]:
425424
W.getapplication().makescriptsmenu()
426425

@@ -546,14 +545,8 @@ def _run_with_cl_interpreter(self):
546545
interp_path = os.path.join(sys.exec_prefix, "bin", "python")
547546
file_path = self.path
548547
if not os.path.exists(interp_path):
549-
# This "can happen" if we are running IDE under MacPython. Try
550-
# the standard location.
551-
interp_path = "/Library/Frameworks/Python.framework/Versions/2.3/bin/python"
552-
try:
553-
fsr = macfs.FSRef(interp_path)
554-
except macfs.Error:
555-
raise W.AlertError, "Can't find command-line Python"
556-
file_path = macfs.FSRef(macfs.FSSpec(self.path)).as_pathname()
548+
# This "can happen" if we are running IDE under MacPython-OS9.
549+
raise W.AlertError, "Can't find command-line Python"
557550
cmd = '"%s" "%s" ; exit' % (interp_path, file_path)
558551
t = Terminal.Terminal()
559552
t.do_script(with_command=cmd)
@@ -1368,8 +1361,10 @@ def EditorDefaultSettings():
13681361

13691362
def resolvealiases(path):
13701363
try:
1371-
return macfs.ResolveAliasFile(path)[0].as_pathname()
1372-
except (macfs.error, ValueError), (error, str):
1364+
fsr, d1, d2 = File.FSResolveAliasFile(path, 1)
1365+
path = fsr.as_pathname()
1366+
return path
1367+
except (File.Error, ValueError), (error, str):
13731368
if error <> -120:
13741369
raise
13751370
dir, file = os.path.split(path)

Mac/Tools/IDE/PythonIDEMain.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import W
88
import os
99
import sys
10-
import macfs
1110
import MacOS
1211
import EasyDialogs
12+
from Carbon import File
13+
from Carbon import Files
1314

1415
if MacOS.runtimemodel == 'macho':
1516
ELIPSES = '...'
@@ -23,6 +24,10 @@ def runningOnOSX():
2324
value = gestalt("menu") & gestaltMenuMgrAquaLayoutMask
2425
return not not value
2526

27+
def getmodtime(file):
28+
file = File.FSRef(file)
29+
catinfo, d1, d2, d3 = file.FSGetCatalogInfo(Files.kFSCatInfoContentMod)
30+
return catinfo.contentModDate
2631

2732
class PythonIDE(Wapplication.Application):
2833

@@ -125,21 +130,21 @@ def makeusermenus(self):
125130

126131
prefs = self.getprefs()
127132
try:
128-
fss, fss_changed = macfs.RawAlias(prefs.scriptsfolder).Resolve()
129-
self.scriptsfolder = fss.NewAlias()
133+
fsr, d = File.Alias(rawdata=prefs.scriptsfolder).FSResolveAlias(None)
134+
self.scriptsfolder = fsr.FSNewAliasMinimal()
130135
except:
131-
path = os.path.join(os.getcwd(), ":Mac:IDE scripts")
136+
path = os.path.join(os.getcwd(), "Mac", "IDE scripts")
132137
if not os.path.exists(path):
133138
path = os.path.join(os.getcwd(), "Scripts")
134139
if not os.path.exists(path):
135140
os.mkdir(path)
136141
f = open(os.path.join(path, "Place your scripts here"+ELIPSES), "w")
137142
f.close()
138-
fss = macfs.FSSpec(path)
139-
self.scriptsfolder = fss.NewAlias()
140-
self.scriptsfoldermodtime = fss.GetDates()[1]
143+
fsr = File.FSRef(path)
144+
self.scriptsfolder = fsr.FSNewAliasMinimal()
145+
self.scriptsfoldermodtime = getmodtime(fsr)
141146
else:
142-
self.scriptsfoldermodtime = fss.GetDates()[1]
147+
self.scriptsfoldermodtime = getmodtime(fsr)
143148
prefs.scriptsfolder = self.scriptsfolder.data
144149
self._scripts = {}
145150
self.scriptsmenu = None
@@ -153,9 +158,9 @@ def quitevent(self, theAppleEvent, theReply):
153158

154159
def suspendresume(self, onoff):
155160
if onoff:
156-
fss, fss_changed = self.scriptsfolder.Resolve()
157-
modtime = fss.GetDates()[1]
158-
if self.scriptsfoldermodtime <> modtime or fss_changed:
161+
fsr, changed = self.scriptsfolder.FSResolveAlias(None)
162+
modtime = getmodtime(fsr)
163+
if self.scriptsfoldermodtime <> modtime or changed:
159164
self.scriptsfoldermodtime = modtime
160165
W.SetCursor('watch')
161166
self.makescriptsmenu()
@@ -171,12 +176,12 @@ def opendocsevent(self, theAppleEvent, theReply):
171176
if type(docs) <> type([]):
172177
docs = [docs]
173178
for doc in docs:
174-
fss, a = doc.Resolve()
175-
path = fss.as_pathname()
179+
fsr, a = doc.FSResolveAlias(None)
180+
path = fsr.as_pathname()
176181
self.opendoc(path)
177182

178183
def opendoc(self, path):
179-
fcreator, ftype = macfs.FSSpec(path).GetCreatorType()
184+
fcreator, ftype = MacOS.GetCreatorAndType(path)
180185
if ftype == 'TEXT':
181186
self.openscript(path)
182187
elif ftype == '\0\0\0\0' and path[-3:] == '.py':
@@ -191,11 +196,11 @@ def do_about(self, id, item, window, event):
191196
Splash.about()
192197

193198
def do_setscriptsfolder(self, *args):
194-
fss = EasyDialogs.AskFolder(message="Select Scripts Folder",
195-
wanted=macfs.FSSpec)
196-
if fss:
199+
fsr = EasyDialogs.AskFolder(message="Select Scripts Folder",
200+
wanted=File.FSRef)
201+
if fsr:
197202
prefs = self.getprefs()
198-
alis = fss.NewAlias()
203+
alis = fsr.FSNewAliasMinimal()
199204
prefs.scriptsfolder = alis.data
200205
self.scriptsfolder = alis
201206
self.makescriptsmenu()
@@ -246,8 +251,8 @@ def makescriptsmenu(self):
246251
self.scriptsmenu = FrameWork.Menu(self.menubar, "Scripts")
247252
#FrameWork.MenuItem(self.scriptsmenu, "New script", None, self.domenu_new)
248253
#self.scriptsmenu.addseparator()
249-
fss, fss_changed = self.scriptsfolder.Resolve()
250-
self.scriptswalk(fss.as_pathname(), self.scriptsmenu)
254+
fsr, d1 = self.scriptsfolder.FSResolveAlias(None)
255+
self.scriptswalk(fsr.as_pathname(), self.scriptsmenu)
251256

252257
def makeopenwindowsmenu(self):
253258
for i in range(len(self.openwindowsmenu.items)):

Mac/Tools/IDE/Wapplication.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from types import *
99
from Carbon import Menu; MenuToolbox = Menu; del Menu
1010
import macresource
11+
from Carbon import File
1112

1213
if hasattr(Win, "FrontNonFloatingWindow"):
1314
MyFrontWindow = Win.FrontNonFloatingWindow
@@ -273,7 +274,7 @@ def scriptswalk(self, top, menu, done=None):
273274
if done.has_key(top):
274275
return
275276
done[top] = 1
276-
import os, macfs, string
277+
import os, string
277278
try:
278279
names = os.listdir(top)
279280
except os.error:
@@ -285,11 +286,11 @@ def scriptswalk(self, top, menu, done=None):
285286
if name == "CVS":
286287
continue
287288
try:
288-
fss, isdir, isalias = macfs.ResolveAliasFile(name)
289+
fsr, isdir, isalias = File.FSResolveAliasFile(name, 1)
289290
except:
290291
# maybe a broken alias
291292
continue
292-
path = fss.as_pathname()
293+
path = fsr.as_pathname()
293294
if done.has_key(path):
294295
continue
295296
name = string.strip(name)
@@ -301,7 +302,7 @@ def scriptswalk(self, top, menu, done=None):
301302
submenu = FrameWork.SubMenu(menu, name)
302303
self.scriptswalk(path, submenu, done)
303304
else:
304-
creator, type = fss.GetCreatorType()
305+
creator, type = MacOS.GetCreatorAndType(path)
305306
if type == 'TEXT':
306307
if name[-3:] == '.py':
307308
name = name[:-3]

Mac/Tools/IDE/Wquicktime.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from Carbon import Win
44
from Carbon import Qt, QuickTime
55
import W
6-
import macfs
6+
from Carbon import File
77
from Carbon import Evt, Events
88

99
_moviesinitialized = 0
@@ -33,14 +33,9 @@ def set(self, path_or_fss, start = 0):
3333
if self.movie:
3434
#self.GetWindow().InvalWindowRect(self.movie.GetMovieBox())
3535
Qd.PaintRect(self.movie.GetMovieBox())
36-
if type(path_or_fss) == type(''):
37-
path = path_or_fss
38-
fss = macfs.FSSpec(path)
39-
else:
40-
path = path_or_fss.as_pathname()
41-
fss = path_or_fss
36+
path = File.pathname(path)
4237
self.movietitle = os.path.basename(path)
43-
movieResRef = Qt.OpenMovieFile(fss, 1)
38+
movieResRef = Qt.OpenMovieFile(path_or_fss, 1)
4439
self.movie, dummy, dummy = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive)
4540
self.moviebox = self.movie.GetMovieBox()
4641
self.calcmoviebox()

0 commit comments

Comments
 (0)