r17681 by jghali - #10804: Scribus crash opening 2 script at the same time

scribus-commit scribus-commit at lists.scribus.net
Wed Jul 4 20:23:53 UTC 2012


Author: jghali
Date: Wed Jul  4 20:23:53 2012
New Revision: 17681

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17681
Log:
#10804: Scribus crash opening 2 script at the same time

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin/pconsole.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h

Modified: trunk/Scribus/scribus/plugins/scriptplugin/pconsole.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17681&path=/trunk/Scribus/scribus/plugins/scriptplugin/pconsole.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/pconsole.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/pconsole.cpp Wed Jul  4 20:23:53 2012
@@ -14,13 +14,15 @@
 #include "pconsole.h"
 
 #include <QFileDialog>
-#include "scribus.h"
+#include "commonstrings.h"
 #include "prefsmanager.h"
 #include "prefsfile.h"
 #include "prefscontext.h"
+#include "scribus.h"
+#include "scribuscore.h"
+#include "util_icon.h"
+
 #include "ui/scmessagebox.h"
-#include "commonstrings.h"
-#include "util_icon.h"
 
 
 PythonConsole::PythonConsole( QWidget* parent)
@@ -125,6 +127,15 @@
 void PythonConsole::slot_runScript()
 {
 	outputEdit->clear();
+
+	//Prevent two scripts to be run concurrently or face crash!
+	if (ScCore->primaryMainWindow()->scriptIsRunning())
+	{
+		outputEdit->append( tr("Another script is already running...") );
+		outputEdit->append( tr("Please let it finish its task...") );
+		return;
+	}
+
 	parsePythonString();
 	emit runCommand();
 	commandEdit->textCursor().movePosition(QTextCursor::Start);
@@ -132,6 +143,14 @@
 
 void PythonConsole::slot_runScriptAsConsole()
 {
+	//Prevent two scripts to be run concurrently or face crash!
+	if (ScCore->primaryMainWindow()->scriptIsRunning())
+	{
+		outputEdit->append( tr("\n>>> Another script is already running...") );
+		outputEdit->append( tr("Please let it finish its task...") );
+		return;
+	}
+
 	parsePythonString();
 	commandEdit->clear();
 	// content is destroyed. This is to prevent overwriting

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17681&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp Wed Jul  4 20:23:53 2012
@@ -36,6 +36,8 @@
 
 ScripterCore::ScripterCore(QWidget* parent)
 {
+	menuMgr = NULL;
+
 	pcon = new PythonConsole(parent);
 	scrScripterActions.clear();
 	scrRecentScriptActions.clear();
@@ -84,6 +86,23 @@
 	buildRecentScriptsMenu();
 }
 
+void ScripterCore::enableMainWindowMenu()
+{
+	if (!menuMgr)
+		return;
+	menuMgr->setMenuEnabled("ScribusScripts", true);
+	menuMgr->setMenuEnabled("RecentScripts", true);
+	scrScripterActions["scripterExecuteScript"]->setEnabled(true);
+}
+
+void ScripterCore::disableMainWindowMenu()
+{
+	if (!menuMgr)
+		return;
+	menuMgr->setMenuEnabled("ScribusScripts", false);
+	menuMgr->setMenuEnabled("RecentScripts", false);
+	scrScripterActions["scripterExecuteScript"]->setEnabled(false);
+}
 
 void ScripterCore::buildScribusScriptsMenu()
 {
@@ -223,6 +242,11 @@
 
 void ScripterCore::slotRunScriptFile(QString fileName, bool inMainInterpreter)
 {
+	// Prevent two scripts to be run concurrently or face crash!
+	if (ScCore->primaryMainWindow()->scriptIsRunning())
+		return;
+	disableMainWindowMenu();
+
 	PyThreadState *state = NULL;
 	QFileInfo fi(fileName);
 	QByteArray na = fi.fileName().toLocal8Bit();
@@ -341,11 +365,18 @@
 		//PyEval_RestoreThread(stateo);
 //		qApp->restoreOverrideCursor();
 		ScCore->primaryMainWindow()->setScriptRunning(false);
-	}	
+	}
+
+	enableMainWindowMenu();
 }
 
 void ScripterCore::slotRunScript(const QString Script)
 {
+	// Prevent two scripts to be run concurrently or face crash!
+	if (ScCore->primaryMainWindow()->scriptIsRunning())
+		return;
+	disableMainWindowMenu();
+
 	ScCore->primaryMainWindow()->propertiesPalette->unsetDoc();
 	ScCore->primaryMainWindow()->pagePalette->setView(NULL);
 	ScCore->primaryMainWindow()->setScriptRunning(true);
@@ -412,6 +443,8 @@
 			Py_XDECREF(result);
 	}
 	ScCore->primaryMainWindow()->setScriptRunning(false);
+
+	enableMainWindowMenu();
 }
 
 void ScripterCore::slotInteractiveScript(bool visible)

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17681&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h Wed Jul  4 20:23:53 2012
@@ -24,7 +24,10 @@
 public:
 	ScripterCore(QWidget* parent);
 	~ScripterCore();
+
 	void addToMainWindowMenu(ScribusMainWindow *);
+	void enableMainWindowMenu();
+	void disableMainWindowMenu();
 
 	/** @brief String representation of result returned by last python console command */
 	QString returnString;




More information about the scribus-commit mailing list