From 4c55e03bcf378182ee9da87f478c51a2c0aa0909 Mon Sep 17 00:00:00 2001
From: Juraj Fedel <wtxnh-scribus@yahoo.com.au>
Date: Tue, 22 Sep 2015 08:34:20 +0200
Subject: [PATCH] Remove extra argument from python and preserve information
 about type of interpreter script is running in.

---
 scribus/plugins/scriptplugin/scriptercore.cpp | 24 ++++++++++--------------
 1 file changed, 10 insertions(+), 14 deletions(-)

diff --git a/scribus/plugins/scriptplugin/scriptercore.cpp b/scribus/plugins/scriptplugin/scriptercore.cpp
index 751d952..4ec6088 100644
--- a/scribus/plugins/scriptplugin/scriptercore.cpp
+++ b/scribus/plugins/scriptplugin/scriptercore.cpp
@@ -262,16 +262,8 @@ void ScripterCore::slotRunScriptFile(QString fileName, QStringList arguments, bo
 
 	// Make sure sys.argv[0] is the path to the script
 	arguments.prepend(na.data());
-	
-	// and tell the script if it's running in the main intepreter or
-	// a subinterpreter using the second argument, ie sys.argv[1]
-	if (inMainInterpreter)
-		arguments.insert(1,QString("ext"));
-	else
-		arguments.insert(1,QString("sub"));
-
 	//convert arguments (QListString) to char** for Python bridge
-	/* typically arguments == ['path/to/script.py','ext','--argument1','valueforarg1','--flag']*/
+	/* typically arguments == ['path/to/script.py','--argument1','valueforarg1','--flag']*/
 	char **comm = new char*[arguments.size()];
 	for (int i = 0; i < arguments.size(); i++)
 	{
@@ -309,6 +301,12 @@ void ScripterCore::slotRunScriptFile(QString fileName, QStringList arguments, bo
 		// Replace sys.stdin with a dummy StringIO that always returns
 		// "" for read
 		cm        += QString("sys.stdin = cStringIO.StringIO()\n");
+		// tell the script if it's running in the main intepreter or a subinterpreter
+		cm        += QString("import scribus\n");
+		if (inMainInterpreter)
+			cm+= QString("scribus.mainInterpreter = True\n");
+		else
+			cm+= QString("scribus.mainInterpreter = False\n");
 		cm        += QString("try:\n");
 		cm        += QString("    execfile(\"%1\")\n").arg(escapedFileName);
 		cm        += QString("except SystemExit:\n");
@@ -414,7 +412,8 @@ void ScripterCore::slotRunScript(const QString Script)
 				"    scribus._bu = cStringIO.StringIO()\n"
 				"    sys.stdout = scribus._bu\n"
 				"    sys.stderr = scribus._bu\n"
-				"    sys.argv = ['scribus', 'ext']\n" // this is the PySys_SetArgv replacement
+				"    sys.argv = ['scribus']\n" // this is the PySys_SetArgv replacement
+				"    scribus.mainInterpreter = True\n" // the scripter console runs everything in the main interpreter
 				"    for i in scribus.getval().splitlines():\n"
 				"        scribus._ia.push(i)\n"
 				"    scribus.retval(scribus._bu.getvalue())\n"
@@ -434,10 +433,7 @@ void ScripterCore::slotRunScript(const QString Script)
 	Anyway - sys.argv is set above
 	char* comm[1];
 	comm[0] = const_cast<char*>("scribus");
-	// the scripter console runs everything in the main interpreter
-	// tell the code it's running there.
-	comm[1] = const_cast<char*>("ext");
-	PySys_SetArgv(2, comm); */
+	PySys_SetArgv(1, comm); */
 	// then run the code
 	PyObject* m = PyImport_AddModule((char*)"__main__");
 	if (m == NULL)
-- 
2.1.4

