1995-07-29 10:48:41 -03:00
|
|
|
"""Edit the Python Preferences file."""
|
1996-04-10 11:52:18 -03:00
|
|
|
#
|
|
|
|
# This program is getting more and more clunky. It should really
|
|
|
|
# be rewritten in a modeless way some time soon.
|
1995-07-29 10:48:41 -03:00
|
|
|
|
|
|
|
from Dlg import *
|
|
|
|
from Events import *
|
|
|
|
from Res import *
|
|
|
|
import string
|
|
|
|
import struct
|
|
|
|
import macfs
|
|
|
|
import MacOS
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import Res # For Res.Error
|
|
|
|
|
1996-10-22 12:33:02 -03:00
|
|
|
# Resource in the Python resource chain
|
|
|
|
PREFNAME_NAME="PythonPreferenceFileName"
|
|
|
|
|
1995-07-29 10:48:41 -03:00
|
|
|
# resource IDs in our own resources (dialogs, etc)
|
|
|
|
MESSAGE_ID = 256
|
|
|
|
|
1996-10-11 08:30:26 -03:00
|
|
|
DIALOG_ID = 511
|
1995-07-29 10:48:41 -03:00
|
|
|
TEXT_ITEM = 1
|
|
|
|
OK_ITEM = 2
|
|
|
|
CANCEL_ITEM = 3
|
1996-04-04 11:38:44 -04:00
|
|
|
DIR_ITEM = 4
|
|
|
|
TITLE_ITEM = 5
|
1996-04-10 11:52:18 -03:00
|
|
|
OPTIONS_ITEM = 7
|
|
|
|
|
|
|
|
# The options dialog. There is a correspondence between
|
|
|
|
# the dialog item numbers and the option.
|
1996-10-11 08:30:26 -03:00
|
|
|
OPT_DIALOG_ID = 510
|
1996-09-06 19:25:34 -03:00
|
|
|
# 1 thru 9 are the options
|
|
|
|
# The GUSI creator/type and delay-console
|
|
|
|
OD_CREATOR_ITEM = 10
|
|
|
|
OD_TYPE_ITEM = 11
|
|
|
|
OD_DELAYCONSOLE_ITEM = 12
|
|
|
|
OD_OK_ITEM = 13
|
|
|
|
OD_CANCEL_ITEM = 14
|
1995-07-29 10:48:41 -03:00
|
|
|
|
|
|
|
# Resource IDs in the preferences file
|
|
|
|
PATH_STRINGS_ID = 128
|
|
|
|
DIRECTORY_ID = 128
|
1996-04-04 11:38:44 -04:00
|
|
|
OPTIONS_ID = 128
|
1996-09-06 19:25:34 -03:00
|
|
|
GUSI_ID = 10240
|
1995-07-29 10:48:41 -03:00
|
|
|
|
1996-04-04 11:38:44 -04:00
|
|
|
# Override IDs (in the applet)
|
|
|
|
OVERRIDE_PATH_STRINGS_ID = 129
|
|
|
|
OVERRIDE_DIRECTORY_ID = 129
|
|
|
|
OVERRIDE_OPTIONS_ID = 129
|
1996-09-07 14:01:47 -03:00
|
|
|
OVERRIDE_GUSI_ID = 10241
|
1996-09-06 19:25:34 -03:00
|
|
|
|
|
|
|
# Things we know about the GUSI resource. Note the code knows these too.
|
|
|
|
GUSIPOS_TYPE=0
|
|
|
|
GUSIPOS_CREATOR=4
|
|
|
|
GUSIPOS_SKIP=8
|
|
|
|
GUSIPOS_FLAGS=9
|
1996-10-22 12:33:02 -03:00
|
|
|
GUSIPOS_VERSION=10
|
|
|
|
GUSIVERSION='0181'
|
|
|
|
GUSIFLAGS_DELAY=0x20 # Mask
|
1996-04-04 11:38:44 -04:00
|
|
|
|
|
|
|
READ = 1
|
1995-07-29 10:48:41 -03:00
|
|
|
WRITE = 2
|
|
|
|
smAllScripts = -3
|
|
|
|
kOnSystemDisk = 0x8000
|
|
|
|
|
|
|
|
def restolist(data):
|
|
|
|
"""Convert STR# resource data to a list of strings"""
|
|
|
|
if not data:
|
|
|
|
return []
|
|
|
|
num, = struct.unpack('h', data[:2])
|
|
|
|
data = data[2:]
|
|
|
|
rv = []
|
|
|
|
for i in range(num):
|
|
|
|
strlen = ord(data[0])
|
|
|
|
if strlen < 0: strlen = strlen + 256
|
|
|
|
str = data[1:strlen+1]
|
|
|
|
data = data[strlen+1:]
|
|
|
|
rv.append(str)
|
|
|
|
return rv
|
|
|
|
|
|
|
|
def listtores(list):
|
|
|
|
"""Convert a list of strings to STR# resource data"""
|
|
|
|
rv = struct.pack('h', len(list))
|
|
|
|
for str in list:
|
|
|
|
rv = rv + chr(len(str)) + str
|
|
|
|
return rv
|
|
|
|
|
|
|
|
def message(str = "Hello, world!", id = MESSAGE_ID):
|
|
|
|
"""Show a simple alert with a text message"""
|
|
|
|
d = GetNewDialog(id, -1)
|
1996-04-10 11:52:18 -03:00
|
|
|
d.SetDialogDefaultItem(1)
|
1995-07-29 10:48:41 -03:00
|
|
|
tp, h, rect = d.GetDialogItem(2)
|
|
|
|
SetDialogItemText(h, str)
|
|
|
|
while 1:
|
|
|
|
n = ModalDialog(None)
|
|
|
|
if n == 1: break
|
|
|
|
|
1996-09-06 19:25:34 -03:00
|
|
|
def optinteract((options, creator, type, delaycons)):
|
1996-04-10 11:52:18 -03:00
|
|
|
"""Let the user interact with the options dialog"""
|
1996-09-06 19:25:34 -03:00
|
|
|
old_options = (options[:], creator, type, delaycons)
|
1996-04-10 11:52:18 -03:00
|
|
|
d = GetNewDialog(OPT_DIALOG_ID, -1)
|
1996-09-06 19:25:34 -03:00
|
|
|
tp, h, rect = d.GetDialogItem(OD_CREATOR_ITEM)
|
|
|
|
SetDialogItemText(h, creator)
|
|
|
|
tp, h, rect = d.GetDialogItem(OD_TYPE_ITEM)
|
|
|
|
SetDialogItemText(h, type)
|
1996-04-10 11:52:18 -03:00
|
|
|
d.SetDialogDefaultItem(OD_OK_ITEM)
|
|
|
|
d.SetDialogCancelItem(OD_CANCEL_ITEM)
|
|
|
|
while 1:
|
|
|
|
for i in range(len(options)):
|
|
|
|
tp, h, rect = d.GetDialogItem(i+1)
|
|
|
|
h.as_Control().SetControlValue(options[i])
|
1996-09-06 19:25:34 -03:00
|
|
|
tp, h, rect = d.GetDialogItem(OD_DELAYCONSOLE_ITEM)
|
|
|
|
h.as_Control().SetControlValue(delaycons)
|
1996-04-10 11:52:18 -03:00
|
|
|
n = ModalDialog(None)
|
|
|
|
if n == OD_OK_ITEM:
|
1996-09-06 19:25:34 -03:00
|
|
|
tp, h, rect = d.GetDialogItem(OD_CREATOR_ITEM)
|
|
|
|
ncreator = GetDialogItemText(h)
|
|
|
|
tp, h, rect = d.GetDialogItem(OD_TYPE_ITEM)
|
|
|
|
ntype = GetDialogItemText(h)
|
|
|
|
if len(ncreator) == 4 and len(ntype) == 4:
|
|
|
|
return options, ncreator, ntype, delaycons
|
|
|
|
else:
|
|
|
|
sys.stderr.write('\007')
|
1996-04-10 11:52:18 -03:00
|
|
|
elif n == OD_CANCEL_ITEM:
|
|
|
|
return old_options
|
1996-09-06 19:25:34 -03:00
|
|
|
elif n in (OD_CREATOR_ITEM, OD_TYPE_ITEM):
|
|
|
|
pass
|
|
|
|
elif n == OD_DELAYCONSOLE_ITEM:
|
|
|
|
delaycons = (not delaycons)
|
1996-04-10 11:52:18 -03:00
|
|
|
elif 1 <= n <= len(options):
|
|
|
|
options[n-1] = (not options[n-1])
|
|
|
|
|
|
|
|
|
|
|
|
def interact(list, pythondir, options, title):
|
1995-07-29 10:48:41 -03:00
|
|
|
"""Let the user interact with the dialog"""
|
|
|
|
opythondir = pythondir
|
|
|
|
try:
|
|
|
|
# Try to go to the "correct" dir for GetDirectory
|
|
|
|
os.chdir(pythondir.as_pathname())
|
|
|
|
except os.error:
|
|
|
|
pass
|
|
|
|
d = GetNewDialog(DIALOG_ID, -1)
|
1996-04-04 11:38:44 -04:00
|
|
|
tp, h, rect = d.GetDialogItem(TITLE_ITEM)
|
|
|
|
SetDialogItemText(h, title)
|
|
|
|
tp, h, rect = d.GetDialogItem(TEXT_ITEM)
|
1996-11-20 10:55:26 -04:00
|
|
|
## SetDialogItemText(h, string.joinfields(list, '\r'))
|
|
|
|
h.data = string.joinfields(list, '\r')
|
|
|
|
d.SelectDialogItemText(TEXT_ITEM, 0, 32767)
|
|
|
|
d.SelectDialogItemText(TEXT_ITEM, 0, 0)
|
1996-04-04 11:38:44 -04:00
|
|
|
## d.SetDialogDefaultItem(OK_ITEM)
|
|
|
|
d.SetDialogCancelItem(CANCEL_ITEM)
|
1996-11-20 10:55:26 -04:00
|
|
|
d.GetDialogWindow().ShowWindow()
|
|
|
|
d.DrawDialog()
|
1995-07-29 10:48:41 -03:00
|
|
|
while 1:
|
|
|
|
n = ModalDialog(None)
|
|
|
|
if n == OK_ITEM:
|
|
|
|
break
|
|
|
|
if n == CANCEL_ITEM:
|
|
|
|
return None
|
1996-04-04 11:38:44 -04:00
|
|
|
## if n == REVERT_ITEM:
|
|
|
|
## return [], pythondir
|
1995-07-29 10:48:41 -03:00
|
|
|
if n == DIR_ITEM:
|
1995-08-14 09:21:12 -03:00
|
|
|
fss, ok = macfs.GetDirectory('Select python home folder:')
|
1995-07-29 10:48:41 -03:00
|
|
|
if ok:
|
|
|
|
pythondir = fss
|
1996-04-10 11:52:18 -03:00
|
|
|
if n == OPTIONS_ITEM:
|
|
|
|
options = optinteract(options)
|
1996-11-20 10:55:26 -04:00
|
|
|
tmp = string.splitfields(h.data, '\r')
|
1995-07-29 10:48:41 -03:00
|
|
|
rv = []
|
|
|
|
for i in tmp:
|
|
|
|
if i:
|
|
|
|
rv.append(i)
|
1996-04-10 11:52:18 -03:00
|
|
|
return rv, pythondir, options
|
1995-07-29 10:48:41 -03:00
|
|
|
|
1996-04-04 11:38:44 -04:00
|
|
|
def getprefpath(id):
|
|
|
|
# Load the path and directory resources
|
1995-07-29 10:48:41 -03:00
|
|
|
try:
|
1996-04-04 11:38:44 -04:00
|
|
|
sr = GetResource('STR#', id)
|
|
|
|
except (MacOS.Error, Res.Error):
|
|
|
|
return None, None
|
|
|
|
d = sr.data
|
|
|
|
l = restolist(d)
|
|
|
|
return l, sr
|
|
|
|
|
|
|
|
def getprefdir(id):
|
|
|
|
try:
|
|
|
|
dr = GetResource('alis', id)
|
|
|
|
fss, fss_changed = macfs.RawAlias(dr.data).Resolve()
|
|
|
|
except (MacOS.Error, Res.Error):
|
|
|
|
return None, None, 1
|
|
|
|
return fss, dr, fss_changed
|
1996-04-10 11:52:18 -03:00
|
|
|
|
|
|
|
def getoptions(id):
|
|
|
|
try:
|
|
|
|
opr = GetResource('Popt', id)
|
|
|
|
except (MacOS.Error, Res.Error):
|
1996-09-07 14:01:47 -03:00
|
|
|
return [0]*9, None
|
|
|
|
options = map(lambda x: ord(x), opr.data)
|
|
|
|
while len(options) < 9:
|
|
|
|
options = options + [0]
|
|
|
|
return options, opr
|
1995-07-29 10:48:41 -03:00
|
|
|
|
1996-09-06 19:25:34 -03:00
|
|
|
def getgusioptions(id):
|
|
|
|
try:
|
|
|
|
opr = GetResource('GU\267I', id)
|
|
|
|
except (MacOS.Error, Res.Error):
|
|
|
|
return '????', '????', 0, None
|
|
|
|
data = opr.data
|
|
|
|
type = data[GUSIPOS_TYPE:GUSIPOS_TYPE+4]
|
|
|
|
creator = data[GUSIPOS_CREATOR:GUSIPOS_CREATOR+4]
|
|
|
|
flags = ord(data[GUSIPOS_FLAGS])
|
1996-10-22 12:33:02 -03:00
|
|
|
version = data[GUSIPOS_VERSION:GUSIPOS_VERSION+4]
|
|
|
|
if version <> GUSIVERSION:
|
|
|
|
message('GU\267I resource version "%s", fixing to "%s"'%(version, GUSIVERSION))
|
|
|
|
flags = 0
|
1996-09-06 19:25:34 -03:00
|
|
|
delay = (not not (flags & GUSIFLAGS_DELAY))
|
|
|
|
return creator, type, delay, opr
|
|
|
|
|
|
|
|
def setgusioptions(opr, creator, type, delay):
|
|
|
|
data = opr.data
|
|
|
|
flags = ord(data[GUSIPOS_FLAGS])
|
1996-10-22 12:33:02 -03:00
|
|
|
version = data[GUSIPOS_VERSION:GUSIPOS_VERSION+4]
|
|
|
|
if version <> GUSIVERSION:
|
|
|
|
flags = 0x88
|
|
|
|
version = GUSIVERSION
|
1996-09-06 19:25:34 -03:00
|
|
|
if delay:
|
|
|
|
flags = flags | GUSIFLAGS_DELAY
|
|
|
|
else:
|
|
|
|
flags = flags & ~GUSIFLAGS_DELAY
|
1996-10-22 12:33:02 -03:00
|
|
|
data = type + creator + data[GUSIPOS_SKIP] + chr(flags) + GUSIVERSION + data[GUSIPOS_VERSION+4:]
|
1996-09-06 19:25:34 -03:00
|
|
|
return data
|
|
|
|
|
1996-04-04 11:38:44 -04:00
|
|
|
def openpreffile(rw):
|
1995-07-29 10:48:41 -03:00
|
|
|
# Find the preferences folder and our prefs file, create if needed.
|
|
|
|
vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0)
|
1996-10-22 12:33:02 -03:00
|
|
|
try:
|
|
|
|
pnhandle = GetNamedResource('STR ', PREFNAME_NAME)
|
|
|
|
except Res.Error:
|
|
|
|
message("No %s resource (old Python?)"%PREFNAME_NAME)
|
|
|
|
sys.exit(1)
|
|
|
|
prefname = pnhandle.data[1:]
|
|
|
|
preff_fss = macfs.FSSpec((vrefnum, dirid, prefname))
|
1995-07-29 10:48:41 -03:00
|
|
|
try:
|
1996-04-04 11:38:44 -04:00
|
|
|
preff_handle = FSpOpenResFile(preff_fss, rw)
|
1995-07-29 10:48:41 -03:00
|
|
|
except Res.Error:
|
|
|
|
# Create it
|
|
|
|
message('No preferences file, creating one...')
|
1996-02-21 11:36:26 -04:00
|
|
|
FSpCreateResFile(preff_fss, 'Pyth', 'pref', smAllScripts)
|
1996-04-04 11:38:44 -04:00
|
|
|
preff_handle = FSpOpenResFile(preff_fss, rw)
|
|
|
|
return preff_handle
|
|
|
|
|
|
|
|
def openapplet(name):
|
|
|
|
fss = macfs.FSSpec(name)
|
1995-07-29 10:48:41 -03:00
|
|
|
try:
|
1996-04-04 11:38:44 -04:00
|
|
|
app_handle = FSpOpenResFile(fss, WRITE)
|
|
|
|
except Res.Error:
|
|
|
|
message('File does not have a resource fork.')
|
1995-07-29 10:48:41 -03:00
|
|
|
sys.exit(0)
|
1996-04-04 11:38:44 -04:00
|
|
|
return app_handle
|
|
|
|
|
1995-07-29 10:48:41 -03:00
|
|
|
|
1996-04-04 11:38:44 -04:00
|
|
|
def edit_preferences():
|
|
|
|
preff_handle = openpreffile(WRITE)
|
|
|
|
|
|
|
|
l, sr = getprefpath(PATH_STRINGS_ID)
|
|
|
|
if l == None:
|
|
|
|
message('Cannot find any sys.path resource! (Old python?)')
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
fss, dr, fss_changed = getprefdir(DIRECTORY_ID)
|
|
|
|
if fss == None:
|
1995-07-29 10:48:41 -03:00
|
|
|
fss = macfs.FSSpec(os.getcwd())
|
|
|
|
fss_changed = 1
|
1996-04-10 11:52:18 -03:00
|
|
|
|
|
|
|
options, opr = getoptions(OPTIONS_ID)
|
|
|
|
saved_options = options[:]
|
1995-07-29 10:48:41 -03:00
|
|
|
|
1996-09-06 19:25:34 -03:00
|
|
|
creator, type, delaycons, gusi_opr = getgusioptions(GUSI_ID)
|
|
|
|
saved_gusi_options = creator, type, delaycons
|
|
|
|
|
1995-07-29 10:48:41 -03:00
|
|
|
# Let the user play away
|
1996-09-06 19:25:34 -03:00
|
|
|
result = interact(l, fss, (options, creator, type, delaycons),
|
|
|
|
'System-wide preferences')
|
1995-07-29 10:48:41 -03:00
|
|
|
|
|
|
|
# See what we have to update, and how
|
|
|
|
if result == None:
|
|
|
|
sys.exit(0)
|
|
|
|
|
1996-09-06 19:25:34 -03:00
|
|
|
pathlist, nfss, (options, creator, type, delaycons) = result
|
1995-07-29 10:48:41 -03:00
|
|
|
if nfss != fss:
|
|
|
|
fss_changed = 1
|
|
|
|
|
1996-04-10 11:52:18 -03:00
|
|
|
if fss_changed:
|
|
|
|
alias = nfss.NewAlias()
|
|
|
|
if dr:
|
|
|
|
dr.data = alias.data
|
|
|
|
dr.ChangedResource()
|
|
|
|
else:
|
|
|
|
dr = Resource(alias.data)
|
|
|
|
dr.AddResource('alis', DIRECTORY_ID, '')
|
|
|
|
|
|
|
|
if pathlist != l:
|
|
|
|
if pathlist == []:
|
|
|
|
if sr.HomeResFile() == preff_handle:
|
|
|
|
sr.RemoveResource()
|
|
|
|
elif sr.HomeResFile() == preff_handle:
|
|
|
|
sr.data = listtores(pathlist)
|
|
|
|
sr.ChangedResource()
|
|
|
|
else:
|
|
|
|
sr = Resource(listtores(pathlist))
|
|
|
|
sr.AddResource('STR#', PATH_STRINGS_ID, '')
|
|
|
|
|
|
|
|
if options != saved_options:
|
|
|
|
newdata = reduce(lambda x, y: x+chr(y), options, '')
|
|
|
|
if opr and opr.HomeResFile() == preff_handle:
|
|
|
|
opr.data = newdata
|
|
|
|
opr.ChangedResource()
|
|
|
|
else:
|
|
|
|
opr = Resource(newdata)
|
|
|
|
opr.AddResource('Popt', OPTIONS_ID, '')
|
1996-09-06 19:25:34 -03:00
|
|
|
|
|
|
|
if (creator, type, delaycons) != saved_gusi_options:
|
|
|
|
newdata = setgusioptions(gusi_opr, creator, type, delaycons)
|
|
|
|
if gusi_opr.HomeResFile() == preff_handle:
|
|
|
|
gusi_opr.data = newdata
|
|
|
|
gusi_opr.ChangedResource()
|
|
|
|
else:
|
1996-09-07 14:01:47 -03:00
|
|
|
ngusi_opr = Resource(newdata)
|
1996-09-06 19:25:34 -03:00
|
|
|
ngusi_opr.AddResource('GU\267I', GUSI_ID, '')
|
1995-07-29 10:48:41 -03:00
|
|
|
|
|
|
|
CloseResFile(preff_handle)
|
1996-04-04 11:38:44 -04:00
|
|
|
|
|
|
|
def edit_applet(name):
|
|
|
|
pref_handle = openpreffile(READ)
|
|
|
|
app_handle = openapplet(name)
|
|
|
|
|
|
|
|
notfound = ''
|
|
|
|
l, sr = getprefpath(OVERRIDE_PATH_STRINGS_ID)
|
|
|
|
if l == None:
|
|
|
|
notfound = 'path'
|
|
|
|
|
|
|
|
l, dummy = getprefpath(PATH_STRINGS_ID)
|
|
|
|
if l == None:
|
|
|
|
message('Cannot find any sys.path resource! (Old python?)')
|
|
|
|
sys.exit(0)
|
|
|
|
|
|
|
|
fss, dr, fss_changed = getprefdir(OVERRIDE_DIRECTORY_ID)
|
|
|
|
if fss == None:
|
|
|
|
if notfound:
|
1996-04-10 11:52:18 -03:00
|
|
|
notfound = notfound + ', directory'
|
1996-04-04 11:38:44 -04:00
|
|
|
else:
|
|
|
|
notfound = 'directory'
|
|
|
|
fss, dummy, dummy2 = getprefdir(DIRECTORY_ID)
|
|
|
|
if fss == None:
|
|
|
|
fss = macfs.FSSpec(os.getcwd())
|
|
|
|
fss_changed = 1
|
1996-04-10 11:52:18 -03:00
|
|
|
|
|
|
|
options, opr = getoptions(OVERRIDE_OPTIONS_ID)
|
|
|
|
if not opr:
|
|
|
|
if notfound:
|
|
|
|
notfound = notfound + ', options'
|
|
|
|
else:
|
|
|
|
notfound = 'options'
|
|
|
|
options, dummy = getoptions(OPTIONS_ID)
|
|
|
|
saved_options = options[:]
|
1996-04-04 11:38:44 -04:00
|
|
|
|
1996-09-06 19:25:34 -03:00
|
|
|
creator, type, delaycons, gusi_opr = getgusioptions(OVERRIDE_GUSI_ID)
|
1996-09-07 14:01:47 -03:00
|
|
|
if not gusi_opr:
|
1996-09-06 19:25:34 -03:00
|
|
|
if notfound:
|
|
|
|
notfound = notfound + ', GUSI options'
|
|
|
|
else:
|
|
|
|
notfound = 'GUSI options'
|
1996-09-07 14:01:47 -03:00
|
|
|
creator, type, delaycons, gusi_opr = getgusioptions(GUSI_ID)
|
1996-09-06 19:25:34 -03:00
|
|
|
saved_gusi_options = creator, type, delaycons
|
|
|
|
|
1996-04-04 11:38:44 -04:00
|
|
|
dummy = dummy2 = None # Discard them.
|
|
|
|
|
|
|
|
if notfound:
|
|
|
|
message('Warning: initial %s taken from system-wide defaults'%notfound)
|
|
|
|
# Let the user play away
|
1996-10-11 08:30:26 -03:00
|
|
|
print 'DBG interaction'
|
1996-09-06 19:25:34 -03:00
|
|
|
result = interact(l, fss, (options, creator, type, delaycons), name)
|
1996-04-04 11:38:44 -04:00
|
|
|
|
|
|
|
# See what we have to update, and how
|
|
|
|
if result == None:
|
|
|
|
sys.exit(0)
|
|
|
|
|
1996-09-07 14:01:47 -03:00
|
|
|
pathlist, nfss, (options, creator, type, delaycons) = result
|
1996-04-04 11:38:44 -04:00
|
|
|
if nfss != fss:
|
|
|
|
fss_changed = 1
|
|
|
|
|
1996-04-10 11:52:18 -03:00
|
|
|
if fss_changed:
|
|
|
|
alias = nfss.NewAlias()
|
|
|
|
if dr:
|
|
|
|
dr.data = alias.data
|
|
|
|
dr.ChangedResource()
|
|
|
|
else:
|
|
|
|
dr = Resource(alias.data)
|
|
|
|
dr.AddResource('alis', OVERRIDE_DIRECTORY_ID, '')
|
|
|
|
|
|
|
|
if pathlist != l:
|
|
|
|
if pathlist == []:
|
|
|
|
if sr.HomeResFile() == app_handle:
|
|
|
|
sr.RemoveResource()
|
|
|
|
elif sr and sr.HomeResFile() == app_handle:
|
|
|
|
sr.data = listtores(pathlist)
|
|
|
|
sr.ChangedResource()
|
|
|
|
else:
|
|
|
|
sr = Resource(listtores(pathlist))
|
|
|
|
sr.AddResource('STR#', OVERRIDE_PATH_STRINGS_ID, '')
|
|
|
|
|
|
|
|
if options != saved_options:
|
|
|
|
newdata = reduce(lambda x, y: x+chr(y), options, '')
|
|
|
|
if opr and opr.HomeResFile() == app_handle:
|
|
|
|
opr.data = newdata
|
|
|
|
opr.ChangedResource()
|
|
|
|
else:
|
|
|
|
opr = Resource(newdata)
|
|
|
|
opr.AddResource('Popt', OVERRIDE_OPTIONS_ID, '')
|
1996-09-06 19:25:34 -03:00
|
|
|
|
|
|
|
if (creator, type, delaycons) != saved_gusi_options:
|
|
|
|
newdata = setgusioptions(gusi_opr, creator, type, delaycons)
|
1996-09-07 14:01:47 -03:00
|
|
|
id, type, name = gusi_opr.GetResInfo()
|
|
|
|
if gusi_opr.HomeResFile() == app_handle and id == OVERRIDE_GUSI_ID:
|
1996-09-06 19:25:34 -03:00
|
|
|
gusi_opr.data = newdata
|
|
|
|
gusi_opr.ChangedResource()
|
|
|
|
else:
|
1996-09-07 14:01:47 -03:00
|
|
|
ngusi_opr = Resource(newdata)
|
|
|
|
ngusi_opr.AddResource('GU\267I', OVERRIDE_GUSI_ID, '')
|
1996-09-06 19:25:34 -03:00
|
|
|
|
1996-04-04 11:38:44 -04:00
|
|
|
CloseResFile(app_handle)
|
|
|
|
|
|
|
|
def main():
|
|
|
|
try:
|
|
|
|
h = OpenResFile('EditPythonPrefs.rsrc')
|
|
|
|
except Res.Error:
|
|
|
|
pass # Assume we already have acces to our own resource
|
|
|
|
|
|
|
|
if len(sys.argv) <= 1:
|
|
|
|
edit_preferences()
|
|
|
|
else:
|
|
|
|
for appl in sys.argv[1:]:
|
|
|
|
edit_applet(appl)
|
|
|
|
|
1995-07-29 10:48:41 -03:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|