Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions scribus/plugins/scriptplugin/samples/3columnA4.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@
# Do so _after_ the 'import scribus' and only import the names you need, such
# as commonly used constants.
import scribus
except ImportError,err:
print "This Python script is written for the Scribus scripting interface."
print "It can only be run from within Scribus."
sys.exit(1)

def main(argv):
"""This is a simple way to demonstrate creating a doc on the fly. """

pass # <--- Delete this line
#########################
# YOUR IMPORTS GO HERE #
#########################

import sys

try:
from scribus import *
#########################
# YOUR IMPORTS GO HERE #
#########################
except ImportError:
print "This script only runs from within Scribus."
sys.exit(1)
Expand Down
11 changes: 5 additions & 6 deletions scribus/plugins/scriptplugin/samples/wordcount.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import re

TITLE = "Word count"
messageBox(TITLE, "running", ICON_INFORMATION)

def wordsplit(text):
word_pattern = "([A-Za-zäöüÄÖÜß]+)"
Expand All @@ -35,8 +36,7 @@ def main():
text = getText(getSelectedObject(i))
words += len(wordsplit(text))
except WrongFrameTypeError:
if sel_count == 1:
# If there's only one object selected, display a message
if sel_count == 1: # If there's only one object selected, display a message
messageBox(TITLE, "Can't count words in a non-text frame", ICON_INFORMATION);
sys.exit(1)
else:
Expand All @@ -52,10 +52,9 @@ def main():
words += len(wordsplit(text))
except WrongFrameTypeError:
pass # ignore the error, it just wasn't a frame we can count

if words == 0: words = "No"
messageBox(TITLE, "%s words counted in %s" % (words, source),
ICON_INFORMATION)
if (words == 0):
words = "No"
messageBox(TITLE, "%s words counted in %s" % (words, source), ICON_INFORMATION)


if __name__ == '__main__':
Expand Down
16 changes: 2 additions & 14 deletions scribus/plugins/scriptplugin/scriptercore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,16 +262,8 @@ void ScripterCore::slotRunScriptFile(QString fileName, QStringList arguments, bo

// Make sure sys.argv[0] is the path to the script
arguments.prepend(na.data());

// and tell the script if it's running in the main intepreter or
// a subinterpreter using the second argument, ie sys.argv[1]
if (inMainInterpreter)
arguments.insert(1,QString("ext"));
else
arguments.insert(1,QString("sub"));

//convert arguments (QListString) to char** for Python bridge
/* typically arguments == ['path/to/script.py','ext','--argument1','valueforarg1','--flag']*/
/* typically arguments == ['path/to/script.py','--argument1','valueforarg1','--flag']*/
char **comm = new char*[arguments.size()];
for (int i = 0; i < arguments.size(); i++)
{
Expand Down Expand Up @@ -431,11 +423,7 @@ void ScripterCore::slotRunScript(const QString Script)
"In file tools/qgarray.cpp, line 147: Out of memory"
Anyway - sys.argv is set above
char* comm[1];
comm[0] = const_cast<char*>("scribus");
// the scripter console runs everything in the main interpreter
// tell the code it's running there.
comm[1] = const_cast<char*>("ext");
PySys_SetArgv(2, comm); */
comm[0] = const_cast<char*>("scribus"); */
// then run the code
PyObject* m = PyImport_AddModule((char*)"__main__");
if (m == NULL)
Expand Down