Mantis Issue Tracking for Scribus
· Hosting provided by / Øverby Consulting ·

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0012572Scribus-public14-Jul-29 21:4414-Sep-17 05:31
Assigned Tojghali 
PlatformLinuxOSFedora OS Version
Product Version 
Target VersionFixed in Version 
Summary0012572: [patch] Add a --python-script command line option to run a script and exit
DescriptionThese patches were written by Juraj Fedel and posted for Scribus 1.4.4.
I have posted another set of patches relative to Scribus 1.5.0svn of 28 July 2014.
Additional InformationFrom [^]

You can create template scribus document 'mydoc.sla' with two text
frames and this small python script '' in the same directory:

import scribus
scribus.setText('Name', 'Text1') # get 'Name' and 'Address' from database
scribus.setText('Address', 'Text2')
pdf = scribus.PDFfile()
pdf.file = 'output1.pdf'

Then run scribus as folow:
scribus --python-script

and you have your output1.pdf file created!

- Use only python script without bugs (he, he :)
- You will anyway find some limitation because scribus really is not in
  its core coded for use without GUI

I have been posting this or similar solution since 2006 (and Scribus
version 1.2 I was using at that time).
TagsNo tags attached.
Attached Files? file icon scribus-cmd-wb-28jul14.pat [^] (6,294 bytes) 14-Jul-29 21:44
patch file icon Run-python-script-from-CLI-4aug14.patch [^] (8,558 bytes) 14-Aug-05 02:46 [Show Content]
gz file icon patch_bundle_v150-20aug14.tar.gz [^] (10,361 bytes) 14-Aug-21 01:42
patch file icon 0013-Do-not-show-messagebox-when-python-script-raise-an-e.patch [^] (3,904 bytes) 14-Aug-29 04:31 [Show Content]
patch file icon 0014-Test-to-convert-qmessagebox.patch [^] (2,201 bytes) 14-Aug-29 04:45 [Show Content]
? file icon [^] (1,323 bytes) 14-Aug-29 05:43
patch file icon 0015-All-in-one-Run-python-script-from-CLI_v150.patch [^] (11,766 bytes) 14-Sep-02 03:48 [Show Content]
? file icon [^] (1,108 bytes) 14-Sep-02 03:48
? file icon 0016-scribus15-20140906-062901-messagebox.pat [^] (114,357 bytes) 14-Sep-06 06:55

- Relationships
related to 0000238assignedcbradney New CL option: scribus --to-pdf <scribus-file> <output.pdf> 
related to 0000967assignedcbradney CLI option -p 
related to 0009331new Allow command line switch so that a user may specify a start-up script 
related to 0007741new Provide a way to run Scribus script from PyDev in Eclipse 
related to 0012594assignedjghali [patch] Add a --python-script command line option to Scribus 1.4.5svn to run a script and exit 

-  Notes
william (reporter)
14-Jul-31 23:36

The patches are in the link at the top "Attached Files scribus-cmd-wb-28jul14.pat [^] (6,294 bytes) 14-Jul-29 21:44".
It was the first time that I used Mantis, and when I made the entry, the "Attached Files" seemed a logical place for the patch.

Juraj said that he is OK with my making what changes are necessary to have the patch accepted.

a.l.e posted earlier posted several objections to the patches:

1) Several comments have the initials "JF". I can change them to "Juraj Fedel".

2) I think that removing the "ugly hack" of testing app.pythonScript.isNull() instead of app.useGUI affects Scribus at a much more systemic level and would change this 150 line patch that affects 6 files into a several thousand line patch that affects a large number of files and should be its own issue in Mantis related to a truly headless version of Scribus.

Also, maybe it is not that ugly at all -- the same mechanism would allow a --initial-python-script that could run before continuing with the GUI, so testing app.pythonScript.isNull() might be more appropriate than testing app.useGUI.

3) The comments say Linux-only because it was never tested under Windows rather than because it does anything operating system specific. Unfortunately, I do not have a Windows build environment either.
Since the patch does not add any new files, I think that the Windows build scripts will probably not need changes.
Another posting said to check if python is enabled. Does that mean testing COMPILE_PYTHON (in config.h) and additionally on Windows, checking HAVE_PYTHON (in win32/vc*/win-config.h)?
I can add the #if defined() tests. It looks like no variables are declared conditionally on the presence of python, so maybe only the command line parsing needs to check for python and exit with a "python is not enabled" message if the build does not include python scripting.
william (reporter)
14-Aug-05 03:00

I uploaded a new set of patches from Juraj in the attachment "Run-python-script-from-CLI-4aug14.patch".
These patches apply cleanly against the current Scribus 1.5.0svn.
The patches should satisfy the earlier objections.
1) Juraj removed all occurrences of his name and initials.
2) The "hack" comment is removed. It is not really a hack.
3) The Linux-only comment is removed. The patches contain no operating-system dependent system calls. The patches now update main_win32.cpp similarly to main_nix.cpp.

