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
|
1997-09-08 10:19:42 -03:00
|
|
|
import pythonprefs
|
|
|
|
import EasyDialogs
|
1997-09-09 10:58:19 -03:00
|
|
|
import Help
|
1996-10-22 12:33:02 -03:00
|
|
|
|
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
|
1997-09-09 10:58:19 -03:00
|
|
|
HELP_ITEM = 9
|
1996-04-10 11:52:18 -03:00
|
|
|
|
|
|
|
# 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
|
1997-09-08 10:19:42 -03:00
|
|
|
|
|
|
|
# Map dialog item numbers to option names (and the reverse)
|
|
|
|
opt_dialog_map = [
|
|
|
|
None,
|
|
|
|
"inspect",
|
|
|
|
"verbose",
|
|
|
|
"optimize",
|
|
|
|
"unbuffered",
|
|
|
|
"debugging",
|
|
|
|
"keepopen",
|
|
|
|
"keeperror",
|
|
|
|
"nointopt",
|
|
|
|
"noargs",
|
1997-09-09 10:58:19 -03:00
|
|
|
"delayconsole",
|
|
|
|
None, None, None, None, None, None, None, None, # 11-18 are different
|
|
|
|
"oldexc",
|
|
|
|
"nosite"]
|
1997-09-08 10:19:42 -03:00
|
|
|
opt_dialog_dict = {}
|
|
|
|
for i in range(len(opt_dialog_map)):
|
|
|
|
if opt_dialog_map[i]:
|
|
|
|
opt_dialog_dict[opt_dialog_map[i]] = i
|
|
|
|
# 1 thru 10 are the options
|
1996-09-06 19:25:34 -03:00
|
|
|
# The GUSI creator/type and delay-console
|
1997-09-08 10:19:42 -03:00
|
|
|
OD_CREATOR_ITEM = 11
|
|
|
|
OD_TYPE_ITEM = 12
|
1996-09-06 19:25:34 -03:00
|
|
|
OD_OK_ITEM = 13
|
|
|
|
OD_CANCEL_ITEM = 14
|
1997-09-09 10:58:19 -03:00
|
|
|
OD_HELP_ITEM = 22
|
1995-07-29 10:48:41 -03:00
|
|
|
|
1997-09-08 10:19:42 -03:00
|
|
|
def optinteract(options):
|
1996-04-10 11:52:18 -03:00
|
|
|
"""Let the user interact with the options dialog"""
|
|
|
|
d = GetNewDialog(OPT_DIALOG_ID, -1)
|
1996-09-06 19:25:34 -03:00
|
|
|
tp, h, rect = d.GetDialogItem(OD_CREATOR_ITEM)
|
1997-09-08 10:19:42 -03:00
|
|
|
SetDialogItemText(h, options['creator'])
|
1996-09-06 19:25:34 -03:00
|
|
|
tp, h, rect = d.GetDialogItem(OD_TYPE_ITEM)
|
1997-09-08 10:19:42 -03:00
|
|
|
SetDialogItemText(h, options['type'])
|
1996-04-10 11:52:18 -03:00
|
|
|
d.SetDialogDefaultItem(OD_OK_ITEM)
|
|
|
|
d.SetDialogCancelItem(OD_CANCEL_ITEM)
|
1997-09-08 10:19:42 -03:00
|
|
|
|
1996-04-10 11:52:18 -03:00
|
|
|
while 1:
|
1997-09-08 10:19:42 -03:00
|
|
|
for name in opt_dialog_dict.keys():
|
|
|
|
num = opt_dialog_dict[name]
|
|
|
|
tp, h, rect = d.GetDialogItem(num)
|
|
|
|
h.as_Control().SetControlValue(options[name])
|
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:
|
1997-09-08 10:19:42 -03:00
|
|
|
options['creator'] = ncreator
|
|
|
|
options['type'] = ntype
|
|
|
|
return options
|
1996-09-06 19:25:34 -03:00
|
|
|
else:
|
1997-09-08 10:19:42 -03:00
|
|
|
MacOS.SysBeep()
|
1996-04-10 11:52:18 -03:00
|
|
|
elif n == OD_CANCEL_ITEM:
|
1997-09-08 10:19:42 -03:00
|
|
|
return
|
1996-09-06 19:25:34 -03:00
|
|
|
elif n in (OD_CREATOR_ITEM, OD_TYPE_ITEM):
|
|
|
|
pass
|
1997-09-09 10:58:19 -03:00
|
|
|
elif n == OD_HELP_ITEM:
|
|
|
|
onoff = Help.HMGetBalloons()
|
|
|
|
Help.HMSetBalloons(not onoff)
|
1997-09-08 10:19:42 -03:00
|
|
|
elif 1 <= n <= len(opt_dialog_map):
|
|
|
|
options[opt_dialog_map[n]] = (not options[opt_dialog_map[n]])
|
1996-04-10 11:52:18 -03:00
|
|
|
|
|
|
|
|
1997-09-08 10:19:42 -03:00
|
|
|
def interact(options, title):
|
1995-07-29 10:48:41 -03:00
|
|
|
"""Let the user interact with the dialog"""
|
|
|
|
try:
|
|
|
|
# Try to go to the "correct" dir for GetDirectory
|
1997-09-08 10:19:42 -03:00
|
|
|
os.chdir(options['dir'].as_pathname())
|
1995-07-29 10:48:41 -03:00
|
|
|
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'))
|
1997-09-08 10:19:42 -03:00
|
|
|
h.data = string.joinfields(options['path'], '\r')
|
1996-11-20 10:55:26 -04:00
|
|
|
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:
|
1997-09-08 10:19:42 -03:00
|
|
|
options['dir'] = fss
|
1997-09-09 10:58:19 -03:00
|
|
|
elif n == HELP_ITEM:
|
|
|
|
onoff = Help.HMGetBalloons()
|
|
|
|
Help.HMSetBalloons(not onoff)
|
1996-04-10 11:52:18 -03:00
|
|
|
if n == OPTIONS_ITEM:
|
1997-09-08 10:19:42 -03:00
|
|
|
noptions = options
|
|
|
|
for k in options.keys():
|
|
|
|
noptions[k] = options[k]
|
|
|
|
noptions = optinteract(noptions)
|
|
|
|
if noptions:
|
|
|
|
options = noptions
|
1996-11-20 10:55:26 -04:00
|
|
|
tmp = string.splitfields(h.data, '\r')
|
1997-09-08 10:19:42 -03:00
|
|
|
newpath = []
|
1995-07-29 10:48:41 -03:00
|
|
|
for i in tmp:
|
|
|
|
if i:
|
1997-09-08 10:19:42 -03:00
|
|
|
newpath.append(i)
|
|
|
|
options['path'] = newpath
|
|
|
|
return options
|
1996-09-06 19:25:34 -03:00
|
|
|
|
1995-07-29 10:48:41 -03:00
|
|
|
|
1996-04-04 11:38:44 -04:00
|
|
|
def edit_preferences():
|
1997-09-08 10:19:42 -03:00
|
|
|
handler = pythonprefs.PythonOptions()
|
|
|
|
result = interact(handler.load(), 'System-wide preferences')
|
|
|
|
if result:
|
|
|
|
handler.save(result)
|
1996-04-04 11:38:44 -04:00
|
|
|
|
|
|
|
def edit_applet(name):
|
1997-09-08 10:19:42 -03:00
|
|
|
handler = pythonprefs.AppletOptions(name)
|
|
|
|
result = interact(handler.load(), os.path.split(name)[1])
|
|
|
|
if result:
|
|
|
|
handler.save(result)
|
1996-04-04 11:38:44 -04:00
|
|
|
|
|
|
|
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()
|