[SOLVED] scribus.setTextColor("Red",myFrame) ?

Previous topic - Next topic

hjh

Hi

I wonder how to set the text color in a frame. I have a new empty document A4 landscape with units set to millimeters run the script given below.
I run the script given below in the console window using Scribus version 1.6.4.
The script does not set the color
scribus.setTextColor("Red",myFrame)I guess I have to make that color available first, but how do I do that?

Thank you for your answer in advance
--Hannes

import scribus
# CC0 Public domain
origX = 15
origY = 25
i = 0
boxHeight = 6
boxWidth = 50
endValueY = origY + 31 * boxHeight
for y in range(origY,endValueY,boxHeight):
    i = i + 1
    myFrame = "box"+str(i)
    scribus.createText(origX,y,boxWidth,boxHeight,myFrame)
    scribus.setLineColor("Black",myFrame)
    scribus.setText(str(i),myFrame)
    scribus.setTextColor("Red",myFrame)
    scribus.setFontSize(12,myFrame)

P.S. Noteworthy is also that the script only runs if the first line in the console window is left blank.

a.l.e

scribus.setTextColor("Red")

does work here in the Scripter console with the text selection in the current text frame and also on the full current text frame.

you might need to check that myFrame points to an existing frame and that the "Red" color does exist in your document...

with some minor tweaking (the indents seem to have some strange characters...) your script above works for me.

and i can replicate your issue with the first line having to be blank.
but if i remove the end of lines, then it works.
there seems to be some hidden chars at the end of each line (maybe just a \r\l or \r\n or similar)

hjh

#2
Hi Ale

Thank your for testing and confirming that setTextColor(...) works for you. This helped me to also get it working.

The issue was that I need to define the color 'Red' which I did with
scribus.defineColorRGB("Red", 255, 0, 0) . See  complete script at the end of this message.

Regarding the need for a blank line as first line in the script: I am using the Scribus version 1.6.4 on Microsoft Windows and indeed the line ends are CR/LF. This is the regular behavior if you copy some text from for example Notepad.

I did a check with Notepad++ (with 'View -> Show symbol -> Show end of line' activated.
I tested both : a variant with CR only and a second one with LF only. Then the blank line was indeed not necessary.
For a MSWindows user this is slightly inconvenient if copy/past into the script console window does not work without having a blank line on top. However I found out that the first line may also be a comment line.

So to summarize
scribus.setTextColor("Red",myFrame) works if a color "Red" has been defined, either by the script or in the document through the menu 'Edit -> Colors and fills...".

And there is a restriction in MSWindows with the script console window making it necessary to have a blank line or just a comment line as first line if a script is pasted into it. Besides that however it is perfectly possible to paste scripts copied from Notepad having CR/LF line endings.

--Hannes

Fixed example script:
#
import scribus
# CC0 Public domain
origX = 15
origY = 25
i = 0
scribus.defineColorRGB("Red", 255, 0, 0)
boxHeight = 6
boxWidth = 50
endValueY = origY + 31 * boxHeight
for y in range(origY,endValueY,boxHeight):
    i = i + 1
    myFrame = "box"+str(i)
    scribus.createText(origX,y,boxWidth,boxHeight,myFrame)
    scribus.setLineColor("Black",myFrame)
    scribus.setText(str(i),myFrame)
    scribus.setTextColor("Red",myFrame)
    scribus.setFontSize(12,myFrame)