In addition, the python script target of --python-script can now have a path. In the original version, it had to be in the current directory.
ale (manager)
14-Aug-05 17:27


let's see if the team is willing to apply this patch.

i think it can be of some use, even if the GUI still fires up.

personally, i still would love to see a "scribus" that really works from the command line, but i'm more and more convinced that such a tool should be written from scratch.
let's see if it will happen one day!
Kunda (developer)
14-Aug-06 15:35

Changing status to 'feedback' to trigger a discussion.
william (reporter)
14-Aug-21 02:21

I uploaded an improved set of patches for Scribus 1.5 from Juraj as patch_bundle_v150-20aug14.tar.gz

The first patch in the set replaces the original patch to add a '--python-script file' command line option.
The seventh patch adds python functions to save and read PDF options.
The eleventh patch enables the '--no-gui' command line option.
The other patches fix problems in Scribus that become apparent when you try to script exporting documents to PDF.

I tested the patches with Scribus 1.5.0svn from August 20, 2014.

0001: Add the '--python-script file' CLI option to run 'file' as python script.
0002: Now help(scribus.newDocument) in python console runs without error.
0003: Translate strings to variable names with unitGetUntranslatedStrFromIndex instead of unitGetStrFromIndex so python scripts are not dependent on the locale.
0004: Fix the help message for scribus.PDFfile.
0005: Fix reading the prefs file. Scribus was opening the wrong file.
0006: Set ScribusMainWindow::ScriptRunning earlier in the initialization process. Scribus was using it before it was initialized.
0007: Add two python commands readPDFOptions(file) and savePDFOptions(file).
0008: Fix errors when reading PDFOptions.
0009: Fix errors in error messages related to reading PDFOptions files.
0010: Escape HTML codes in scripter error messages so error messages enclosed by <> show correctly.
0011: Enable the --no-gui CLI option so 'scribus --no-gui --python-script' runs a script and exits without starting the GUI.
0012: Update the python scripter to allow exporting documents in PDF 1.5. Scribus limited the 'version' variable to 14 instead of 15.

To test the pdf version patch, create a mydoc.sla as described in the initial note and run the script below and then check that output1.pdf is PDF 1.5.

import scribus
scribus.setText('Name', 'Text1') # get 'Name' and 'Address' from database
scribus.setText('Address', 'Text2')
pdf = scribus.PDFfile()
pdf.file = 'output1.pdf'
pdf.version = 15

To test the PDF options patches, run the script below without and with an open document. Without an open document, it should raise a NoDocOpenError error and not crash Scribus. With an open document, it should create and then load an XML with PDF preferences.

import scribus
william (reporter)
14-Aug-29 04:53

I uploaded an additional patch from Juraj
0013: Do not show messagebox when python script raise an error

With this patch, when Scribus is run with --no-gui, Scribus writes python tracebacks to stderr.
william (reporter)
14-Aug-29 04:59

I uploaded a test patch that I wrote to print the error message for scribus.openDoc() to stderr through qWarning() instead of to a dialog through QMessageBox when Scribus is run with --no-gui (ScribusQApp::useGUI is false).
0014: Test converting a QMessageBox error to qWarning when not using the GUI

Scribus has about 250 calls to QMessageBox that would need to be converted. In my test, I had to copy the message string. Is there a way to wrap QMessageBox similar to how scdebug.h wraps QDebug?
william (reporter)
14-Aug-29 05:48

I uploaded an example script that makes Scribus into a web server that listens on http://localhost:8080/ [^]
It is only a test and returns a "Hello World!" message, but it shows an example of what is possible.
Kunda (developer)
14-Aug-29 06:09

Removed the 'Warning: Linux Only' from the 'Additional Information' field of this issue summary as per OPs comment in 0012572:0033180
This is not a linux only patch now because "The patches contain no operating-system dependent system calls. The patches now update main_win32.cpp similarly to main_nix.cpp."
jghali (administrator)
14-Aug-30 03:26

For now, i applied following patches:

The three last ones need to be discussed a bit more and I will wait for the return of vacation of other team members.
Kunda (developer)
14-Aug-30 03:34

Thanks jghali, william and Juraj !!
So the patches in question are:
william (reporter)
14-Aug-30 04:01


Can you also apply the corresponding patches in [^] to Scribus 1.4?

What are the issues with the patches
0011-Enable-the-use-of-no-gui-CLI-option.patch and
What would it take to have them approved?

Is the issue with 0003-Do-not-use-and-xB0-as-identifier-in-python.patch that it might affect existing scripts? Would it help to have an example where this patch is required?

