[scribus] Problems with setStyle() and some more...

yakup çetinkaya yakup.cetinkaya at gmail.com
Fri Oct 22 22:07:31 CEST 2010


Hi list,

I am trying to build an automated layout engine to be used in newspaper
design. This is actually a school project for me, but thinking of the
repetitive and low-intellectual processes in the laying out of newspapers, I
thought of sharing such a script could be useful for a lot of people.
Note that the images and titles are excluded here, only the body text with
subtitles is counted for focusing on the issue at hand : )
Below is a simplified version of my script, the problem emerges in the
Estimator class where i try to set the size value of each NewsElement
instance. The dictionary called "switch" is distinguishing text items and
image url's with a convention i used in the sourceText.

class Estimator:
    def __init__(self):
        names = []
        for n in newsList:

names.append(scribus.createText(doc.pageMargins[0]+doc.colWidth*len(names),doc.pageMargins[2],doc.colWidth,doc.pageSize[1]*doc.defCols))
            this = names[-1]
            scribus.insertText(n.body.data,-1,this)
            scribus.hyphenateText(this)
            for s in n.body.styleIndex:
                print s[0],s[1],s[2],this
                scribus.selectText(s[0],s[1],this)
                scribus.setStyle(s[2], this)
            l = scribus.getTextLines(this)
             print 'lineCount:', l
            n.size = l

class NewsElement:
    def __init__(self):
        self.body = BodyElement("")
        self.size = 0

    def appendToBody(self,body,style):
        self.body.append(body,style)

class BodyElement:
    def __init__(self,data):
        self.data = data
        self.styleIndex = []

    def append(self,data,style):
        l = len(self.data)
        self.data += data
        s = [l,len(data),style]
        self.styleIndex.append(s)

def news(data):
    n = NewsElement()
    newsList.append(n)

def header(data):
    newsList[-1].appendToBody('\n'+data,'ps_header')

def first(data):
    newsList[-1].appendToBody(data,'ps_first')

def para(data):
    newsList[-1].appendToBody('\n'+data,'ps_body')

def slant(data):
    newsList[-1].appendToBody('\n'+data,'ps_slanted')

def question(data):
    newsList[-1].appendToBody('\n+ '+data,'ps_body')

def answer(data):
    newsList[-1].appendToBody('\n- '+data,'ps_body')

def bullet(data):
    newsList[-1].appendToBody('\n* '+data,'ps_body')

def pas(data):
    pass

class docBasics:
    def __init__(self):
        self.unit = scribus.UNIT_PICAS
        self.pageSize = (1080,1584)
        self.pageMargins = (36,36,60,48)
        self.contentSize =
(self.pageSize[0]-self.pageMargins[0]-self.pageMargins[1],
self.pageSize[1]-self.pageMargins[2]-self.pageMargins[3])
        self.columnGap = 12
        self.baseLine = 15
        self.numPages = 20
        self.defCols = 5
        self.colWidth =
float(self.contentSize[0]-self.columnGap*(self.defCols-1))/self.defCols;
        self.basePath = "/home/yakup/scribus/AGOS/"

switch = {
"?" : news,
"*" : subtitle,
"^" : first,
"&" : para,
"/" : slant,
"+" : question,
"-" : answer,
"!" : bullet,
"" : pas
}

newsList = []
doc = docBasics()

def getTextFromSource():
    source = sourceText.splitlines(1)
    for line in source:
        switch[line[0]](line[1:-1])

getTextFromSource()
est = Estimator()

With the outcome, the most evident problem is that the setStyle() command in
the Estimator class only seems to be working for the first and the last
paragraphs, even though the start and count indexes and style names are
printed correctly for each item.
The second issue is the getTextLines() method is returning 0, no matter if I
put it before or after the styling loop or the hyphenate() command. So I
fail to get any estimations for my NewsElements to start the pagination
process.
I am using Scribus v1.3.8 on Ubuntu 10.10.

Any help is appreciated.

-- 
yakup
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.scribus.net/pipermail/scribus/attachments/20101022/32b4cb8d/attachment.htm>


More information about the scribus mailing list