r14171 by jghali - on Windows, isolate local python install from other potential system installed versions

scribus-commit scribus-commit at lists.scribus.net
Sun Oct 18 16:40:24 CEST 2009


Revision: 14171
Author: jghali
Date: 2009-10-18T12:23:33.886047Z
Commit message: on Windows, isolate local python install from other potential system installed versions

Changeset: 
M  /trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.h
M  /trunk/Scribus/scribus/main_win32.cpp
M  /trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp

Diffs:
Index: scribus/main_win32.cpp
===================================================================
--- scribus/main_win32.cpp	(revision 14170)
+++ scribus/main_win32.cpp	(revision 14171)
@@ -49,8 +49,8 @@
 
 #include "scconfig.h"
 
+#include <windows.h>
 #include <wincon.h>
-#include <windows.h>
 
 int mainApp(ScribusQApp& app);
 
@@ -64,6 +64,9 @@
 bool consoleOptionEnabled(int argc, char* argv[]);
 void redirectIOToConsole(void);
 
+// Python environment configuration function
+void setPythonEnvironment(const QString& appPath);
+
 // Console option arguments declared in scribusapp.cpp
 extern const char ARG_CONSOLE[];
 extern const char ARG_CONSOLE_SHORT[];
@@ -85,6 +88,7 @@
 	}
 #endif
 	ScribusQApp app(argc, argv);
+	setPythonEnvironment(app.applicationDirPath());
 	result =  mainApp(app);
 	return result;
 }
@@ -125,6 +129,47 @@
 }
 
 /*!
+\fn void setPythonEnvironment(const QString& appPath)
+\author Jean Ghali
+\date Sat Jul 03 23:00:00 CET 2009
+\brief set the Python envirionment for Scribus
+\param appPath application Path
+\retval None
+*/
+void setPythonEnvironment(const QString& appPath)
+{
+	QString pythonHome = appPath + "/python";
+	if (!QDir(pythonHome).exists()) return; //assume a custom python
+
+	QString tmp = "PYTHONHOME=" + QDir::toNativeSeparators(pythonHome);
+	_wputenv((const wchar_t*) tmp.utf16());
+
+	QString nativePath = QDir::toNativeSeparators(appPath);
+    tmp = "PYTHONPATH=";
+    tmp += nativePath;
+    tmp += "\\python;";
+    tmp += nativePath;
+    tmp += "\\python\\lib;";
+    tmp += nativePath;
+    tmp += "\\python\\dlls;";
+	tmp += nativePath;
+    tmp += "\\python\\tcl";
+    _wputenv((const wchar_t*) tmp.utf16());
+
+	wchar_t* oldenv = _wgetenv(L"PATH");
+    tmp = "PATH=";
+    tmp += nativePath;
+    tmp += ";";
+    tmp += nativePath;
+    tmp += "\\python";
+    if(oldenv != NULL) {
+        tmp += ";";
+		tmp +=  QString::fromUtf16((const ushort*) oldenv);
+    }
+    _wputenv((const wchar_t*) tmp.utf16());
+}
+
+/*!
 \fn int exceptionFilter(DWORD exceptionCode)
 \author Jean Ghali
 \date Sun Oct 30 14:30:30 CET 2005
Index: scribus/plugins/scriptplugin/scriptplugin.h
===================================================================
--- scribus/plugins/scriptplugin/scriptplugin.h	(revision 14170)
+++ scribus/plugins/scriptplugin/scriptplugin.h	(revision 14171)
@@ -11,6 +11,7 @@
 #include "scplugin.h"
 #include "pluginapi.h"
 //Added by qt3to4:
+#include <QByteArray>
 #include <QPixmap>
 
 class QString;
@@ -37,6 +38,7 @@
 		virtual void addToMainWindowMenu(ScribusMainWindow *);
 
 		// Special features (none)
+		QByteArray pythonHome;
 };
 
 extern "C" PLUGIN_API int scriptplugin_getPluginAPIVersion();
Index: scribus/plugins/scriptplugin/scriptplugin.cpp
===================================================================
--- scribus/plugins/scriptplugin/scriptplugin.cpp	(revision 14170)
+++ scribus/plugins/scriptplugin/scriptplugin.cpp	(revision 14171)
@@ -159,6 +159,15 @@
 bool ScriptPlugin::initPlugin()
 {
 	QString cm;
+#if defined(Q_OS_WIN)
+	QString pyHome = qApp->applicationDirPath() + "/python";
+	if (QDir(pyHome).exists())
+	{
+		QString ph = QDir::toNativeSeparators(pyHome);
+		pythonHome = ph.toLocal8Bit();
+		Py_SetPythonHome(pythonHome.data());
+	}
+#endif
 	Py_Initialize();
 	if (PyUnicode_SetDefaultEncoding("utf-8"))
 	{




More information about the scribus-commit mailing list