Keepconsole is now a 4-way option: never/errorexit/unseen output/always. Default is "unseen output". Upped the Popt version number.
diff --git a/Mac/Include/macbuildno.h b/Mac/Include/macbuildno.h
index 7cced77..f1bf41a 100644
--- a/Mac/Include/macbuildno.h
+++ b/Mac/Include/macbuildno.h
@@ -1 +1 @@
-#define BUILD 55
+#define BUILD 66
diff --git a/Mac/Include/pythonresources.h b/Mac/Include/pythonresources.h
index 1782608..0b74328 100644
--- a/Mac/Include/pythonresources.h
+++ b/Mac/Include/pythonresources.h
@@ -68,9 +68,11 @@
 #define OPT_OPTIMIZE	5
 #define OPT_UNBUFFERED	6
 #define OPT_DEBUGGING	7
-#define OPT_KEEPNORMAL	8
-#define OPT_KEEPERROR	9
-#define OPT_CMDLINE		10
+#define OPT_KEEPALWAYS	8
+#define OPT_KEEPOUTPUT	9
+#define OPT_KEEPERROR   10
+#define OPT_KEEPNEVER   11
+#define OPT_CMDLINE		12
 #define OPT_TABWARN	13
 #define OPT_NOSITE	14
 #define OPT_HELP	15
@@ -134,17 +136,12 @@
 /* The Python options resource and offset of its members */
 #define PYTHONOPTIONS_ID 228
 #define PYTHONOPTIONSOVERRIDE_ID 229
-#if 0
-#define POPT_INSPECT	0
-#define POPT_VERBOSE	1
-#define POPT_OPTIMIZE	2
-#define POPT_UNBUFFERED	3
-#define POPT_DEBUGGING	4
-#define POPT_KEEPNORM	5
-#define POPT_KEEPERR	6
-#endif
 
-#define POPT_VERSION_CURRENT	5	/* Current version number */
+#define POPT_VERSION_CURRENT	6	/* Current version number */
+#define   POPT_KEEPCONSOLE_NEVER  0
+#define   POPT_KEEPCONSOLE_OUTPUT 1
+#define   POPT_KEEPCONSOLE_ERROR  2
+#define   POPT_KEEPCONSOLE_ALWAYS 3
 
 #ifndef rez
 typedef struct PyMac_PrefRecord {
@@ -154,8 +151,8 @@
 	unsigned char	optimize;
 	unsigned char	unbuffered;
 	unsigned char	debugging;
-	unsigned char	keep_normal;
-	unsigned char	keep_error;
+	unsigned char	unused;
+	unsigned char	keep_console;
 	unsigned char	nointopt;
 	unsigned char	noargs;
 	unsigned char	tabwarn;
diff --git a/Mac/Lib/pythonprefs.py b/Mac/Lib/pythonprefs.py
index 916ec9f..81d095f 100644
--- a/Mac/Lib/pythonprefs.py
+++ b/Mac/Lib/pythonprefs.py
@@ -16,7 +16,7 @@
 OVERRIDE_GUSI_ID = 10241
 
 # version
-CUR_VERSION=5
+CUR_VERSION=6
 
 preffilename = PstringLoader(AnyResLoader('STR ', resname=PREFNAME_NAME)).load()
 pref_fss = preferencefile(preffilename, 'Pyth', 'pref')
@@ -88,7 +88,7 @@
 		dict['creator'], dict['type'], dict['delayconsole'] = self.gusi.load()
 		flags = self.popt.load()
 		dict['version'], dict['inspect'], dict['verbose'], dict['optimize'], \
-			dict['unbuffered'], dict['debugging'], dict['keepopen'], dict['keeperror'], \
+			dict['unbuffered'], dict['debugging'], dummy, dict['keep_console'], \
 			dict['nointopt'], dict['noargs'], dict['tabwarn'], \
 			dict['nosite'], dict['nonavservice'] = flags
 		return dict
@@ -99,7 +99,7 @@
 		self.dir.save(diralias)
 		self.gusi.save((dict['creator'], dict['type'], dict['delayconsole']))
 		flags = dict['version'], dict['inspect'], dict['verbose'], dict['optimize'], \
-			dict['unbuffered'], dict['debugging'], dict['keepopen'], dict['keeperror'], \
+			dict['unbuffered'], dict['debugging'], 0, dict['keep_console'], \
 			dict['nointopt'], dict['noargs'], dict['tabwarn'], \
 			dict['nosite'], dict['nonavservice']
 		self.popt.save(flags)
diff --git a/Mac/Python/macmain.c b/Mac/Python/macmain.c
index c46fd2f..3531f4c 100644
--- a/Mac/Python/macmain.c
+++ b/Mac/Python/macmain.c
@@ -53,6 +53,9 @@
 #ifdef USE_MAC_SHARED_LIBRARY
 extern PyMac_AddLibResources(void);
 #endif
+#ifdef USE_GUSI
+#include "GUSISIOUX.h"
+#endif
 
 #define STARTUP "PythonStartup"
 
@@ -151,8 +154,15 @@
 	SET_OPT_ITEM(OPT_OPTIMIZE, optimize);
 	SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered);
 	SET_OPT_ITEM(OPT_DEBUGGING, debugging);
