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 *
|
1999-12-23 10:34:07 -04:00
|
|
|
import Controls
|
1995-07-29 10:48:41 -03:00
|
|
|
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
|
2001-01-29 10:59:33 -04:00
|
|
|
try:
|
|
|
|
import Help
|
|
|
|
except ImportError:
|
|
|
|
Help = None
|
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 = [
|
2000-10-19 18:50:54 -03:00
|
|
|
None,
|
2000-09-22 18:50:11 -03:00
|
|
|
None,
|
1997-09-08 10:19:42 -03:00
|
|
|
None,
|
|
|
|
"inspect",
|
|
|
|
"verbose",
|
|
|
|
"optimize",
|
|
|
|
"unbuffered",
|
|
|
|
"debugging",
|
2000-09-22 18:50:11 -03:00
|
|
|
"tabwarn",
|
|
|
|
"nosite",
|
|
|
|
"nonavservice",
|
1997-09-08 10:19:42 -03:00
|
|
|
"nointopt",
|
|
|
|
"noargs",
|
1997-09-09 10:58:19 -03:00
|
|
|
"delayconsole",
|
2000-09-22 18:50:11 -03:00
|
|
|
]
|
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
|
2000-09-22 18:50:11 -03:00
|
|
|
OD_CREATOR_ITEM = 18
|
|
|
|
OD_TYPE_ITEM = 19
|
|
|
|
OD_OK_ITEM = 1
|
|
|
|
OD_CANCEL_ITEM = 2
|
|
|
|
OD_HELP_ITEM = 20
|
|
|
|
OD_KEEPALWAYS_ITEM = 14
|
|
|
|
OD_KEEPOUTPUT_ITEM = 15
|
|
|
|
OD_KEEPERROR_ITEM = 16
|
|
|
|
OD_KEEPNEVER_ITEM = 17
|
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)
|
1999-12-23 10:34:07 -04:00
|
|
|
htext = d.GetDialogItemAsControl(OD_CREATOR_ITEM)
|
|
|
|
SetDialogItemText(htext, options['creator'])
|
|
|
|
htext = d.GetDialogItemAsControl(OD_TYPE_ITEM)
|
|
|
|
SetDialogItemText(htext, options['type'])
|
1996-04-10 11:52:18 -03:00
|
|
|
d.SetDialogDefaultItem(OD_OK_ITEM)
|
|
|
|
d.SetDialogCancelItem(OD_CANCEL_ITEM)
|
2001-01-29 10:59:33 -04:00
|
|
|
if not Help:
|
|
|
|
d.HideDialogItem(OD_HELP_ITEM)
|
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]
|
1999-12-23 10:34:07 -04:00
|
|
|
ctl = d.GetDialogItemAsControl(num)
|
|
|
|
ctl.SetControlValue(options[name])
|
2000-09-22 18:50:11 -03:00
|
|
|
ctl = d.GetDialogItemAsControl(OD_KEEPALWAYS_ITEM)
|
|
|
|
ctl.SetControlValue(options['keep_console'] == 3)
|
|
|
|
ctl = d.GetDialogItemAsControl(OD_KEEPOUTPUT_ITEM)
|
|
|
|
ctl.SetControlValue(options['keep_console'] == 1)
|
|
|
|
ctl = d.GetDialogItemAsControl(OD_KEEPERROR_ITEM)
|
|
|
|
ctl.SetControlValue(options['keep_console'] == 2)
|
|
|
|
ctl = d.GetDialogItemAsControl(OD_KEEPNEVER_ITEM)
|
|
|
|
ctl.SetControlValue(options['keep_console'] == 0)
|
1996-04-10 11:52:18 -03:00
|
|
|
n = ModalDialog(None)
|
|
|
|
if n == OD_OK_ITEM:
|
1999-12-23 10:34:07 -04:00
|
|
|
htext = d.GetDialogItemAsControl(OD_CREATOR_ITEM)
|
|
|
|
ncreator = GetDialogItemText(htext)
|
|
|
|
htext = d.GetDialogItemAsControl(OD_TYPE_ITEM)
|
|
|
|
ntype = GetDialogItemText(htext)
|
1996-09-06 19:25:34 -03:00
|
|
|
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
|
2000-09-22 18:50:11 -03:00
|
|
|
elif n == OD_KEEPALWAYS_ITEM:
|
|
|
|
options['keep_console'] = 3;
|
|
|
|
elif n == OD_KEEPOUTPUT_ITEM:
|
|
|
|
options['keep_console'] = 1;
|
|
|
|
elif n == OD_KEEPERROR_ITEM:
|
|
|
|
options['keep_console'] = 2;
|
|
|
|
elif n == OD_KEEPNEVER_ITEM:
|
|
|
|
options['keep_console'] = 0;
|
2001-01-29 10:59:33 -04:00
|
|
|
elif n == OD_HELP_ITEM and Help:
|
1997-09-09 10:58:19 -03:00
|
|
|
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)
|
1999-12-23 10:34:07 -04:00
|
|
|
htext = d.GetDialogItemAsControl(TITLE_ITEM)
|
|
|
|
SetDialogItemText(htext, title)
|
2000-01-13 12:22:12 -04:00
|
|
|
path_ctl = d.GetDialogItemAsControl(TEXT_ITEM)
|
1999-12-23 10:34:07 -04:00
|
|
|
data = string.joinfields(options['path'], '\r')
|
2000-01-13 12:22:12 -04:00
|
|
|
path_ctl.SetControlData(Controls.kControlEditTextPart, Controls.kControlEditTextTextTag, data)
|
1999-12-23 10:34:07 -04:00
|
|
|
|
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)
|
2001-01-29 10:59:33 -04:00
|
|
|
if not Help:
|
|
|
|
d.HideDialogItem(HELP_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
|
2001-01-29 10:59:33 -04:00
|
|
|
elif n == HELP_ITEM and Help:
|
1997-09-09 10:58:19 -03:00
|
|
|
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
|
2000-01-13 12:22:12 -04:00
|
|
|
data = path_ctl.GetControlData(Controls.kControlEditTextPart, Controls.kControlEditTextTextTag)
|
|
|
|
tmp = string.splitfields(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()
|
1999-12-02 18:52:12 -04:00
|
|
|
options = handler.load()
|
|
|
|
if options['noargs']:
|
|
|
|
EasyDialogs.Message('Warning: system-wide sys.argv processing is off.\nIf you dropped an applet I have not seen it.')
|
|
|
|
result = interact(options, 'System-wide preferences')
|
1997-09-08 10:19:42 -03:00
|
|
|
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:
|
2000-06-20 18:59:25 -03:00
|
|
|
h = FSpOpenResFile('EditPythonPrefs.rsrc', 1)
|
1996-04-04 11:38:44 -04:00
|
|
|
except Res.Error:
|
|
|
|
pass # Assume we already have acces to our own resource
|
|
|
|
|
2000-10-13 20:34:06 -03:00
|
|
|
MacOS.SchedParams(1, 0)
|
1996-04-04 11:38:44 -04:00
|
|
|
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()
|