Index: scribus/main_nix.cpp =================================================================== --- scribus/main_nix.cpp (revision 19413) +++ scribus/main_nix.cpp (working copy) @@ -37,6 +37,7 @@ #include "scribus.h" #include "scconfig.h" +#include "scraction.h" // need to be able to trigger action for scripter to run from CLI int mainApp(int argc, char **argv); void initCrashHandler(); @@ -81,7 +82,13 @@ int appRetVal=app.init(); if (appRetVal==EXIT_FAILURE) return(EXIT_FAILURE); - return app.exec(); + if (!app.pythonScript.isNull()) + { + if (ScCore->primaryMainWindow()->scrActions.contains("scripterRunPythonScript")) + ScCore->primaryMainWindow()->scrActions.value("scripterRunPythonScript")->trigger(); + } + else + return app.exec(); } return EXIT_SUCCESS; } Index: scribus/main_win32.cpp =================================================================== --- scribus/main_win32.cpp (revision 19413) +++ scribus/main_win32.cpp (working copy) @@ -48,6 +48,7 @@ #include "scribus.h" #include "scconfig.h" +#include "scraction.h" // need to be able to trigger action for scripter to run from CLI #include #include @@ -112,7 +113,13 @@ { appRetVal = app.init(); if (appRetVal != EXIT_FAILURE) - appRetVal = app.exec(); + if (!app.pythonScript.isNull()) + { + if (ScCore->primaryMainWindow()->scrActions.contains("scripterRunPythonScript")) + ScCore->primaryMainWindow()->scrActions.value("scripterRunPythonScript")->trigger(); + } + else + appRetVal = app.exec(); } #ifndef _DEBUG } Index: scribus/plugins/scriptplugin/scriptercore.cpp =================================================================== --- scribus/plugins/scriptplugin/scriptercore.cpp (revision 19413) +++ scribus/plugins/scriptplugin/scriptercore.cpp (working copy) @@ -32,6 +32,7 @@ #include "prefscontext.h" #include "prefstable.h" #include "prefsmanager.h" +#include "scribusapp.h" // need it to acces ScQApp->pythonScript ScripterCore::ScripterCore(QWidget* parent) { @@ -57,6 +58,10 @@ QObject::connect( scrScripterActions["scripterShowConsole"], SIGNAL(toggled(bool)) , this, SLOT(slotInteractiveScript(bool)) ); QObject::connect( scrScripterActions["scripterAboutScript"], SIGNAL(triggered()) , this, SLOT(aboutScript()) ); + // Create an action that will run python file from CLI + ScCore->primaryMainWindow()->scrActions.insert("scripterRunPythonScript", new ScrAction(this)); + QObject::connect( ScCore->primaryMainWindow()->scrActions.value("scripterRunPythonScript"), SIGNAL(triggered()) , this, SLOT(slotRunPythonScript()) ); + SavedRecentScripts.clear(); ReadPlugPrefs(); @@ -228,7 +233,7 @@ void ScripterCore::runScriptDialog() { QString fileName; - QString curDirPath = QDir::currentPath(); + // QString curDirPath = QDir::currentPath(); RunScriptDialog dia( ScCore->primaryMainWindow(), m_enableExtPython ); if (dia.exec()) { @@ -244,7 +249,7 @@ } rebuildRecentScriptsMenu(); } - QDir::setCurrent(curDirPath); + // QDir::setCurrent(curDirPath); FinishScriptRun(); } @@ -298,7 +303,7 @@ global_state = PyThreadState_Get(); state = Py_NewInterpreter(); // Chdir to the dir the script is in - QDir::setCurrent(fi.absolutePath()); + // QDir::setCurrent(fi.absolutePath()); // Init the scripter module in the sub-interpreter initscribus(ScCore->primaryMainWindow()); } @@ -404,6 +409,13 @@ enableMainWindowMenu(); } +// needed for running scriptfrom CLI - this is activated by action from main_nix.cpp +void ScripterCore::slotRunPythonScript() +{ + slotRunScriptFile(ScQApp->pythonScript); + FinishScriptRun(); +} + void ScripterCore::slotRunScript(const QString Script) { // Prevent two scripts to be run concurrently or face crash! Index: scribus/plugins/scriptplugin/scriptercore.h =================================================================== --- scribus/plugins/scriptplugin/scriptercore.h (revision 19413) +++ scribus/plugins/scriptplugin/scriptercore.h (working copy) @@ -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(); Index: scribus/scribus.cpp =================================================================== --- scribus/scribus.cpp (revision 19413) +++ scribus/scribus.cpp (working copy) @@ -285,7 +285,8 @@ setAttribute(Qt::WA_KeyCompression, false); setWindowIcon(loadIcon("AppIcon.png")); scrActionGroups.clear(); - scrActions.clear(); + // DO NOT clear actions : scripter plugin has created one already! +// scrActions.clear(); scrRecentFileActions.clear(); scrRecentPasteActions.clear(); scrWindowsActions.clear(); Index: scribus/scribusapp.cpp =================================================================== --- scribus/scribusapp.cpp (revision 19413) +++ scribus/scribusapp.cpp (working copy) @@ -61,6 +61,7 @@ #define ARG_SWAPDIABUTTONS "--swap-buttons" #define ARG_PREFS "--prefs" #define ARG_UPGRADECHECK "--upgradecheck" +#define ARG_PYTHONSCRIPT "--python-script" #define ARG_VERSION_SHORT "-v" #define ARG_HELP_SHORT "-h" @@ -75,6 +76,7 @@ #define ARG_SWAPDIABUTTONS_SHORT "-sb" #define ARG_PREFS_SHORT "-pr" #define ARG_UPGRADECHECK_SHORT "-u" +#define ARG_PYTHONSCRIPT_SHORT "-py" // Qt wants -display not --display or -d #define ARG_DISPLAY_QT "-display" @@ -218,6 +220,21 @@ } 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(argv()[i + 1]); + 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(); + useGUI=false; + return; + } else { + ++i; + } } else { fileName = QFile::decodeName(argv()[i]); if (!QFileInfo(fileName).exists()) { @@ -428,8 +445,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") ); - #if defined(_WIN32) && !defined(_CONSOLE) printArgLine(ts, ARG_CONSOLE_SHORT, ARG_CONSOLE, tr("Display a console window") ); #endif Index: scribus/scribusapp.h =================================================================== --- scribus/scribusapp.h (revision 19413) +++ scribus/scribusapp.h (working copy) @@ -67,6 +67,7 @@ bool neverSplashExists(); const QString& currGUILanguage() {return GUILang;}; ScDLManager* dlManager() { return m_scDLMgr; } + QString pythonScript; // script to be run in python from CLI public slots: