[scribus] Python scripter - scribus.setFont() and scribus.setTextAlignment() ? -- Solution
Gregory Pittman
gpittman at iglou.com
Fri Jun 5 13:51:16 UTC 2015
On 06/04/2015 10:38 PM, William Bader wrote:
>
>
>> Date: Thu, 4 Jun 2015 21:52:32 -0400
>> From: gpittman at iglou.com
>> To: scribus at lists.scribus.net
>> Subject: [scribus] Python scripter - scribus.setFont() and scribus.setTextAlignment() ? -- Solution
>>
>> 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...
>
> Arial is a Windows font, and some Linux systems do not have it.
> I have the code below in one of my test scripts.
> try:
> scribus.setFont("Arial Regular", txt)
> except:
> try:
> scribus.setFont("FreeSans Medium", txt)
> except:
> pass
The font was not the issue. I changed it to one on my system, and it
still did the same thing. Arial would be a safe choice on Windows.
There are some other features which could also be added, such as testing
to make sure that the selected objects are all text frames. At the same
time, for my own personal scripts used for very small tasks, I don't
always put in all the error detections that I might, since at some point
they take up more lines than the actual important parts.
Greg
More information about the scribus
mailing list