2828# The options dialog. There is a correspondence between
2929# the dialog item numbers and the option.
3030OPT_DIALOG_ID = 513
31- # 1 thru 7 are the options
32- OD_OK_ITEM = 8
33- OD_CANCEL_ITEM = 9
31+ # 1 thru 9 are the options
32+ # The GUSI creator/type and delay-console
33+ OD_CREATOR_ITEM = 10
34+ OD_TYPE_ITEM = 11
35+ OD_DELAYCONSOLE_ITEM = 12
36+ OD_OK_ITEM = 13
37+ OD_CANCEL_ITEM = 14
3438
3539# Resource IDs in the preferences file
3640PATH_STRINGS_ID = 128
3741DIRECTORY_ID = 128
3842OPTIONS_ID = 128
43+ GUSI_ID = 10240
3944
4045# Override IDs (in the applet)
4146OVERRIDE_PATH_STRINGS_ID = 129
4247OVERRIDE_DIRECTORY_ID = 129
4348OVERRIDE_OPTIONS_ID = 129
49+ OVERRIDE_GUSI_ID = 10240
50+
51+ # Things we know about the GUSI resource. Note the code knows these too.
52+ GUSIPOS_TYPE = 0
53+ GUSIPOS_CREATOR = 4
54+ GUSIPOS_SKIP = 8
55+ GUSIPOS_FLAGS = 9
56+ GUSIFLAGS_DELAY = 0x04 # Mask
4457
4558READ = 1
4659WRITE = 2
@@ -80,21 +93,38 @@ def message(str = "Hello, world!", id = MESSAGE_ID):
8093 n = ModalDialog (None )
8194 if n == 1 : break
8295
83- def optinteract (options ):
96+ def optinteract (( options , creator , type , delaycons ) ):
8497 """Let the user interact with the options dialog"""
85- old_options = options [:]
98+ old_options = ( options [:], creator , type , delaycons )
8699 d = GetNewDialog (OPT_DIALOG_ID , - 1 )
100+ tp , h , rect = d .GetDialogItem (OD_CREATOR_ITEM )
101+ SetDialogItemText (h , creator )
102+ tp , h , rect = d .GetDialogItem (OD_TYPE_ITEM )
103+ SetDialogItemText (h , type )
87104 d .SetDialogDefaultItem (OD_OK_ITEM )
88105 d .SetDialogCancelItem (OD_CANCEL_ITEM )
89106 while 1 :
90107 for i in range (len (options )):
91108 tp , h , rect = d .GetDialogItem (i + 1 )
92109 h .as_Control ().SetControlValue (options [i ])
110+ tp , h , rect = d .GetDialogItem (OD_DELAYCONSOLE_ITEM )
111+ h .as_Control ().SetControlValue (delaycons )
93112 n = ModalDialog (None )
94113 if n == OD_OK_ITEM :
95- return options
114+ tp , h , rect = d .GetDialogItem (OD_CREATOR_ITEM )
115+ ncreator = GetDialogItemText (h )
116+ tp , h , rect = d .GetDialogItem (OD_TYPE_ITEM )
117+ ntype = GetDialogItemText (h )
118+ if len (ncreator ) == 4 and len (ntype ) == 4 :
119+ return options , ncreator , ntype , delaycons
120+ else :
121+ sys .stderr .write ('\007 ' )
96122 elif n == OD_CANCEL_ITEM :
97123 return old_options
124+ elif n in (OD_CREATOR_ITEM , OD_TYPE_ITEM ):
125+ pass
126+ elif n == OD_DELAYCONSOLE_ITEM :
127+ delaycons = (not delaycons )
98128 elif 1 <= n <= len (options ):
99129 options [n - 1 ] = (not options [n - 1 ])
100130
@@ -160,6 +190,28 @@ def getoptions(id):
160190 return [0 ]* 7 , None
161191 return map (lambda x : ord (x ), opr .data ), opr
162192
193+ def getgusioptions (id ):
194+ try :
195+ opr = GetResource ('GU\267 I' , id )
196+ except (MacOS .Error , Res .Error ):
197+ return '????' , '????' , 0 , None
198+ data = opr .data
199+ type = data [GUSIPOS_TYPE :GUSIPOS_TYPE + 4 ]
200+ creator = data [GUSIPOS_CREATOR :GUSIPOS_CREATOR + 4 ]
201+ flags = ord (data [GUSIPOS_FLAGS ])
202+ delay = (not not (flags & GUSIFLAGS_DELAY ))
203+ return creator , type , delay , opr
204+
205+ def setgusioptions (opr , creator , type , delay ):
206+ data = opr .data
207+ flags = ord (data [GUSIPOS_FLAGS ])
208+ if delay :
209+ flags = flags | GUSIFLAGS_DELAY
210+ else :
211+ flags = flags & ~ GUSIFLAGS_DELAY
212+ data = type + creator + data [GUSIPOS_SKIP ] + chr (flags ) + data [GUSIPOS_FLAGS + 1 :]
213+ return data
214+
163215def openpreffile (rw ):
164216 # Find the preferences folder and our prefs file, create if needed.
165217 vrefnum , dirid = macfs .FindFolder (kOnSystemDisk , 'pref' , 0 )
@@ -199,14 +251,18 @@ def edit_preferences():
199251 options , opr = getoptions (OPTIONS_ID )
200252 saved_options = options [:]
201253
254+ creator , type , delaycons , gusi_opr = getgusioptions (GUSI_ID )
255+ saved_gusi_options = creator , type , delaycons
256+
202257 # Let the user play away
203- result = interact (l , fss , options , 'System-wide preferences' )
258+ result = interact (l , fss , (options , creator , type , delaycons ),
259+ 'System-wide preferences' )
204260
205261 # See what we have to update, and how
206262 if result == None :
207263 sys .exit (0 )
208264
209- pathlist , nfss , options = result
265+ pathlist , nfss , ( options , creator , type , delaycons ) = result
210266 if nfss != fss :
211267 fss_changed = 1
212268
@@ -238,6 +294,16 @@ def edit_preferences():
238294 else :
239295 opr = Resource (newdata )
240296 opr .AddResource ('Popt' , OPTIONS_ID , '' )
297+
298+ if (creator , type , delaycons ) != saved_gusi_options :
299+ newdata = setgusioptions (gusi_opr , creator , type , delaycons )
300+ if gusi_opr .HomeResFile () == preff_handle :
301+ gusi_opr .data = newdata
302+ gusi_opr .ChangedResource ()
303+ else :
304+ print 'Created new GUSI option'
305+ ngusi_opr = Resource (gusi_opr .data )
306+ ngusi_opr .AddResource ('GU\267 I' , GUSI_ID , '' )
241307
242308 CloseResFile (preff_handle )
243309
@@ -275,12 +341,21 @@ def edit_applet(name):
275341 options , dummy = getoptions (OPTIONS_ID )
276342 saved_options = options [:]
277343
344+ creator , type , delaycons , gusi_opr = getgusioptions (OVERRIDE_GUSI_ID )
345+ if not opr :
346+ if notfound :
347+ notfound = notfound + ', GUSI options'
348+ else :
349+ notfound = 'GUSI options'
350+ creator , type , delaycons , dummy = getgusioptions (GUSI_ID )
351+ saved_gusi_options = creator , type , delaycons
352+
278353 dummy = dummy2 = None # Discard them.
279354
280355 if notfound :
281356 message ('Warning: initial %s taken from system-wide defaults' % notfound )
282357 # Let the user play away
283- result = interact (l , fss , options , name )
358+ result = interact (l , fss , ( options , creator , type , delaycons ) , name )
284359
285360 # See what we have to update, and how
286361 if result == None :
@@ -318,7 +393,16 @@ def edit_applet(name):
318393 else :
319394 opr = Resource (newdata )
320395 opr .AddResource ('Popt' , OVERRIDE_OPTIONS_ID , '' )
321-
396+
397+ if (creator , type , delaycons ) != saved_gusi_options :
398+ newdata = setgusioptions (gusi_opr , creator , type , delaycons )
399+ if gusi_opr .HomeResFile == app_handle :
400+ gusi_opr .data = newdata
401+ gusi_opr .ChangedResource ()
402+ else :
403+ gusi_opr = Resource (gusi_opr .data )
404+ gusi_opr .AddResource ('GU\267 I' , OVERRIDE_GUSI_ID , '' )
405+
322406 CloseResFile (app_handle )
323407
324408def main ():
@@ -335,5 +419,4 @@ def main():
335419
336420
337421if __name__ == '__main__' :
338- print # Stupid, to init toolboxes...
339422 main ()
0 commit comments