annotate Mac/scripts/EditPythonPrefs.py @ 27406:caa6df9e0880 legacy-trunk

Use new file dialogs.
author Jack Jansen <jack.jansen@cwi.nl>
date Sun, 26 Jan 2003 21:40:00 +0000
parents f4af27cb2632
children d19bc3b1813c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 """Edit the Python Preferences file."""
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
2 #
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
3 # This program is getting more and more clunky. It should really
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
4 # be rewritten in a modeless way some time soon.
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5
19488
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16342
diff changeset
6 from Carbon.Dlg import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16342
diff changeset
7 from Carbon.Events import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16342
diff changeset
8 from Carbon.Res import *
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16342
diff changeset
9 from Carbon import Controls
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 import string
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 import struct
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 import macfs
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 import MacOS
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14 import os
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 import sys
19488
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16342
diff changeset
16 from Carbon import Res # For Res.Error
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
17 import pythonprefs
19515
546ef318ba5d Use the new macresource module to open the accompanying resource file (if needed).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
18 import macresource
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
19 import EasyDialogs
16342
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
20 try:
19488
42b2f1936254 Import the MacOS toolbox modules from the Carbon package.
Jack Jansen <jack.jansen@cwi.nl>
parents: 16342
diff changeset
21 from Carbon import Help
16342
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
22 except ImportError:
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
23 Help = None
4448
85d38456adf0 Get preference file name from a resource.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4398
diff changeset
24
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 # resource IDs in our own resources (dialogs, etc)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 MESSAGE_ID = 256
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27
4398
ec4c42bea69d Moved resources to 510/511: the numbers above 512 gave problems when
Jack Jansen <jack.jansen@cwi.nl>
parents: 4235
diff changeset
28 DIALOG_ID = 511
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29 TEXT_ITEM = 1
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 OK_ITEM = 2
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 CANCEL_ITEM = 3
3484
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
32 DIR_ITEM = 4
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
33 TITLE_ITEM = 5
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
34 OPTIONS_ITEM = 7
6298
ebd099889721 Implemented balloon help for EditPythonPrefs
Jack Jansen <jack.jansen@cwi.nl>
parents: 6275
diff changeset
35 HELP_ITEM = 9
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
36
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
37 # The options dialog. There is a correspondence between
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
38 # the dialog item numbers and the option.
4398
ec4c42bea69d Moved resources to 510/511: the numbers above 512 gave problems when
Jack Jansen <jack.jansen@cwi.nl>
parents: 4235
diff changeset
39 OPT_DIALOG_ID = 510
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
40
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
41 # Map dialog item numbers to option names (and the reverse)
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
42 opt_dialog_map = [
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
43 None,
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
44 None,
15277
ba3677e1f81b Oops, all the options were off-by-one. Reported by Tom Bridgman.
Jack Jansen <jack.jansen@cwi.nl>
parents: 15211
diff changeset
45 None,
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
46 "inspect",
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
47 "verbose",
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
48 "optimize",
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
49 "unbuffered",
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
50 "debugging",
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
51 "tabwarn",
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
52 "nosite",
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
53 "nonavservice",
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
54 "nointopt",
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
55 "noargs",
6298
ebd099889721 Implemented balloon help for EditPythonPrefs
Jack Jansen <jack.jansen@cwi.nl>
parents: 6275
diff changeset
56 "delayconsole",
19640
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
57 "divisionwarn",
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
58 "unixnewlines",
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
59 ]
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
60 opt_dialog_dict = {}
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
61 for i in range(len(opt_dialog_map)):
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
62 if opt_dialog_map[i]:
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
63 opt_dialog_dict[opt_dialog_map[i]] = i
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
64 # 1 thru 10 are the options
4230
41a52ab263da Allow editing selected bits of the GUSI preferences (creator, type and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3504
diff changeset
65 # The GUSI creator/type and delay-console
19640
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
66 OD_CREATOR_ITEM = 20
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
67 OD_TYPE_ITEM = 21
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
68 OD_OK_ITEM = 1
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
69 OD_CANCEL_ITEM = 2
19640
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
70 OD_HELP_ITEM = 22
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
71 OD_KEEPALWAYS_ITEM = 16
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
72 OD_KEEPOUTPUT_ITEM = 17
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
73 OD_KEEPERROR_ITEM = 18
f4af27cb2632 Added preferences/startup options for division warning
Jack Jansen <jack.jansen@cwi.nl>
parents: 19515
diff changeset
74 OD_KEEPNEVER_ITEM = 19
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
76 def optinteract(options):
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
77 """Let the user interact with the options dialog"""
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
78 d = GetNewDialog(OPT_DIALOG_ID, -1)
11624
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
79 htext = d.GetDialogItemAsControl(OD_CREATOR_ITEM)
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
80 SetDialogItemText(htext, options['creator'])
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
81 htext = d.GetDialogItemAsControl(OD_TYPE_ITEM)
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
82 SetDialogItemText(htext, options['type'])
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
83 d.SetDialogDefaultItem(OD_OK_ITEM)
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
84 d.SetDialogCancelItem(OD_CANCEL_ITEM)
16342
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
85 if not Help:
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
86 d.HideDialogItem(OD_HELP_ITEM)
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
87 while 1:
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
88 for name in opt_dialog_dict.keys():
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
89 num = opt_dialog_dict[name]
11624
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
90 ctl = d.GetDialogItemAsControl(num)
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
91 ctl.SetControlValue(options[name])
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
92 ctl = d.GetDialogItemAsControl(OD_KEEPALWAYS_ITEM)
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
93 ctl.SetControlValue(options['keep_console'] == 3)
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
94 ctl = d.GetDialogItemAsControl(OD_KEEPOUTPUT_ITEM)
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
95 ctl.SetControlValue(options['keep_console'] == 1)
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
96 ctl = d.GetDialogItemAsControl(OD_KEEPERROR_ITEM)
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
97 ctl.SetControlValue(options['keep_console'] == 2)
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
98 ctl = d.GetDialogItemAsControl(OD_KEEPNEVER_ITEM)
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
99 ctl.SetControlValue(options['keep_console'] == 0)
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
100 n = ModalDialog(None)
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
101 if n == OD_OK_ITEM:
11624
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
102 htext = d.GetDialogItemAsControl(OD_CREATOR_ITEM)
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
103 ncreator = GetDialogItemText(htext)
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
104 htext = d.GetDialogItemAsControl(OD_TYPE_ITEM)
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
105 ntype = GetDialogItemText(htext)
4230
41a52ab263da Allow editing selected bits of the GUSI preferences (creator, type and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3504
diff changeset
106 if len(ncreator) == 4 and len(ntype) == 4:
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
107 options['creator'] = ncreator
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
108 options['type'] = ntype
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
109 return options
4230
41a52ab263da Allow editing selected bits of the GUSI preferences (creator, type and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3504
diff changeset
110 else:
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
111 MacOS.SysBeep()
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
112 elif n == OD_CANCEL_ITEM:
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
113 return
4230
41a52ab263da Allow editing selected bits of the GUSI preferences (creator, type and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3504
diff changeset
114 elif n in (OD_CREATOR_ITEM, OD_TYPE_ITEM):
41a52ab263da Allow editing selected bits of the GUSI preferences (creator, type and
Jack Jansen <jack.jansen@cwi.nl>
parents: 3504
diff changeset
115 pass
14773
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
116 elif n == OD_KEEPALWAYS_ITEM:
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
117 options['keep_console'] = 3;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
118 elif n == OD_KEEPOUTPUT_ITEM:
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
119 options['keep_console'] = 1;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
120 elif n == OD_KEEPERROR_ITEM:
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
121 options['keep_console'] = 2;
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
122 elif n == OD_KEEPNEVER_ITEM:
c5ec0b11f8c9 Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
Jack Jansen <jack.jansen@cwi.nl>
parents: 12972
diff changeset
123 options['keep_console'] = 0;
16342
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
124 elif n == OD_HELP_ITEM and Help:
6298
ebd099889721 Implemented balloon help for EditPythonPrefs
Jack Jansen <jack.jansen@cwi.nl>
parents: 6275
diff changeset
125 onoff = Help.HMGetBalloons()
ebd099889721 Implemented balloon help for EditPythonPrefs
Jack Jansen <jack.jansen@cwi.nl>
parents: 6275
diff changeset
126 Help.HMSetBalloons(not onoff)
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
127 elif 1 <= n <= len(opt_dialog_map):
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
128 options[opt_dialog_map[n]] = (not options[opt_dialog_map[n]])
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
129
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
130
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
131 def interact(options, title):
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132 """Let the user interact with the dialog"""
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133 try:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 # Try to go to the "correct" dir for GetDirectory
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
135 os.chdir(options['dir'].as_pathname())
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 except os.error:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
137 pass
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138 d = GetNewDialog(DIALOG_ID, -1)
11624
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
139 htext = d.GetDialogItemAsControl(TITLE_ITEM)
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
140 SetDialogItemText(htext, title)
11652
99c9b126690d Get/set sys.path initializer in new appearance way.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11624
diff changeset
141 path_ctl = d.GetDialogItemAsControl(TEXT_ITEM)
11624
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
142 data = string.joinfields(options['path'], '\r')
11652
99c9b126690d Get/set sys.path initializer in new appearance way.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11624
diff changeset
143 path_ctl.SetControlData(Controls.kControlEditTextPart, Controls.kControlEditTextTextTag, data)
11624
3c213e372b22 Partially converted to Appearance, the dialog still has the old ugly layout and
Jack Jansen <jack.jansen@cwi.nl>
parents: 11517
diff changeset
144
4550
f1244036ebab Fixed to allow sys.path initializer to be longer than 255 chars.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4448
diff changeset
145 d.SelectDialogItemText(TEXT_ITEM, 0, 32767)
f1244036ebab Fixed to allow sys.path initializer to be longer than 255 chars.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4448
diff changeset
146 d.SelectDialogItemText(TEXT_ITEM, 0, 0)
3484
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
147 ## d.SetDialogDefaultItem(OK_ITEM)
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
148 d.SetDialogCancelItem(CANCEL_ITEM)
16342
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
149 if not Help:
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
150 d.HideDialogItem(HELP_ITEM)
4550
f1244036ebab Fixed to allow sys.path initializer to be longer than 255 chars.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4448
diff changeset
151 d.GetDialogWindow().ShowWindow()
f1244036ebab Fixed to allow sys.path initializer to be longer than 255 chars.
Jack Jansen <jack.jansen@cwi.nl>
parents: 4448
diff changeset
152 d.DrawDialog()
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 while 1:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154 n = ModalDialog(None)
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 if n == OK_ITEM:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156 break
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 if n == CANCEL_ITEM:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158 return None
3484
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
159 ## if n == REVERT_ITEM:
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
160 ## return [], pythondir
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161 if n == DIR_ITEM:
27406
caa6df9e0880 Use new file dialogs.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19640
diff changeset
162 fss = EasyDialogs.AskFolder(message='Select python home folder:',
caa6df9e0880 Use new file dialogs.
Jack Jansen <jack.jansen@cwi.nl>
parents: 19640
diff changeset
163 wanted=macfs.FSSpec)
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 if ok:
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
165 options['dir'] = fss
16342
05a913ff97a6 Make balloon code dependent on existence of Help module
Jack Jansen <jack.jansen@cwi.nl>
parents: 15277
diff changeset
166 elif n == HELP_ITEM and Help:
6298
ebd099889721 Implemented balloon help for EditPythonPrefs
Jack Jansen <jack.jansen@cwi.nl>
parents: 6275
diff changeset
167 onoff = Help.HMGetBalloons()
ebd099889721 Implemented balloon help for EditPythonPrefs
Jack Jansen <jack.jansen@cwi.nl>
parents: 6275
diff changeset
168 Help.HMSetBalloons(not onoff)
3504
e8d501c88a3e Added region arg to update calls. And binhex files rebinhexed.
Jack Jansen <jack.jansen@cwi.nl>
parents: 3484
diff changeset
169 if n == OPTIONS_ITEM:
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
170 noptions = options
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
171 for k in options.keys():
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
172 noptions[k] = options[k]
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
173 noptions = optinteract(noptions)
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
174 if noptions:
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
175 options = noptions
11652
99c9b126690d Get/set sys.path initializer in new appearance way.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11624
diff changeset
176 data = path_ctl.GetControlData(Controls.kControlEditTextPart, Controls.kControlEditTextTextTag)
99c9b126690d Get/set sys.path initializer in new appearance way.
Jack Jansen <jack.jansen@cwi.nl>
parents: 11624
diff changeset
177 tmp = string.splitfields(data, '\r')
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
178 newpath = []
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 for i in tmp:
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180 if i:
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
181 newpath.append(i)
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
182 options['path'] = newpath
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
183 return options
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184
3484
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
185
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
186 def edit_preferences():
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
187 handler = pythonprefs.PythonOptions()
11517
71281ff8c6a2 Give a warning if system-wide sys.argv processing is off (because then we
Jack Jansen <jack.jansen@cwi.nl>
parents: 6298
diff changeset
188 options = handler.load()
71281ff8c6a2 Give a warning if system-wide sys.argv processing is off (because then we
Jack Jansen <jack.jansen@cwi.nl>
parents: 6298
diff changeset
189 if options['noargs']:
71281ff8c6a2 Give a warning if system-wide sys.argv processing is off (because then we
Jack Jansen <jack.jansen@cwi.nl>
parents: 6298
diff changeset
190 EasyDialogs.Message('Warning: system-wide sys.argv processing is off.\nIf you dropped an applet I have not seen it.')
71281ff8c6a2 Give a warning if system-wide sys.argv processing is off (because then we
Jack Jansen <jack.jansen@cwi.nl>
parents: 6298
diff changeset
191 result = interact(options, 'System-wide preferences')
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
192 if result:
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
193 handler.save(result)
3484
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
194
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
195 def edit_applet(name):
6275
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
196 handler = pythonprefs.AppletOptions(name)
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
197 result = interact(handler.load(), os.path.split(name)[1])
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
198 if result:
f9fbde75c536 Major overhaul: this is now little more than a user interface, the
Jack Jansen <jack.jansen@cwi.nl>
parents: 6174
diff changeset
199 handler.save(result)
3484
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
200
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
201 def main():
19515
546ef318ba5d Use the new macresource module to open the accompanying resource file (if needed).
Jack Jansen <jack.jansen@cwi.nl>
parents: 19488
diff changeset
202 macresource.need('DLOG', DIALOG_ID, 'EditPythonPrefs.rsrc')
3484
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
203
15211
e4c9b805f39f Added some of the new Numeric modules (which weren't rebuilt).
Jack Jansen <jack.jansen@cwi.nl>
parents: 14773
diff changeset
204 MacOS.SchedParams(1, 0)
3484
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
205 if len(sys.argv) <= 1:
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
206 edit_preferences()
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
207 else:
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
208 for appl in sys.argv[1:]:
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
209 edit_applet(appl)
ce27e0328462 Added support for editing override preferences in applets
Jack Jansen <jack.jansen@cwi.nl>
parents: 3462
diff changeset
210
2873
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
212 if __name__ == '__main__':
315760ba0041 A new home for scripts/applets
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
213 main()