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

Skip to content

Commit 0168f27

Browse files
committed
Added options for keeping window open on normal/error termination
Moved whole exit-handling of console window here (from pythonrun.c)
1 parent 66a8977 commit 0168f27

2 files changed

Lines changed: 47 additions & 10 deletions

File tree

Mac/Include/pythonresources.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#define OPT_SUPPRESS 5
4242
#define OPT_UNBUFFERED 6
4343
#define OPT_DEBUGGING 7
44+
#define OPT_KEEPNORMAL 8
45+
#define OPT_KEEPERROR 9
4446

4547
/* Dialog for 'No preferences directory' */
4648
#define NOPREFDIR_ID 133

Mac/Python/macmain.c

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
4040
#include <SIOUX.h>
4141
#endif
4242

43+
#ifdef THINK_C
44+
#include <console.h>
45+
#endif
46+
4347
#define STARTUP "PythonStartup"
4448

4549
extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */
@@ -59,6 +63,10 @@ static char *argv0;
5963
static char **orig_argv;
6064
static int orig_argc;
6165

66+
/* Flags indicating whether stdio window should stay open on termination */
67+
static int keep_normal;
68+
static int keep_error = 1;
69+
6270
#ifdef USE_MAC_APPLET_SUPPORT
6371
/* Applet support */
6472

@@ -117,12 +125,7 @@ PyMac_InitApplet()
117125
err = run_main_resource();
118126
fflush(stderr);
119127
fflush(stdout);
120-
#ifdef __MWERKS__
121-
if (!err)
122-
SIOUXSettings.autocloseonquit = 1;
123-
else
124-
printf("\n[Terminated]\n");
125-
#endif
128+
PyMac_Exit(err);
126129
/* XXX Should we bother to Py_Exit(sts)? */
127130
}
128131

@@ -164,7 +167,8 @@ PyMac_InitApplication()
164167
*/
165168
void
166169
PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,
167-
int *unbuffered, int *debugging)
170+
int *unbuffered, int *debugging, int *keep_normal,
171+
int *keep_error)
168172
{
169173
KeyMap rmap;
170174
unsigned char *map;
@@ -183,6 +187,11 @@ PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,
183187
printf("Option dialog not found - cannot set options\n");
184188
return;
185189
}
190+
191+
/* Set keep-open-on-error */
192+
GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect);
193+
SetCtlValue(handle, *keep_error);
194+
186195
while (1) {
187196
handle = NULL;
188197
ModalDialog(NULL, &item);
@@ -204,6 +213,8 @@ PyMac_InteractiveOptions(int *inspect, int *verbose, int *suppress_print,
204213
OPT_ITEM(OPT_SUPPRESS, suppress_print);
205214
OPT_ITEM(OPT_UNBUFFERED, unbuffered);
206215
OPT_ITEM(OPT_DEBUGGING, debugging);
216+
OPT_ITEM(OPT_KEEPNORMAL, keep_normal);
217+
OPT_ITEM(OPT_KEEPERROR, keep_error);
207218

208219
#undef OPT_ITEM
209220
}
@@ -228,8 +239,7 @@ Py_Main(argc, argv)
228239
argv0 = argv[0]; /* For getprogramname() */
229240

230241
PyMac_InteractiveOptions(&inspect, &Py_VerboseFlag, &Py_SuppressPrintingFlag,
231-
&unbuffered, &Py_DebugFlag);
232-
242+
&unbuffered, &Py_DebugFlag, &keep_normal, &keep_error);
233243

234244
if (unbuffered) {
235245
#ifndef MPW
@@ -253,7 +263,7 @@ Py_Main(argc, argv)
253263
if ((fp = fopen(filename, "r")) == NULL) {
254264
fprintf(stderr, "%s: can't open file '%s'\n",
255265
argv[0], filename);
256-
exit(2);
266+
PyMac_Exit(2);
257267
}
258268
}
259269

@@ -282,6 +292,31 @@ Py_Main(argc, argv)
282292
/*NOTREACHED*/
283293
}
284294

295+
/*
296+
** Terminate application
297+
*/
298+
PyMac_Exit(status)
299+
int status;
300+
{
301+
int keep;
302+
303+
if ( status )
304+
keep = keep_error;
305+
else
306+
keep = keep_normal;
307+
308+
#ifdef __MWERKS__
309+
if (keep)
310+
printf("\n[Terminated]\n");
311+
else
312+
SIOUXSettings.autocloseonquit = 1;
313+
#endif
314+
#ifdef THINK_C
315+
console_options.pause_atexit = keep;
316+
#endif
317+
318+
exit(status);
319+
}
285320

286321
/* Return the program name -- some code out there needs this. */
287322

0 commit comments

Comments
 (0)