Is there a better way to do what I did in the 14th patch?
Could I make a ScribusMessageBox class that inherits from QMessageBox and adds a scribusWarning() function that calls either QMessageBox::warning or qWarning based on ScribusQApp::useGUI?
william (reporter)
14-Sep-02 03:55

Juraj has a new patch 0015 that replaces and obsoletes patches 0001, 0011 and 0013. This patch is cleaner and works with the current SVN source.

william (reporter)
14-Sep-02 04:02

Juraj provided examples of the necessity of the patch 0003-Do-not-use-and-xB0-as-identifier-in-python.patch

1) If you open the python scripting console with Script -> Show Console and then run
you get the python error

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/lib64/python2.7/", line 459, in __call__
    return*args, **kwds)
  File "/usr/lib64/python2.7/", line 1745, in __call__
  File "/usr/lib64/python2.7/", line 1792, in help
    else: doc(request, 'Help on %s:')
  File "/usr/lib64/python2.7/", line 1529, in doc
    pager(render_doc(thing, title, forceload))
  File "/usr/lib64/python2.7/", line 1524, in render_doc
    return title % desc + '\n\n' + text.document(object, name)
  File "/usr/lib64/python2.7/", line 326, in document
    if inspect.ismodule(object): return self.docmodule(*args)
  File "/usr/lib64/python2.7/", line 1113, in docmodule
    result = result + self.section('DATA', join(contents, '\n'))
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb0 in position 4810: invalid start byte

2) If you run the commands
  import scribus
it works in English but gets errors in some other languages.
See the attached script.

# Test variable name translations
# This script is a test case for patch 0003
# in [^] (1.5)
# and [^] (1.4)
# You can run this script from the command line
# (if you have applied the command line patches)
# or from the Scripter menu item.
# This script runs OK with English strings:
# scribus-1.4.4 -g -py -l en
# 0.0352777777778
# 0.352777777778
# The script fails with Russian strings:
# scribus-1.4.4 -g -py -l ru
# 0.0352777777778
# Traceback (most recent call last):
# File "<string>", line 8, in <module>
# File "", line 3, in <module>
# print
# AttributeError: 'module' object has no attribute 'mm'
# The script fails with a different error with Ukrainian strings:
# scribus-1.4.4 -g -py -l uk
# Traceback (most recent call last):
# File "<string>", line 8, in <module>
# File "", line 2, in <module>
# print
# AttributeError: 'module' object has no attribute 'cm'

import scribus
jghali (administrator)
14-Sep-02 08:57

>> What would it take to have them approved?

Well someone other than me should review them. I see one clear issue in the first patch tho: not setting current directory is something which would likely break existing scripts.
william (reporter)
14-Sep-06 07:22

I uploaded a patch eliminate calls to QMessageBox when there is no GUI.

This patch applies after 0003-Do-not-use-and-xB0-as-identifier-in-python and 0015-All-in-one-Run-python-script-from-CLI_v150.

This patch also replaces my test 0014-Test-to-convert-qmessagebox.

This patch creates a derived class ScribusMessageBox that uses QMessageBox when there is a GUI and qDebug when there is no GUI. Most of the changes only replace QMessageBox with ScribusMessageBox. I simplified ScribusMessageBox by not implementing obsolete member functions of QMessageBox. When I found calls to obsolete member functions, I updated them.

The purpose is to allow shell scripts to run Scribus without hanging if Scribus gets an error.
cbradney (administrator)
14-Sep-15 22:05

I'm going to help Jean review this. First.. can someone please identify all the patch files you want reviewed/tested/committed and zip them in one archive. Include a description of each patch (even if its just a copy of the above text).

Reason I'm asking this: We have many bugs with lots of patches and many are different versions of each other. This will clear this up for me and save my time.

Kunda (developer)
14-Sep-15 23:08

I just tried to understand what has been done and what is left to be done and now I"m a little confused :/ Looking forward to seeing a clear breakdown of this issue. It's important to understand how many different files are effected implementing this patch.
william (reporter)
14-Sep-16 01:41


Thanks, most of the patches to review for inclusion have already been combined as
That patch contains all but one of the remaining patches by Juraj that have not already been committed. Can you please review it and either commit it or say what needs to be changed?


Also, patch 0003-Do-not-use-and-xB0-as-identifier-in-python.patch needs to be reviewed for being committed. It is separate because it does not depend on the other patches, and one of the reviewers had a question about whether it was necessary, and I posted a python script to demonstrate the issue.


