r22470 by jghali - #15238: Conflict with Python 3 prevent scribus to run

scribus-commit scribus-commit at lists.scribus.net
Mon Apr 16 11:01:46 UTC 2018


Author: jghali
Date: Mon Apr 16 11:01:46 2018
New Revision: 22470

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22470
Log:
#15238: Conflict with Python 3 prevent scribus to run

Modified:
    branches/Version14x/Scribus/scribus/main_win32.cpp
    branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
    branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.h

Modified: branches/Version14x/Scribus/scribus/main_win32.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22470&path=/branches/Version14x/Scribus/scribus/main_win32.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/main_win32.cpp	(original)
+++ branches/Version14x/Scribus/scribus/main_win32.cpp	Mon Apr 16 11:01:46 2018
@@ -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,7 +88,9 @@
 	}
 #endif
 	ScribusQApp app(argc, argv);
+	setPythonEnvironment(app.applicationDirPath());
 	result =  mainApp(app);
+
 	return result;
 }
 
@@ -125,6 +130,48 @@
 }
 
 /*!
+\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
@@ -135,7 +182,7 @@
 LONG exceptionFilter(DWORD exceptionCode)
 {
 	LONG result;
-	switch( exceptionCode )
+	switch (exceptionCode)
 	{
 	case EXCEPTION_ACCESS_VIOLATION:
 	case EXCEPTION_DATATYPE_MISALIGNMENT:

Modified: branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22470&path=/branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(original)
+++ branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	Mon Apr 16 11:01:46 2018
@@ -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"))
 	{

Modified: branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22470&path=/branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.h
==============================================================================
--- branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.h	(original)
+++ branches/Version14x/Scribus/scribus/plugins/scriptplugin/scriptplugin.h	Mon Apr 16 11:01:46 2018
@@ -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();




More information about the scribus-commit mailing list