r19604 by craig - #12572: Apply python/no gui patches

scribus-commit scribus-commit at lists.scribus.net
Tue Oct 21 20:23:25 UTC 2014


Author: craig
Date: Tue Oct 21 20:23:25 2014
New Revision: 19604

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=19604
Log:
#12572: Apply python/no gui patches

Modified:
    trunk/Scribus/scribus/main_nix.cpp
    trunk/Scribus/scribus/main_win32.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
    trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
    trunk/Scribus/scribus/scribusapp.cpp
    trunk/Scribus/scribus/scribusapp.h
    trunk/Scribus/scribus/scribuscore.cpp
    trunk/Scribus/scribus/scribuscore.h

Modified: trunk/Scribus/scribus/main_nix.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/main_nix.cpp
==============================================================================
--- trunk/Scribus/scribus/main_nix.cpp (original)
+++ trunk/Scribus/scribus/main_nix.cpp Tue Oct 21 20:23:25 2014
@@ -78,13 +78,11 @@
 #endif // QT_VERSION == 0x040400
 #endif // Q_OS_UNIX
 	app.parseCommandLine();
+	int appRetVal=app.init();
+	if (appRetVal==EXIT_FAILURE)
+		return(EXIT_FAILURE);
 	if (app.useGUI)
-	{
-		int appRetVal=app.init();
-		if (appRetVal==EXIT_FAILURE)
-			return(EXIT_FAILURE);
 		return app.exec();
-	}
 	return EXIT_SUCCESS;	
 }
 

Modified: trunk/Scribus/scribus/main_win32.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/main_win32.cpp
==============================================================================
--- trunk/Scribus/scribus/main_win32.cpp (original)
+++ trunk/Scribus/scribus/main_win32.cpp Tue Oct 21 20:23:25 2014
@@ -114,10 +114,10 @@
 	{
 #endif
 		app.parseCommandLine();
-		if (app.useGUI)
+		appRetVal = app.init();
+		if (appRetVal != EXIT_FAILURE)
 		{
-			appRetVal = app.init();
-			if (appRetVal != EXIT_FAILURE)
+			if (app.useGUI)
 				appRetVal = app.exec();
 		}
 #ifndef _DEBUG

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp Tue Oct 21 20:23:25 2014
@@ -36,6 +36,7 @@
 #include "prefscontext.h"
 #include "prefstable.h"
 #include "prefsmanager.h"
+#include "scribusapp.h" // need it to acces ScQApp->pythonScript
 
 ScripterCore::ScripterCore(QWidget* parent)
 {
@@ -66,6 +67,9 @@
 
 	QObject::connect(pcon, SIGNAL(runCommand()), this, SLOT(slotExecute()));
 	QObject::connect(pcon, SIGNAL(paletteShown(bool)), this, SLOT(slotInteractiveScript(bool)));
+
+	QObject::connect(ScQApp, SIGNAL(appStarted()) , this, SLOT(runStartupScript()) );
+	QObject::connect(ScQApp, SIGNAL(appStarted()) , this, SLOT(slotRunPythonScript()) );
 }
 
 ScripterCore::~ScripterCore()
@@ -177,7 +181,6 @@
 void ScripterCore::runScriptDialog()
 {
 	QString fileName;
-	QString curDirPath = QDir::currentPath();
 	RunScriptDialog dia( ScCore->primaryMainWindow(), m_enableExtPython );
 	if (dia.exec())
 	{
@@ -193,7 +196,6 @@
 		}
 		rebuildRecentScriptsMenu();
 	}
-	QDir::setCurrent(curDirPath);
 	FinishScriptRun();
 }
 
@@ -246,8 +248,6 @@
 		//stateo = PyEval_SaveThread();
 		global_state = PyThreadState_Get();
 		state = Py_NewInterpreter();
-		// Chdir to the dir the script is in
-		QDir::setCurrent(fi.absolutePath());
 		// Init the scripter module in the sub-interpreter
 		initscribus(ScCore->primaryMainWindow());
 	}
@@ -292,11 +292,9 @@
 		// into a StringIO buffer for later extraction.
 		cm        += QString("except:\n");
 		cm        += QString("    import traceback\n");
-		cm        += QString("    import scribus\n");                  // we stash our working vars here
-		cm        += QString("    scribus._f=cStringIO.StringIO()\n");
-		cm        += QString("    traceback.print_exc(file=scribus._f)\n");
-		cm        += QString("    _errorMsg = scribus._f.getvalue()\n");
-		cm        += QString("    del(scribus._f)\n");
+		cm        += QString("    _errorMsg = traceback.format_exc()\n");
+		if (!ScCore->usingGUI())
+			cm += QString("    traceback.print_exc()\n");
 		// We re-raise the exception so the return value of PyRun_StringFlags reflects
 		// the fact that an exception has ocurred.
 		cm        += QString("    raise\n");