In addition, I have an additional patch 0016-scribus15-20140906-062901-messagebox.pat that replaces QMessageBox with a class that calls QMessageBox when there is a GUI and calls qDebug() otherwise. I am still working on it, so please don't commit 0016, but I would be interested in any comments. I am changing it to write to cerr instead of qDebug(), and to allow an additional default button when there is no GUI because some of the dialogs in the GUI default to not continuing the command.
Kunda (developer)
14-Sep-17 01:53
edited on: 14-Sep-17 01:54

First I want to say, this is very exciting development. Thank you to all that are involved.
Secondly, I interpreted Craig asking to simplify things which it looks like you a degree.

I need to be careful here because I may be talking out of my behind...but maybe implementing 1 thing at at time..instead of introducing what maybe considered 'context switching'. I've heard this also called a "multi-headed, kitten-eating monster of a patch" (see: [^])

I'm sure Craig will comment on what he is specifically needing elaborations on. Perhaps an IRC session on this topic would be merited?

Edit: spelling

william (reporter)
14-Sep-17 05:31

Juraj originally submitted 13 small patches. After the majority were accepted, he had to rebase the remaining patches, and he made patch 0015 with the majority of the remaining patches. It is not a monster patch. It mostly adds parsing for the command line arguments --no-gui and --python-script.

My patch to replace QMessageBox is large, mainly because Scribus has about 250 calls to QMessageBox.

If it would help to have an IRC session, the best times for me for the next two months are between 3pm and 9pm US Eastern Time.

- Issue History
Date Modified Username Field Change
14-Jul-29 21:44 william New Issue
14-Jul-29 21:44 william File Added: scribus-cmd-wb-28jul14.pat
14-Jul-30 05:47 Kunda Relationship added related to 0000238
14-Jul-30 05:47 Kunda Relationship added related to 0000967
14-Jul-30 05:48 Kunda Relationship added related to 0009331
14-Jul-31 21:21 JLuc Note Added: 0033117
14-Jul-31 23:36 william Note Added: 0033119
14-Aug-05 02:46 william File Added: Run-python-script-from-CLI-4aug14.patch
14-Aug-05 03:00 william Note Added: 0033180
14-Aug-05 17:27 ale Note Added: 0033182
14-Aug-06 15:35 Kunda Note Added: 0033188
14-Aug-06 15:35 Kunda Status new => feedback
14-Aug-07 08:16 christoph_s Assigned To => jghali
14-Aug-07 08:16 christoph_s OS => Fedora
14-Aug-07 08:16 christoph_s Platform => Linux
14-Aug-07 08:26 christoph_s Status feedback => new
14-Aug-07 08:27 christoph_s Status new => assigned
14-Aug-08 06:21 Kunda Relationship added related to 0012594
14-Aug-09 22:36 jghali Project Contributor Builds => Scribus
14-Aug-21 01:42 william File Added: patch_bundle_v150-20aug14.tar.gz
14-Aug-21 02:21 william Note Added: 0033306
14-Aug-29 04:31 william File Added: 0013-Do-not-show-messagebox-when-python-script-raise-an-e.patch
14-Aug-29 04:45 william File Added: 0014-Test-to-convert-qmessagebox.patch
14-Aug-29 04:53 william Note Added: 0033359
14-Aug-29 04:59 william Note Added: 0033360
14-Aug-29 05:43 william File Added:
14-Aug-29 05:48 william Note Added: 0033362
14-Aug-29 06:09 Kunda Note Added: 0033363
14-Aug-29 06:09 Kunda Category General => -
14-Aug-29 06:09 Kunda Additional Information Updated View Revisions
14-Aug-30 03:26 jghali Note Added: 0033372
14-Aug-30 03:34 Kunda Note Added: 0033373
14-Aug-30 04:01 william Note Added: 0033375
14-Sep-02 03:48 william File Added: 0015-All-in-one-Run-python-script-from-CLI_v150.patch
14-Sep-02 03:48 william File Added:
14-Sep-02 03:55 william Note Added: 0033447
14-Sep-02 04:02 william Note Added: 0033448
14-Sep-02 08:57 jghali Note Added: 0033450
14-Sep-06 06:55 william File Added: 0016-scribus15-20140906-062901-messagebox.pat
14-Sep-06 07:22 william Note Added: 0033537
14-Sep-09 15:09 JLuc Note Deleted: 0033117
14-Sep-13 17:17 Kunda Relationship added related to 0007741
14-Sep-15 22:05 cbradney Note Added: 0033703
14-Sep-15 23:08 Kunda Note Added: 0033706
14-Sep-16 01:41 william Note Added: 0033710
14-Sep-17 01:53 Kunda Note Added: 0033717
14-Sep-17 01:54 Kunda Note Edited: 0033717 View Revisions
14-Sep-17 05:31 william Note Added: 0033721

Copyright © 2000 - 2014 MantisBT Team
Powered by Mantis Bugtracker