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.
15 import Res
# For Res.Error
20 # resource IDs in our own resources (dialogs, etc)
32 # The options dialog. There is a correspondence between
33 # the dialog item numbers and the option.
36 # Map dialog item numbers to option names (and the reverse)
49 None, None, None, None, None, None, None, None, # 11-18 are different
53 for i
in range(len(opt_dialog_map
)):
55 opt_dialog_dict
[opt_dialog_map
[i
]] = i
56 # 1 thru 10 are the options
57 # The GUSI creator/type and delay-console
64 def optinteract(options
):
65 """Let the user interact with the options dialog"""
66 d
= GetNewDialog(OPT_DIALOG_ID
, -1)
67 tp
, h
, rect
= d
.GetDialogItem(OD_CREATOR_ITEM
)
68 SetDialogItemText(h
, options
['creator'])
69 tp
, h
, rect
= d
.GetDialogItem(OD_TYPE_ITEM
)
70 SetDialogItemText(h
, options
['type'])
71 d
.SetDialogDefaultItem(OD_OK_ITEM
)
72 d
.SetDialogCancelItem(OD_CANCEL_ITEM
)
75 for name
in opt_dialog_dict
.keys():
76 num
= opt_dialog_dict
[name
]
77 tp
, h
, rect
= d
.GetDialogItem(num
)
78 h
.as_Control().SetControlValue(options
[name
])
81 tp
, h
, rect
= d
.GetDialogItem(OD_CREATOR_ITEM
)
82 ncreator
= GetDialogItemText(h
)
83 tp
, h
, rect
= d
.GetDialogItem(OD_TYPE_ITEM
)
84 ntype
= GetDialogItemText(h
)
85 if len(ncreator
) == 4 and len(ntype
) == 4:
86 options
['creator'] = ncreator
87 options
['type'] = ntype
91 elif n
== OD_CANCEL_ITEM
:
93 elif n
in (OD_CREATOR_ITEM
, OD_TYPE_ITEM
):
95 elif n
== OD_HELP_ITEM
:
96 onoff
= Help
.HMGetBalloons()
97 Help
.HMSetBalloons(not onoff
)
98 elif 1 <= n
<= len(opt_dialog_map
):
99 options
[opt_dialog_map
[n
]] = (not options
[opt_dialog_map
[n
]])
102 def interact(options
, title
):
103 """Let the user interact with the dialog"""
105 # Try to go to the "correct" dir for GetDirectory
106 os
.chdir(options
['dir'].as_pathname())
109 d
= GetNewDialog(DIALOG_ID
, -1)
110 tp
, h
, rect
= d
.GetDialogItem(TITLE_ITEM
)
111 SetDialogItemText(h
, title
)
112 tp
, h
, rect
= d
.GetDialogItem(TEXT_ITEM
)
113 ## SetDialogItemText(h, string.joinfields(list, '\r'))
114 h
.data
= string
.joinfields(options
['path'], '\r')
115 d
.SelectDialogItemText(TEXT_ITEM
, 0, 32767)
116 d
.SelectDialogItemText(TEXT_ITEM
, 0, 0)
117 ## d.SetDialogDefaultItem(OK_ITEM)
118 d
.SetDialogCancelItem(CANCEL_ITEM
)
119 d
.GetDialogWindow().ShowWindow()
122 n
= ModalDialog(None)
127 ## if n == REVERT_ITEM:
128 ## return [], pythondir
130 fss
, ok
= macfs
.GetDirectory('Select python home folder:')
134 onoff
= Help
.HMGetBalloons()
135 Help
.HMSetBalloons(not onoff
)
136 if n
== OPTIONS_ITEM
:
138 for k
in options
.keys():
139 noptions
[k
] = options
[k
]
140 noptions
= optinteract(noptions
)
143 tmp
= string
.splitfields(h
.data
, '\r')
148 options
['path'] = newpath
152 def edit_preferences():
153 handler
= pythonprefs
.PythonOptions()
154 result
= interact(handler
.load(), 'System-wide preferences')
158 def edit_applet(name
):
159 handler
= pythonprefs
.AppletOptions(name
)
160 result
= interact(handler
.load(), os
.path
.split(name
)[1])
166 h
= OpenResFile('EditPythonPrefs.rsrc')
168 pass # Assume we already have acces to our own resource
170 if len(sys
.argv
) <= 1:
173 for appl
in sys
.argv
[1:]:
177 if __name__
== '__main__':