From db0baced2309b358d706f5f027a2ecd2e581e609 Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Thu, 4 Apr 1996 15:38:44 +0000 Subject: Added support for editing override preferences in applets --- Mac/scripts/EditPythonPrefs.py | 157 +++++++++++++++++++++++++++++------ Mac/scripts/EditPythonPrefs.rsrc.hqx | 98 +++++++++++----------- 2 files changed, 181 insertions(+), 74 deletions(-) diff --git a/Mac/scripts/EditPythonPrefs.py b/Mac/scripts/EditPythonPrefs.py index f070d82..0fd6bed 100644 --- a/Mac/scripts/EditPythonPrefs.py +++ b/Mac/scripts/EditPythonPrefs.py @@ -18,13 +18,20 @@ DIALOG_ID = 512 TEXT_ITEM = 1 OK_ITEM = 2 CANCEL_ITEM = 3 -REVERT_ITEM = 4 -DIR_ITEM = 5 +DIR_ITEM = 4 +TITLE_ITEM = 5 # Resource IDs in the preferences file PATH_STRINGS_ID = 128 DIRECTORY_ID = 128 +OPTIONS_ID = 128 +# Override IDs (in the applet) +OVERRIDE_PATH_STRINGS_ID = 129 +OVERRIDE_DIRECTORY_ID = 129 +OVERRIDE_OPTIONS_ID = 129 + +READ = 1 WRITE = 2 smAllScripts = -3 kOnSystemDisk = 0x8000 @@ -61,7 +68,7 @@ def message(str = "Hello, world!", id = MESSAGE_ID): n = ModalDialog(None) if n == 1: break -def interact(list, pythondir): +def interact(list, pythondir, title): """Let the user interact with the dialog""" opythondir = pythondir try: @@ -70,16 +77,20 @@ def interact(list, pythondir): except os.error: pass d = GetNewDialog(DIALOG_ID, -1) - tp, h, rect = d.GetDialogItem(1) + tp, h, rect = d.GetDialogItem(TITLE_ITEM) + SetDialogItemText(h, title) + tp, h, rect = d.GetDialogItem(TEXT_ITEM) SetDialogItemText(h, string.joinfields(list, '\r')) +## d.SetDialogDefaultItem(OK_ITEM) + d.SetDialogCancelItem(CANCEL_ITEM) while 1: n = ModalDialog(None) if n == OK_ITEM: break if n == CANCEL_ITEM: return None - if n == REVERT_ITEM: - return [], pythondir +## if n == REVERT_ITEM: +## return [], pythondir if n == DIR_ITEM: fss, ok = macfs.GetDirectory('Select python home folder:') if ok: @@ -91,42 +102,62 @@ def interact(list, pythondir): rv.append(i) return rv, pythondir -def main(): +def getprefpath(id): + # Load the path and directory resources try: - h = OpenResFile('EditPythonPrefs.rsrc') - except Res.Error: - pass # Assume we already have acces to our own resource + 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 +def openpreffile(rw): # Find the preferences folder and our prefs file, create if needed. vrefnum, dirid = macfs.FindFolder(kOnSystemDisk, 'pref', 0) preff_fss = macfs.FSSpec((vrefnum, dirid, 'Python Preferences')) try: - preff_handle = FSpOpenResFile(preff_fss, WRITE) + preff_handle = FSpOpenResFile(preff_fss, rw) except Res.Error: # Create it message('No preferences file, creating one...') FSpCreateResFile(preff_fss, 'Pyth', 'pref', smAllScripts) - preff_handle = FSpOpenResFile(preff_fss, WRITE) - - # Load the path and directory resources + preff_handle = FSpOpenResFile(preff_fss, rw) + return preff_handle + +def openapplet(name): + fss = macfs.FSSpec(name) try: - sr = GetResource('STR#', PATH_STRINGS_ID) - except (MacOS.Error, Res.Error): - message('Cannot find any sys.path resource! (Old python?)') + app_handle = FSpOpenResFile(fss, WRITE) + except Res.Error: + message('File does not have a resource fork.') sys.exit(0) - d = sr.data - l = restolist(d) + return app_handle + - try: - dr = GetResource('alis', DIRECTORY_ID) - fss, fss_changed = macfs.RawAlias(dr.data).Resolve() - except (MacOS.Error, Res.Error): - dr = None +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: fss = macfs.FSSpec(os.getcwd()) fss_changed = 1 # Let the user play away - result = interact(l, fss) + result = interact(l, fss, 'System-wide preferences') # See what we have to update, and how if result == None: @@ -158,6 +189,82 @@ def main(): sr.AddResource('STR#', PATH_STRINGS_ID, '') CloseResFile(preff_handle) + +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: + notfound = notfound + ' and ' + 'directory' + else: + notfound = 'directory' + fss, dummy, dummy2 = getprefdir(DIRECTORY_ID) + if fss == None: + fss = macfs.FSSpec(os.getcwd()) + fss_changed = 1 + + dummy = dummy2 = None # Discard them. + + if notfound: + message('Warning: initial %s taken from system-wide defaults'%notfound) + # Let the user play away + result = interact(l, fss, name) + + # See what we have to update, and how + if result == None: + sys.exit(0) + + pathlist, nfss = result + if nfss != fss: + fss_changed = 1 + + if fss_changed or pathlist != l: + 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, '') + + 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) + if __name__ == '__main__': print # Stupid, to init toolboxes... diff --git a/Mac/scripts/EditPythonPrefs.rsrc.hqx b/M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