Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a4b7e14

Browse files
committed
Store default startup options in preference file or
app.
1 parent 532e3c2 commit a4b7e14

3 files changed

Lines changed: 66 additions & 4 deletions

File tree

Mac/Include/pythonresources.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,14 @@
6565

6666
/* The alis resource for locating the python home directory */
6767
#define PYTHONHOME_ID 128
68+
69+
/* The Python options resource and offset of its members */
70+
#define PYTHONOPTIONS_ID 128
71+
#define POPT_INSPECT 0
72+
#define POPT_VERBOSE 1
73+
#define POPT_SUPPRESS 2
74+
#define POPT_UNBUFFERED 3
75+
#define POPT_DEBUGGING 4
76+
#define POPT_KEEPNORM 5
77+
#define POPT_KEEPERR 6
78+

Mac/Python/macgetpath.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,37 @@ char *dir;
263263
}
264264
#endif /* !USE_BUILTIN_PATH */
265265

266+
void
267+
PyMac_PreferenceOptions(int *inspect, int *verbose, int *suppress_print,
268+
int *unbuffered, int *debugging, int *keep_normal,
269+
int *keep_error)
270+
{
271+
short oldrh, prefrh;
272+
Handle handle;
273+
int size;
274+
char *p;
275+
276+
277+
oldrh = CurResFile();
278+
prefrh = PyMac_OpenPrefFile();
279+
handle = GetResource('Popt', PYTHONOPTIONS_ID);
280+
if ( handle == NULL ) {
281+
return;
282+
}
283+
HLock(handle);
284+
size = GetHandleSize(handle);
285+
p = (char *)*handle;
286+
287+
if ( size > POPT_INSPECT ) *inspect = p[POPT_INSPECT];
288+
if ( size > POPT_VERBOSE ) *verbose = p[POPT_VERBOSE];
289+
if ( size > POPT_SUPPRESS ) *suppress_print = p[POPT_SUPPRESS];
290+
if ( size > POPT_UNBUFFERED ) *unbuffered = p[POPT_UNBUFFERED];
291+
if ( size > POPT_DEBUGGING ) *debugging = p[POPT_DEBUGGING];
292+
if ( size > POPT_KEEPNORM ) *keep_normal = p[POPT_KEEPNORM];
293+
if ( size > POPT_KEEPERR ) *keep_error = p[POPT_KEEPERR];
294+
295+
HUnlock(handle);
296+
297+
CloseResFile(prefrh);
298+
UseResFile(oldrh);
299+
}

Mac/Python/macmain.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,
178178
DialogPtr dialog;
179179
Rect rect;
180180

181+
/* Default-defaults: */
182+
*keep_error = 1;
183+
/* Get default settings from our preference file */
184+
PyMac_PreferenceOptions(&inspect, &Py_VerboseFlag, &Py_SuppressPrintingFlag,
185+
&unbuffered, &Py_DebugFlag, &keep_normal, &keep_error);
186+
/* If option is pressed override these */
181187
GetKeys(rmap);
182188
map = (unsigned char *)rmap;
183189
if ( ( map[0x3a>>3] & (1<<(0x3a&7)) ) == 0 ) /* option key is 3a */
@@ -189,9 +195,20 @@ PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,
189195
return;
190196
}
191197

192-
/* Set keep-open-on-error */
193-
GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect);
194-
SetCtlValue(handle, *keep_error);
198+
/* Set default values */
199+
#define SET_OPT_ITEM(num, var) \
200+
GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \
201+
SetCtlValue(handle, (short)*(var));
202+
203+
SET_OPT_ITEM(OPT_INSPECT, inspect);
204+
SET_OPT_ITEM(OPT_VERBOSE, verbose);
205+
SET_OPT_ITEM(OPT_SUPPRESS, suppress_print);
206+
SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered);
207+
SET_OPT_ITEM(OPT_DEBUGGING, debugging);
208+
SET_OPT_ITEM(OPT_KEEPNORMAL, keep_normal);
209+
SET_OPT_ITEM(OPT_KEEPERROR, keep_error);
210+
211+
#undef SET_OPT_ITEM
195212

196213
while (1) {
197214
handle = NULL;
@@ -310,7 +327,7 @@ PyMac_Exit(status)
310327
if (keep) {
311328
SIOUXSettings.standalone = 1;
312329
SIOUXSettings.autocloseonquit = 0;
313-
SIOUXSetTitle("\pÇterminatedÈ");
330+
SIOUXSetTitle("\p«terminated»");
314331
}
315332
else
316333
SIOUXSettings.autocloseonquit = 1;

0 commit comments

Comments
 (0)