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.
6 from Carbon
.Dlg
import *
7 from Carbon
.Events
import *
8 from Carbon
.Res
import *
9 from Carbon
import Controls
16 from Carbon
import Res
# For Res.Error
21 from Carbon
import Help
25 # resource IDs in our own resources (dialogs, etc)
37 # The options dialog. There is a correspondence between
38 # the dialog item numbers and the option.
41 # Map dialog item numbers to option names (and the reverse)
61 for i
in range(len(opt_dialog_map
)):
63 opt_dialog_dict
[opt_dialog_map
[i
]] = i
64 # 1 thru 10 are the options
65 # The GUSI creator/type and delay-console
71 OD_KEEPALWAYS_ITEM
= 16
72 OD_KEEPOUTPUT_ITEM
= 17
73 OD_KEEPERROR_ITEM
= 18
74 OD_KEEPNEVER_ITEM
= 19
76 def optinteract(options
):
77 """Let the user interact with the options dialog"""
78 d
= GetNewDialog(OPT_DIALOG_ID
, -1)
79 htext
= d
.GetDialogItemAsControl(OD_CREATOR_ITEM
)
80 SetDialogItemText(htext
, options
['creator'])
81 htext
= d
.GetDialogItemAsControl(OD_TYPE_ITEM
)
82 SetDialogItemText(htext
, options
['type'])
83 d
.SetDialogDefaultItem(OD_OK_ITEM
)
84 d
.SetDialogCancelItem(OD_CANCEL_ITEM
)
86 d
.HideDialogItem(OD_HELP_ITEM
)
88 for name
in opt_dialog_dict
.keys():
89 num
= opt_dialog_dict
[name
]
90 ctl
= d
.GetDialogItemAsControl(num
)
91 ctl
.SetControlValue(options
[name
])
92 ctl
= d
.GetDialogItemAsControl(OD_KEEPALWAYS_ITEM
)
93 ctl
.SetControlValue(options
['keep_console'] == 3)
94 ctl
= d
.GetDialogItemAsControl(OD_KEEPOUTPUT_ITEM
)
95 ctl
.SetControlValue(options
['keep_console'] == 1)
96 ctl
= d
.GetDialogItemAsControl(OD_KEEPERROR_ITEM
)
97 ctl
.SetControlValue(options
['keep_console'] == 2)
98 ctl
= d
.GetDialogItemAsControl(OD_KEEPNEVER_ITEM
)
99 ctl
.SetControlValue(options
['keep_console'] == 0)
100 n
= ModalDialog(None)
102 htext
= d
.GetDialogItemAsControl(OD_CREATOR_ITEM
)
103 ncreator
= GetDialogItemText(htext
)
104 htext
= d
.GetDialogItemAsControl(OD_TYPE_ITEM
)
105 ntype
= GetDialogItemText(htext
)
106 if len(ncreator
) == 4 and len(ntype
) == 4:
107 options
['creator'] = ncreator
108 options
['type'] = ntype
112 elif n
== OD_CANCEL_ITEM
:
114 elif n
in (OD_CREATOR_ITEM
, OD_TYPE_ITEM
):
116 elif n
== OD_KEEPALWAYS_ITEM
:
117 options
['keep_console'] = 3;
118 elif n
== OD_KEEPOUTPUT_ITEM
:
119 options
['keep_console'] = 1;
120 elif n
== OD_KEEPERROR_ITEM
:
121 options
['keep_console'] = 2;
122 elif n
== OD_KEEPNEVER_ITEM
:
123 options
['keep_console'] = 0;
124 elif n
== OD_HELP_ITEM
and Help
:
125 onoff
= Help
.HMGetBalloons()
126 Help
.HMSetBalloons(not onoff
)
127 elif 1 <= n
<= len(opt_dialog_map
):
128 options
[opt_dialog_map
[n
]] = (not options
[opt_dialog_map
[n
]])
131 def interact(options
, title
):
132 """Let the user interact with the dialog"""
134 # Try to go to the "correct" dir for GetDirectory
135 os
.chdir(options
['dir'].as_pathname())
138 d
= GetNewDialog(DIALOG_ID
, -1)
139 htext
= d
.GetDialogItemAsControl(TITLE_ITEM
)
140 SetDialogItemText(htext
, title
)
141 path_ctl
= d
.GetDialogItemAsControl(TEXT_ITEM
)
142 data
= string
.joinfields(options
['path'], '\r')
143 path_ctl
.SetControlData(Controls
.kControlEditTextPart
, Controls
.kControlEditTextTextTag
, data
)
145 d
.SelectDialogItemText(TEXT_ITEM
, 0, 32767)
146 d
.SelectDialogItemText(TEXT_ITEM
, 0, 0)
147 ## d.SetDialogDefaultItem(OK_ITEM)
148 d
.SetDialogCancelItem(CANCEL_ITEM
)
150 d
.HideDialogItem(HELP_ITEM
)
151 d
.GetDialogWindow().ShowWindow()
154 n
= ModalDialog(None)
159 ## if n == REVERT_ITEM:
160 ## return [], pythondir
162 fss
= EasyDialogs
.AskFolder(message
='Select python home folder:',
166 elif n
== HELP_ITEM
and Help
:
167 onoff
= Help
.HMGetBalloons()
168 Help
.HMSetBalloons(not onoff
)
169 if n
== OPTIONS_ITEM
:
171 for k
in options
.keys():
172 noptions
[k
] = options
[k
]
173 noptions
= optinteract(noptions
)
176 data
= path_ctl
.GetControlData(Controls
.kControlEditTextPart
, Controls
.kControlEditTextTextTag
)
177 tmp
= string
.splitfields(data
, '\r')
182 options
['path'] = newpath
186 def edit_preferences():
187 handler
= pythonprefs
.PythonOptions()
188 options
= handler
.load()
189 if options
['noargs']:
190 EasyDialogs
.Message('Warning: system-wide sys.argv processing is off.\nIf you dropped an applet I have not seen it.')
191 result
= interact(options
, 'System-wide preferences')
195 def edit_applet(name
):
196 handler
= pythonprefs
.AppletOptions(name
)
197 result
= interact(handler
.load(), os
.path
.split(name
)[1])
202 macresource
.need('DLOG', DIALOG_ID
, 'EditPythonPrefs.rsrc')
204 MacOS
.SchedParams(1, 0)
205 if len(sys
.argv
) <= 1:
208 for appl
in sys
.argv
[1:]:
212 if __name__
== '__main__':