@@ -321,7 +319,7 @@
 				qDebug("Exception was:");
 				PyErr_Print();
 			}
-			else
+			else if (ScCore->usingGUI())
 			{
 				QString errorMsg = PyString_AsString(errorMsgPyStr);
 				// Display a dialog to the user with the exception
@@ -351,6 +349,16 @@
 	}
 
 	enableMainWindowMenu();
+}
+
+// needed for running script from CLI
+void ScripterCore::slotRunPythonScript()
+{
+	if (!ScQApp->pythonScript.isNull())
+	{
+		slotRunScriptFile(ScQApp->pythonScript, true);
+		FinishScriptRun();
+	}
 }
 
 void ScripterCore::slotRunScript(const QString Script)

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h Tue Oct 21 20:23:25 2014
@@ -39,6 +39,7 @@
 	void StdScript(QString filebasename);
 	void RecentScript(QString fn);
 	void slotRunScriptFile(QString fileName, bool inMainInterpreter = false);
+	void slotRunPythonScript(); // needed for running python script from CLI
 	void slotRunScript(const QString Script);
 	void slotInteractiveScript(bool);
 	void slotExecute();

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp Tue Oct 21 20:23:25 2014
@@ -185,7 +185,6 @@
 #endif
 	scripterCore->setupMainInterpreter();
 	scripterCore->initExtensionScripts();
-	scripterCore->runStartupScript();
 	return true;
 }
 
@@ -734,7 +733,7 @@
 
 	// Measurement units understood by Scribus's units.cpp functions are exported as constant conversion
 	// factors to be used from Python.
-	for (int i = 0; i <= unitGetMaxIndex(); ++i)
+	for (int i = 0; i <= unitGetMaxIndex()-2; ++i)
 	{
 		PyObject* value = PyFloat_FromDouble(unitGetRatioFromIndex(i));
 		if (!value)
@@ -744,10 +743,10 @@
 		}
 		// `in' is a reserved word in Python so we must replace it
 		PyObject* name;
-		if (unitGetStrFromIndex(i) == "in")
+		if (unitGetUntranslatedStrFromIndex(i) == "in")
 			name = PyString_FromString("inch");
 		else
-			name = PyString_FromString(unitGetStrFromIndex(i).toLatin1().constData());
+			name = PyString_FromString(unitGetUntranslatedStrFromIndex(i).toLatin1().constData());
 		if (!name)
 		{
 			initscribus_failed(__FILE__, __LINE__);

Modified: trunk/Scribus/scribus/scribusapp.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/scribusapp.cpp
==============================================================================
--- trunk/Scribus/scribus/scribusapp.cpp (original)
+++ trunk/Scribus/scribus/scribusapp.cpp Tue Oct 21 20:23:25 2014
@@ -66,6 +66,7 @@
 #define ARG_PREFS "--prefs"
 #define ARG_UPGRADECHECK "--upgradecheck"
 #define ARG_TESTS "--tests"
+#define ARG_PYTHONSCRIPT "--python-script"
 
 #define ARG_VERSION_SHORT "-v"
 #define ARG_HELP_SHORT "-h"
@@ -81,6 +82,7 @@
 #define ARG_PREFS_SHORT "-pr"
 #define ARG_UPGRADECHECK_SHORT "-u"
 #define ARG_TESTS_SHORT "-T"
+#define ARG_PYTHONSCRIPT_SHORT "-py"
 
 // Qt wants -display not --display or -d
 #define ARG_DISPLAY_QT "-display"
@@ -204,10 +206,9 @@
 		uc.fetch();
 	}
 	//Dont run the GUI init process called from main.cpp, and return
-	if (!header)
-		useGUI=true;
-	else
-		return;
+	if (header)
+		std::exit(EXIT_SUCCESS);
+	useGUI = true;
 	//We are going to run something other than command line help
 	for(int i = 1; i < argsc; i++) {
 		arg = args[i];
@@ -244,14 +245,27 @@
 					std::cout << tr("File %1 does not exist, aborting.").arg(prefsUserFile).toLocal8Bit().data() << std::endl;
 				}
 				showUsage();
