1 """Edit the Python Preferences file."""
3 # This program is getting more and more clunky. It should really
4 # be rewritten in a modeless way some time soon.
16 import Res
# For Res.Error
24 # resource IDs in our own resources (dialogs, etc)
36 # The options dialog. There is a correspondence between
37 # the dialog item numbers and the option.
40 # Map dialog item numbers to option names (and the reverse)
58 for i
in range(len(opt_dialog_map
)):
60 opt_dialog_dict
[opt_dialog_map
[i
]] = i
61 # 1 thru 10 are the options
62 # The GUSI creator/type and delay-console
68 OD_KEEPALWAYS_ITEM
= 14
69 OD_KEEPOUTPUT_ITEM
= 15
70 OD_KEEPERROR_ITEM
= 16
71 OD_KEEPNEVER_ITEM
= 17
73 def optinteract(options
):
74 """Let the user interact with the options dialog"""
75 d
= GetNewDialog(OPT_DIALOG_ID
, -1)
76 htext
= d
.GetDialogItemAsControl(OD_CREATOR_ITEM
)
77 SetDialogItemText(htext
, options
['creator'])
78 htext
= d
.GetDialogItemAsControl(OD_TYPE_ITEM
)
79 SetDialogItemText(htext
, options
['type'])
80 d
.SetDialogDefaultItem(OD_OK_ITEM
)
81 d
.SetDialogCancelItem(OD_CANCEL_ITEM
)
83 d
.HideDialogItem(OD_HELP_ITEM
)
85 for name
in opt_dialog_dict
.keys():
86 num
= opt_dialog_dict
[name
]
87 ctl
= d
.GetDialogItemAsControl(num
)
88 ctl
.SetControlValue(options
[name
])
89 ctl
= d
.GetDialogItemAsControl(OD_KEEPALWAYS_ITEM
)
90 ctl
.SetControlValue(options
['keep_console'] == 3)
91 ctl
= d
.GetDialogItemAsControl(OD_KEEPOUTPUT_ITEM
)
92 ctl
.SetControlValue(options
['keep_console'] == 1)
93 ctl
= d
.GetDialogItemAsControl(OD_KEEPERROR_ITEM
)
94 ctl
.SetControlValue(options
['keep_console'] == 2)
95 ctl
= d
.GetDialogItemAsControl(OD_KEEPNEVER_ITEM
)
96 ctl
.SetControlValue(options
['keep_console'] == 0)
99 htext
= d
.GetDialogItemAsControl(OD_CREATOR_ITEM
)
100 ncreator
= GetDialogItemText(htext
)
101 htext
= d
.GetDialogItemAsControl(OD_TYPE_ITEM
)
102 ntype
= GetDialogItemText(htext
)
103 if len(ncreator
) == 4 and len(ntype
) == 4:
104 options
['creator'] = ncreator
105 options
['type'] = ntype
109 elif n
== OD_CANCEL_ITEM
:
111 elif n
in (OD_CREATOR_ITEM
, OD_TYPE_ITEM
):
113 elif n
== OD_KEEPALWAYS_ITEM
:
114 options
['keep_console'] = 3;
115 elif n
== OD_KEEPOUTPUT_ITEM
:
116 options
['keep_console'] = 1;
117 elif n
== OD_KEEPERROR_ITEM
:
118 options
['keep_console'] = 2;
119 elif n
== OD_KEEPNEVER_ITEM
:
120 options
['keep_console'] = 0;
121 elif n
== OD_HELP_ITEM
and Help
:
122 onoff
= Help
.HMGetBalloons()
123 Help
.HMSetBalloons(not onoff
)
124 elif 1 <= n
<= len(opt_dialog_map
):
125 options
[opt_dialog_map
[n
]] = (not options
[opt_dialog_map
[n
]])
128 def interact(options
, title
):
129 """Let the user interact with the dialog"""
131 # Try to go to the "correct" dir for GetDirectory
132 os
.chdir(options
['dir'].as_pathname())
135 d
= GetNewDialog(DIALOG_ID
, -1)
136 htext
= d
.GetDialogItemAsControl(TITLE_ITEM
)
137 SetDialogItemText(htext
, title
)
138 path_ctl
= d
.GetDialogItemAsControl(TEXT_ITEM
)
139 data
= string
.joinfields(options
['path'], '\r')
140 path_ctl
.SetControlData(Controls
.kControlEditTextPart
, Controls
.kControlEditTextTextTag
, data
)
142 d
.SelectDialogItemText(TEXT_ITEM
, 0, 32767)
143 d
.SelectDialogItemText(TEXT_ITEM
, 0, 0)
144 ## d.SetDialogDefaultItem(OK_ITEM)
145 d
.SetDialogCancelItem(CANCEL_ITEM
)
147 d
.HideDialogItem(HELP_ITEM
)
148 d
.GetDialogWindow().ShowWindow()
151 n
= ModalDialog(None)
156 ## if n == REVERT_ITEM:
157 ## return [], pythondir
159 fss
, ok
= macfs
.GetDirectory('Select python home folder:')
162 elif n
== HELP_ITEM
and Help
:
163 onoff
= Help
.HMGetBalloons()
164 Help
.HMSetBalloons(not onoff
)
165 if n
== OPTIONS_ITEM
:
167 for k
in options
.keys():
168 noptions
[k
] = options
[k
]
169 noptions
= optinteract(noptions
)
172 data
= path_ctl
.GetControlData(Controls
.kControlEditTextPart
, Controls
.kControlEditTextTextTag
)
173 tmp
= string
.splitfields(data
, '\r')
178 options
['path'] = newpath
182 def edit_preferences():
183 handler
= pythonprefs
.PythonOptions()
184 options
= handler
.load()
185 if options
['noargs']:
186 EasyDialogs
.Message('Warning: system-wide sys.argv processing is off.\nIf you dropped an applet I have not seen it.')
187 result
= interact(options
, 'System-wide preferences')
191 def edit_applet(name
):
192 handler
= pythonprefs
.AppletOptions(name
)
193 result
= interact(handler
.load(), os
.path
.split(name
)[1])
199 h
= FSpOpenResFile('EditPythonPrefs.rsrc', 1)
201 pass # Assume we already have acces to our own resource
203 MacOS
.SchedParams(1, 0)
204 if len(sys
.argv
) <= 1:
207 for appl
in sys
.argv
[1:]:
211 if __name__
== '__main__':