[scribus] Python scripter - scribus.setFont() and scribus.setTextAlignment() ? -- Solution
Gregory Pittman
gpittman at iglou.com
Fri Jun 5 01:52:32 UTC 2015
I somehow lost this email from my client, but here it is copied from the
Archives:
*************************
I am trying to run the following (very simple) script:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
try:
import scribus
except ImportError:
print "This script only works from within Scribus"
sys.exit(1)
n = scribus.selectionCount()
for count in range(0,n):
textbox = scribus.getSelectedObject(count)
scribus.messageBox('Error:', textbox);
scribus.setFont('Arial Regular', textbox)
scribus.setTextAlignment(scribus.ALIGN_CENTERED, textbox)
scribus.setTextColor("White", textbox)
scribus.setFillColor("Red", textbox)
However it fails after one iteration. The error message is:
Traceback (most recent call last):
File "<string>", line 8, in <module>
File "/home/.../SetTableHeading.py", line 17, in <module>
scribus.setFont('Arial Regular', textbox)
NoValidObjectError: Cannot use empty string for object name when there is
no selection
If I remove the function calls scribus.setFont() and
scribus.setTextAlignment(), the script runs fine, but I dont know why...
I am running Scribus 1.4.3 and python 2.7.6 under Ubuntu 14.04.2 LTS.
I am not able to find any solution to this - any suggestions?
regards,
Anders
*****************************
I'm not quite sure why this doesn't work, but I am able to accomplish
what you're looking for (I think) with a modified syntax. Basically,
instead of relying on the count of the selection, I create a list of
frame names, then feed that list into your text manipulations...
*************
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
try:
import scribus
except ImportError:
print "This script only works from within Scribus"
sys.exit(1)
n = scribus.selectionCount()
boxes = []
for x in range(n):
frame = scribus.getSelectedObject(x)
boxes.append(frame)
for textbox in boxes:
scribus.messageBox('Error:', textbox);
scribus.setFont('Arial Regular', textbox)
scribus.setTextAlignment(scribus.ALIGN_CENTERED, textbox)
scribus.setTextColor("White", textbox)
scribus.setFillColor("Red", textbox)
*************
Greg
More information about the scribus
mailing list