-	SET_OPT_ITEM(OPT_KEEPNORMAL, keep_normal);
-	SET_OPT_ITEM(OPT_KEEPERROR, keep_error);
+	GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect);
+	SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS));
+	GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect);
+	SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT));
+	GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect);
+	SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR));
+	GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect);
+	SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER));
+/*	SET_OPT_ITEM(OPT_KEEPCONSOLE, keep_console); */
 	SET_OPT_ITEM(OPT_TABWARN, tabwarn);
 	SET_OPT_ITEM(OPT_NOSITE, nosite);
 	SET_OPT_ITEM(OPT_NONAVSERV, nonavservice);
@@ -204,8 +214,18 @@
 		OPT_ITEM(OPT_OPTIMIZE, optimize);
 		OPT_ITEM(OPT_UNBUFFERED, unbuffered);
 		OPT_ITEM(OPT_DEBUGGING, debugging);
-		OPT_ITEM(OPT_KEEPNORMAL, keep_normal);
-		OPT_ITEM(OPT_KEEPERROR, keep_error);
+		if ( item == OPT_KEEPALWAYS ) p->keep_console = POPT_KEEPCONSOLE_ALWAYS;
+		if ( item == OPT_KEEPOUTPUT ) p->keep_console = POPT_KEEPCONSOLE_OUTPUT;
+		if ( item == OPT_KEEPERROR ) p->keep_console = POPT_KEEPCONSOLE_ERROR;
+		if ( item == OPT_KEEPNEVER ) p->keep_console = POPT_KEEPCONSOLE_NEVER;
+		GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect);
+		SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS));
+		GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect);
+		SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT));
+		GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect);
+		SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR));
+		GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect);
+		SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER));
 		OPT_ITEM(OPT_TABWARN, tabwarn);
 		OPT_ITEM(OPT_NOSITE, nosite);
 		OPT_ITEM(OPT_NONAVSERV, nonavservice);
@@ -252,7 +272,7 @@
 #endif
 
 	/* Get options from preference file (or from applet resource fork) */
-	options.keep_error = 1;		/* default-default */
+	options.keep_console = POPT_KEEPCONSOLE_OUTPUT;		/* default-default */
 	PyMac_PreferenceOptions(&options);
 	
 	if ( embedded ) {
@@ -281,7 +301,7 @@
 	}
 	
 	/* Copy selected options to where the machine-independent stuff wants it */
-	Py_VerboseFlag = options.verbose *2;
+	Py_VerboseFlag = options.verbose;
 /*	Py_SuppressPrintingFlag = options.suppress_print; */
 	Py_OptimizeFlag = options.optimize;
 	Py_DebugFlag = options.debugging;
