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
21 # resource IDs in our own resources (dialogs, etc)
33 # The options dialog. There is a correspondence between
34 # the dialog item numbers and the option.
37 # Map dialog item numbers to option names (and the reverse)
50 None, None, None, None, None, None, None, None, # 11-18 are different
54 for i
in range(len(opt_dialog_map
)):
56 opt_dialog_dict
[opt_dialog_map
[i
]] = i
57 # 1 thru 10 are the options
58 # The GUSI creator/type and delay-console
65 def optinteract(options
):
66 """Let the user interact with the options dialog"""
67 d
= GetNewDialog(OPT_DIALOG_ID
, -1)
68 htext
= d
.GetDialogItemAsControl(OD_CREATOR_ITEM
)
69 SetDialogItemText(htext
, options
['creator'])
70 htext
= d
.GetDialogItemAsControl(OD_TYPE_ITEM
)
71 SetDialogItemText(htext
, options
['type'])
72 d
.SetDialogDefaultItem(OD_OK_ITEM
)
73 d
.SetDialogCancelItem(OD_CANCEL_ITEM
)
76 for name
in opt_dialog_dict
.keys():
77 num
= opt_dialog_dict
[name
]
78 ctl
= d
.GetDialogItemAsControl(num
)
79 ctl
.SetControlValue(options
[name
])
82 htext
= d
.GetDialogItemAsControl(OD_CREATOR_ITEM
)
83 ncreator
= GetDialogItemText(htext
)
84 htext
= d
.GetDialogItemAsControl(OD_TYPE_ITEM
)
85 ntype
= GetDialogItemText(htext
)
86 if len(ncreator
) == 4 and len(ntype
) == 4:
87 options
['creator'] = ncreator
88 options
['type'] = ntype
92 elif n
== OD_CANCEL_ITEM
:
94 elif n
in (OD_CREATOR_ITEM
, OD_TYPE_ITEM
):
96 elif n
== OD_HELP_ITEM
:
97 onoff
= Help
.HMGetBalloons()
98 Help
.HMSetBalloons(not onoff
)
99 elif 1 <= n
<= len(opt_dialog_map
):
100 options
[opt_dialog_map
[n
]] = (not options
[opt_dialog_map
[n
]])
103 def interact(options
, title
):
104 """Let the user interact with the dialog"""
106 # Try to go to the "correct" dir for GetDirectory
107 os
.chdir(options
['dir'].as_pathname())
110 d
= GetNewDialog(DIALOG_ID
, -1)
111 htext
= d
.GetDialogItemAsControl(TITLE_ITEM
)
112 SetDialogItemText(htext
, title
)
113 path_ctl
= d
.GetDialogItemAsControl(TEXT_ITEM
)
114 data
= string
.joinfields(options
['path'], '\r')
115 path_ctl
.SetControlData(Controls
.kControlEditTextPart
, Controls
.kControlEditTextTextTag
, data
)
117 d
.SelectDialogItemText(TEXT_ITEM
, 0, 32767)
118 d
.SelectDialogItemText(TEXT_ITEM
, 0, 0)
119 ## d.SetDialogDefaultItem(OK_ITEM)
120 d
.SetDialogCancelItem(CANCEL_ITEM
)
121 d
.GetDialogWindow().ShowWindow()
124 n
= ModalDialog(None)
129 ## if n == REVERT_ITEM:
130 ## return [], pythondir
132 fss
, ok
= macfs
.GetDirectory('Select python home folder:')
136 onoff
= Help
.HMGetBalloons()
137 Help
.HMSetBalloons(not onoff
)
138 if n
== OPTIONS_ITEM
:
140 for k
in options
.keys():
141 noptions
[k
] = options
[k
]
142 noptions
= optinteract(noptions
)
145 data
= path_ctl
.GetControlData(Controls
.kControlEditTextPart
, Controls
.kControlEditTextTextTag
)
146 tmp
= string
.splitfields(data
, '\r')
151 options
['path'] = newpath
155 def edit_preferences():
156 handler
= pythonprefs
.PythonOptions()
157 options
= handler
.load()
158 if options
['noargs']:
159 EasyDialogs
.Message('Warning: system-wide sys.argv processing is off.\nIf you dropped an applet I have not seen it.')
160 result
= interact(options
, 'System-wide preferences')
164 def edit_applet(name
):
165 handler
= pythonprefs
.AppletOptions(name
)
166 result
= interact(handler
.load(), os
.path
.split(name
)[1])
172 h
= OpenResFile('EditPythonPrefs.rsrc')
174 pass # Assume we already have acces to our own resource
176 if len(sys
.argv
) <= 1:
179 for appl
in sys
.argv
[1:]:
183 if __name__
== '__main__':