-				useGUI=false;
-				return;
+				std::exit(EXIT_FAILURE);
 			} else {
 				++i;
 			}
 		} else if (strncmp(arg.toLocal8Bit().data(),"-psn_",4) == 0)
 		{
 			// Andreas Vox: Qt/Mac has -psn_blah flags that must be accepted.
+		} else if (arg == ARG_PYTHONSCRIPT || arg == ARG_PYTHONSCRIPT_SHORT) {
+			pythonScript = QFile::decodeName(args[i + 1].toLocal8Bit());
+			if (!QFileInfo(pythonScript).exists()) {
+				showHeader();
+				if (pythonScript.left(1) == "-" || pythonScript.left(2) == "--") {
+					std::cout << tr("Invalid argument: ").toLocal8Bit().data() << pythonScript.toLocal8Bit().data() << std::endl;
+				} else {
+					std::cout << tr("File %1 does not exist, aborting.").arg(pythonScript).toLocal8Bit().data() << std::endl;
+				}
+				showUsage();
+				std::exit(EXIT_FAILURE);
+			} else {
+				++i;
+			}
 		} else {
 			fileName = QFile::decodeName(args[i].toLocal8Bit());
 			if (!QFileInfo(fileName).exists()) {
@@ -262,8 +276,7 @@
 					std::cout << tr("File %1 does not exist, aborting.").arg(fileName).toLocal8Bit().data() << std::endl;
 				}
 				showUsage();
-				useGUI=false;
-				return;
+				std::exit(EXIT_FAILURE);
 			}
 			else
 			{
@@ -283,8 +296,20 @@
 	processEvents();
 	ScCore->init(useGUI, swapDialogButtonOrder, filesToLoad);
 	int retVal=EXIT_SUCCESS;
-	if (useGUI)
+	/* TODO:
+	 * When Scribus is truly able to run without GUI
+	 * we should uncomment if (useGUI)
+	 * and delete if (true)
+	 */
+	// if (useGUI)
+	if (true)
 		retVal=ScCore->startGUI(showSplash, showFontInfo, showProfileInfo, lang, prefsUserFile);
+
+	// A hook for plugins and scripts to trigger on. Some plugins and scripts
+	// require the app to be fully set up (in particular, the main window to be
+	// built and shown) before running their setup.
+	emit appStarted();
+
 	return retVal;
 }
 
@@ -464,7 +489,8 @@
 	printArgLine(ts, ARG_SWAPDIABUTTONS_SHORT, ARG_SWAPDIABUTTONS, tr("Use right to left dialog button ordering (eg. Cancel/No/Yes instead of Yes/No/Cancel)") );
 	printArgLine(ts, ARG_UPGRADECHECK_SHORT, ARG_UPGRADECHECK, tr("Download a file from the Scribus website and show the latest available version.") );
 	printArgLine(ts, ARG_VERSION_SHORT, ARG_VERSION, tr("Output version information and exit") );
-	
+	printArgLine(ts, ARG_PYTHONSCRIPT_SHORT, QString(QString(ARG_PYTHONSCRIPT) + QString(" ") + tr("filename")).toLocal8Bit().constData(), tr("Run filename in Python scripter") );
+	printArgLine(ts, ARG_NOGUI_SHORT, ARG_NOGUI, tr("Do not start GUI") );
 	
 #if defined(_WIN32) && !defined(_CONSOLE)
 	printArgLine(ts, ARG_CONSOLE_SHORT, ARG_CONSOLE, tr("Display a console window") );

Modified: trunk/Scribus/scribus/scribusapp.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/scribusapp.h
==============================================================================
--- trunk/Scribus/scribus/scribusapp.h (original)
+++ trunk/Scribus/scribus/scribusapp.h Tue Oct 21 20:23:25 2014
@@ -69,6 +69,7 @@
 		bool neverSplashExists();
 		const QString& currGUILanguage() { return GUILang; }
 		ScDLManager* dlManager() { return m_scDLMgr; }
+		QString pythonScript; // script to be run in python from CLI
 
 	private:
 		ScribusCore* m_ScCore;
@@ -105,6 +106,9 @@
 
 	protected slots:
 		void downloadComplete(const QString& t);
+
+	signals:
+		void appStarted();
 };
 
 #endif

Modified: trunk/Scribus/scribus/scribuscore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/scribuscore.cpp
==============================================================================
--- trunk/Scribus/scribus/scribuscore.cpp (original)
+++ trunk/Scribus/scribus/scribuscore.cpp Tue Oct 21 20:23:25 2014
@@ -141,11 +141,6 @@
 		scribus->slotRaiseOnlineHelp();
 	}
 
-	// A hook for plugins and scripts to trigger on. Some plugins and scripts
-	// require the app to be fully set up (in particular, the main window to be
-	// built and shown) before running their setup.
-	emit appStarted();
-	
 	return EXIT_SUCCESS;
 }
 

Modified: trunk/Scribus/scribus/scribuscore.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=19604&path=/trunk/Scribus/scribus/scribuscore.h
==============================================================================
--- trunk/Scribus/scribus/scribuscore.h (original)
+++ trunk/Scribus/scribus/scribuscore.h Tue Oct 21 20:23:25 2014
@@ -142,11 +142,6 @@
 	bool m_HaveGS;
 	bool m_HavePngAlpha;
 	bool m_HaveTiffSep;
-	
-	
-signals:
-	void appStarted();
-
 };
 
 /*




More information about the scribus-commit mailing list