@@ -525,18 +545,31 @@
 PyMac_Exit(status)
 	int status;
 {
-	int keep;
+	int keep = 0;
 
 #if __profile__ == 1
 	ProfilerDump("\pPython Profiler Results");
 	ProfilerTerm();
 #endif	
-	if ( status )
-		keep = options.keep_error;
-	else
-		keep = options.keep_normal;
 		
 #ifdef USE_SIOUX
+	switch (options.keep_console) {
+	case POPT_KEEPCONSOLE_NEVER:
+		keep = 0;
+		break;
+	case POPT_KEEPCONSOLE_OUTPUT:
+		if (gusisioux_state == GUSISIOUX_STATE_LASTWRITE ||
+				gusisioux_state == GUSISIOUX_STATE_UNKNOWN )
+			keep = 1;
+		else
+			keep = 0;
+		break;
+	case POPT_KEEPCONSOLE_ERROR:
+		keep = (status != 0);
+		break;
+	default:
+		keep = 1;
+	}
 	if (keep) {
 		SIOUXSettings.standalone = 1;
 		SIOUXSettings.autocloseonquit = 0;
diff --git a/Mac/Resources/dialogs.rsrc b/Mac/Resources/dialogs.rsrc
index 907b9d0..4a84dd6 100644
--- a/Mac/Resources/dialogs.rsrc
+++ b/Mac/Resources/dialogs.rsrc
Binary files differ
diff --git a/Mac/Resources/pythonpath.r b/Mac/Resources/pythonpath.r
index 7f23c15..25b59cd 100644
--- a/Mac/Resources/pythonpath.r
+++ b/Mac/Resources/pythonpath.r
@@ -15,8 +15,11 @@
 	byte noOptimize = 0, optimize = 1;
 	byte noUnbuffered = 0, unbuffered = 1;
 	byte noDebugParser = 0, debugParser = 1;
-	byte closeOnNormalExit = 0, noCloseOnNormalExit = 1;
-	byte closeOnErrorExit = 0, noCloseOnErrorExit = 1;
+	byte unused_0 = 0, unused_1 = 1;
+	byte closeAlways = POPT_KEEPCONSOLE_NEVER,
+	     noCloseOutput = POPT_KEEPCONSOLE_OUTPUT,
+	     noCloseError = POPT_KEEPCONSOLE_ERROR,
+	     closeNever = POPT_KEEPCONSOLE_ALWAYS;
 	byte interactiveOptions = 0, noInteractiveOptions = 1;
 	byte argcArgv = 0, noArgcArgv = 1;
 	byte newStandardExceptions = 0, oldStandardExceptions = 1;
@@ -62,8 +65,8 @@
 	noOptimize,
 	noUnbuffered,
 	noDebugParser,
-	closeOnNormalExit,
-	noCloseOnErrorExit,
+	unused_0,
+	noCloseOutput,
 	interactiveOptions,
 	argcArgv,
 	newStandardExceptions,
diff --git a/Mac/scripts/EditPythonPrefs.py b/Mac/scripts/EditPythonPrefs.py
index d9f30f1..f49f398 100644
--- a/Mac/scripts/EditPythonPrefs.py
+++ b/Mac/scripts/EditPythonPrefs.py
@@ -37,31 +37,34 @@
 # Map dialog item numbers to option names (and the reverse)
 opt_dialog_map = [
 	None,
+	None,
 	"inspect",
 	"verbose",
 	"optimize",
 	"unbuffered",
 	"debugging",
-	"keepopen",
-	"keeperror",
+	"tabwarn",
+	"nosite",
+	"nonavservice",
 	"nointopt",
 	"noargs",
 	"delayconsole",
-	None, None, None, None, None, None, None, None, # 11-18 are different
-	"tabwarn",
-	"nosite",
-	"nonavservice"]
+	]
 opt_dialog_dict = {}
 for i in range(len(opt_dialog_map)):
 	if opt_dialog_map[i]:
 		opt_dialog_dict[opt_dialog_map[i]] = i
 # 1 thru 10 are the options
 # The GUSI creator/type and delay-console
-OD_CREATOR_ITEM = 11
-OD_TYPE_ITEM = 12
-OD_OK_ITEM = 13
-OD_CANCEL_ITEM = 14
-OD_HELP_ITEM = 22
+OD_CREATOR_ITEM = 18
+OD_TYPE_ITEM = 19
+OD_OK_ITEM = 1
+OD_CANCEL_ITEM = 2
+OD_HELP_ITEM = 20
+OD_KEEPALWAYS_ITEM = 14
+OD_KEEPOUTPUT_ITEM = 15
+OD_KEEPERROR_ITEM = 16
+OD_KEEPNEVER_ITEM = 17
 
 def optinteract(options):
 	"""Let the user interact with the options dialog"""
@@ -72,12 +75,19 @@
 	SetDialogItemText(htext, options['type'])
 	d.SetDialogDefaultItem(OD_OK_ITEM)
 	d.SetDialogCancelItem(OD_CANCEL_ITEM)
-	
 	while 1:
 		for name in opt_dialog_dict.keys():
 			num = opt_dialog_dict[name]
 			ctl = d.GetDialogItemAsControl(num)
 			ctl.SetControlValue(options[name])
+		ctl = d.GetDialogItemAsControl(OD_KEEPALWAYS_ITEM)
+		ctl.SetControlValue(options['keep_console'] == 3)
+		ctl = d.GetDialogItemAsControl(OD_KEEPOUTPUT_ITEM)
+		ctl.SetControlValue(options['keep_console'] == 1)
+		ctl = d.GetDialogItemAsControl(OD_KEEPERROR_ITEM)
+		ctl.SetControlValue(options['keep_console'] == 2)
+		ctl = d.GetDialogItemAsControl(OD_KEEPNEVER_ITEM)
+		ctl.SetControlValue(options['keep_console'] == 0)
 		n = ModalDialog(None)
 		if n == OD_OK_ITEM:
 			htext = d.GetDialogItemAsControl(OD_CREATOR_ITEM)
@@ -94,6 +104,14 @@
 			return
 		elif n in (OD_CREATOR_ITEM, OD_TYPE_ITEM):
 			pass
+		elif n == OD_KEEPALWAYS_ITEM:
+			options['keep_console'] = 3;
+		elif n == OD_KEEPOUTPUT_ITEM:
+			options['keep_console'] = 1;
+		elif n == OD_KEEPERROR_ITEM:
+			options['keep_console'] = 2;
+		elif n == OD_KEEPNEVER_ITEM:
+			options['keep_console'] = 0;
 		elif n == OD_HELP_ITEM:
 			onoff = Help.HMGetBalloons()
 			Help.HMSetBalloons(not onoff)
diff --git a/Mac/scripts/EditPythonPrefs.rsrc b/Mac/scripts/EditPythonPrefs.rsrc
index f4b893f..cc35df2 100644
--- a/Mac/scripts/EditPythonPrefs.rsrc
+++ b/Mac/scripts/EditPythonPrefs.rsrc
Binary files differ