コード例 #1
0
def newWikiTextBlock(cont, x, y, w):
    h = 0
    #title
    title = scribus.createText(x, y, w, 1)
    scribus.setText(cont["wp"].title, title)
    scribus.setTextAlignment(scribus.ALIGN_LEFT, title)
    scribus.setFont("Open Sans Bold", title)
    scribus.setFontSize(14, title)
    scribus.setLineSpacing(14, title)

    tw, th = scribus.getSize(title)
    while scribus.textOverflows(title):
        scribus.sizeObject(tw, th + 1, title)
        tw, th = scribus.getSize(title)

    h = th

    #content
    content = scribus.createText(x, y + h + 1, w, 1)
    scribus.setText(cont["summary"], content)
    scribus.setTextAlignment(scribus.ALIGN_LEFT, content)
    scribus.setFont("Open Sans Regular", content)
    scribus.setFontSize(10, content)

    tw, th = scribus.getSize(content)
    while scribus.textOverflows(content):
        scribus.sizeObject(tw, th + 1, content)
        tw, th = scribus.getSize(content)
        if h + th > bH:
            break

    h = h + th

    return h
コード例 #2
0
def newWikiTextBlock(cont,x,y,w):
  h = 0
  #title
  title = scribus.createText(x, y, w, 1)
  scribus.setText(cont["wp"].title, title)
  scribus.setTextAlignment(scribus.ALIGN_LEFT, title)
  scribus.setFont("Open Sans Bold", title)
  scribus.setFontSize(14, title)
  scribus.setLineSpacing(14, title)

  tw,th = scribus.getSize(title)
  while scribus.textOverflows(title):
    scribus.sizeObject(tw, th+1, title)
    tw,th = scribus.getSize(title)

  h = th

  #content
  content = scribus.createText(x, y+h+1, w, 1)
  scribus.setText(cont["summary"], content)
  scribus.setTextAlignment(scribus.ALIGN_LEFT, content)
  scribus.setFont("Open Sans Regular", content)
  scribus.setFontSize(10, content)

  tw,th = scribus.getSize(content)
  while scribus.textOverflows(content):
    scribus.sizeObject(tw, th+1, content)
    tw,th = scribus.getSize(content)
    if h+th > bH:
      break

  h = h+th

  return h
コード例 #3
0
ファイル: CreateCards.py プロジェクト: gimmemoore/gameoffilth
def createCell(text, roffset, coffset, w, h, marginl, margint, isBlack):
    #Create textbox
    box=scribus.createRect(marginl+(roffset-1)*w,margint+(coffset-1)*h, w, h)
    textBox=scribus.createText(marginl+(roffset-1)*w,margint+(coffset-1)*h, w, h)
    #insert the text into textbox
    scribus.setFont("Arial Bold", textBox)
    
    
    
    #Default  font size
    fontSize=12
    if len(text) < 50: fontSize=14
    if len(text) < 20: fontSize=16
    scribus.setFontSize(fontSize, textBox)
    scribus.setTextDistances(3, 3, 3, 3, textBox)
    scribus.insertText(text, 0, textBox)

    #black card
    if isBlack==True:
        scribus.setFillColor("Black", box)
        scribus.setTextColor("White", textBox)
        scribus.setLineColor("White", box)


    #add Logo
    hOffset=37
    wOffset=5
    addLogo(marginl+(roffset-1)*w+wOffset,margint+(coffset-1)*h+hOffset, isBlack)
    return
コード例 #4
0
def createCell(text, roffset, coffset, w, h, marginl, margint, isBlack):
    #Create textbox
    box=scribus.createRect(marginl+(roffset-1)*w,margint+(coffset-1)*h, w, h)
    textBox=scribus.createText(marginl+(roffset-1)*w,margint+(coffset-1)*h, w, h)
    #insert the text into textbox
    scribus.setFont("Arial Bold", textBox)
    
    
    
    #Default  font size
    fontSize=12
    if len(text) < 50: fontSize=14
    if len(text) < 20: fontSize=16
    scribus.setFontSize(fontSize, textBox)
    scribus.setTextDistances(3, 3, 3, 3, textBox)
    scribus.insertText(text, 0, textBox)

    #black card
    if isBlack==True:
        scribus.setFillColor("Black", box)
        scribus.setTextColor("White", textBox)
        scribus.setLineColor("White", box)


    #add Logo
    hOffset=37
    wOffset=5
    addLogo(marginl+(roffset-1)*w+wOffset,margint+(coffset-1)*h+hOffset, isBlack)
    return
コード例 #5
0
ファイル: hd.py プロジェクト: fleshgordo/HDbuch
def textframes(text_id, x, y, width, height, bg_colour, text_colour, fontsize, font, spacing, parsedtext, layer, linespacing=0, resize=0):
	scribus.createText(x, y, width, height, text_id)
#scribus.text_id = scribus.createText(120, 10, 200, 20)
	scribus.setText(parsedtext, text_id)
	scribus.setFont(font, text_id)
	scribus.setTextColor(text_colour, text_id)
	scribus.setTextDistances(3*spacing, spacing, 0, spacing, text_id)
	scribus.sentToLayer(layer, text_id)
	scribus.setFontSize(fontsize, text_id)
コード例 #6
0
def addLogo(x, y, isBlack):
    #square side
    a=5
    #line
    line=0.01
    #angle
    angle=15
    #LightGrey
    scribus.defineColor("LightGrey",0,0,0,128)
    #DarkGrey
    scribus.defineColor("DarkGrey",0,0,0,192)
    
    # White cards colors
    squareColor1="Black"
    lineColor1="White"
    squareColor2="DarkGrey"
    lineColor2="White"
    squareColor3="LightGrey"
    lineColor3="White"
    titleColor="Black"
    
    # Black cards colors
    if isBlack==True:
        squareColor1="DarkGrey"
        lineColor1="DarkGrey"
        squareColor2="LightGrey"
        lineColor2="LightGrey"
        squareColor3="White"
        lineColor3="White"
        titleColor="White"
    
    square1=scribus.createRect(x, y+a/10, a, a)
    scribus.setLineWidth(1, square1)
    scribus.setFillColor(squareColor1, square1)
    scribus.setLineColor(lineColor1, square1)
    scribus.rotateObject(angle, square1)
    
    square2=scribus.createRect(x+a/2, y, a, a)
    scribus.setLineWidth(1, square2)
    scribus.setFillColor(squareColor2, square2)
    scribus.setLineColor(lineColor2, square2)
    
    square3=scribus.createRect(x+a, y, a, a)
    scribus.setLineWidth(1, square3)
    scribus.setFillColor(squareColor3, square3)
    scribus.setLineColor(lineColor3, square3)
    scribus.rotateObject(-angle, square3)
    
    title=scribus.createText(x+10,y+2, 50, 5)
    scribus.setFont("Arial Bold", title)
    scribus.setFontSize(8, title)
    scribus.insertText("Cards Against Humanity", 0, title)
    scribus.setTextColor(titleColor, title)
    return
コード例 #7
0
ファイル: CreateCards.py プロジェクト: gimmemoore/gameoffilth
def addLogo(x, y, isBlack):
    #square side
    a=5
    #line
    line=0.01
    #angle
    angle=15
    #LightGrey
    scribus.defineColor("LightGrey",0,0,0,128)
    #DarkGrey
    scribus.defineColor("DarkGrey",0,0,0,192)
    
    # White cards colors
    squareColor1="Black"
    lineColor1="White"
    squareColor2="DarkGrey"
    lineColor2="White"
    squareColor3="LightGrey"
    lineColor3="White"
    titleColor="Black"
    
    # Black cards colors
    if isBlack==True:
        squareColor1="DarkGrey"
        lineColor1="DarkGrey"
        squareColor2="LightGrey"
        lineColor2="LightGrey"
        squareColor3="White"
        lineColor3="White"
        titleColor="White"
    
    square1=scribus.createRect(x, y+a/10, a, a)
    scribus.setLineWidth(1, square1)
    scribus.setFillColor(squareColor1, square1)
    scribus.setLineColor(lineColor1, square1)
    scribus.rotateObject(angle, square1)
    
    square2=scribus.createRect(x+a/2, y, a, a)
    scribus.setLineWidth(1, square2)
    scribus.setFillColor(squareColor2, square2)
    scribus.setLineColor(lineColor2, square2)
    
    square3=scribus.createRect(x+a, y, a, a)
    scribus.setLineWidth(1, square3)
    scribus.setFillColor(squareColor3, square3)
    scribus.setLineColor(lineColor3, square3)
    scribus.rotateObject(-angle, square3)
    
    title=scribus.createText(x+10,y+2, 50, 5)
    scribus.setFont("Arial Bold", title)
    scribus.setFontSize(8, title)
    scribus.insertText("Game of Filth", 0, title)
    scribus.setTextColor(titleColor, title)
    return
コード例 #8
0
def main(argv):
    """This is a documentation string. Write a description of what your code
    does here. You should generally put documentation strings ("docstrings")
    on all your Python functions."""
    #########################
    #  YOUR CODE GOES HERE  #
    #########################
    #copyPlayer("__player__","PLAYER 1")
    #copyPlayer("__player__","PLAYER 2")
    #copyPlayer("__player__","PLAYER 3")
    csv = scribus.fileDialog('Open input', 'CSV files (*.csv)')
    stuff = {
        'NAME': 'Mike Hingley',
        'ADDRESS': '22 Trinity Street, Cradley Heath, West Midlands',
        'PHOTO': '128.jpg'
    }
    print(os.path.dirname(os.path.realpath(sys.argv[0])))
    print os.getcwd()
    print(sys.path[0])
    print(os.path.abspath(''))
    sourceName = "__player__"
    if scribus.objectExists(sourceName):
        scribus.selectObject(sourceName)
        scribus.unGroupObject()
        childObjectCount = scribus.selectionCount()
        for x in range(0, childObjectCount):
            element = scribus.getSelectedObject(x)
            if scribus.getObjectType(str(element)) == 'TextFrame':
                current = scribus.getAllText(element)
                if current in stuff:
                    fontsize = scribus.getFontSize(element)
                    font = scribus.getFont(element)
                    scribus.setText(stuff[current], element)
                    scribus.setFont(font)
                    scribus.setFontSize(fontsize)
            if scribus.getObjectType(str(element)) == 'ImageFrame':
                current = scribus.getImageFile(element)
                currentName = os.path.basename(os.path.normpath(current))
                print current
                print currentName
                if currentName in stuff:
                    ExistingFolder = os.path.split(current)
                    print ExistingFolder[0]
                    newFile = os.path.join(ExistingFolder[0],
                                           stuff[currentName])
                    print newFile
                    scribus.loadImage(newFile, element)
            print scribus.getObjectType(str(element))
            print str(scribus.getSelectedObject(x))
        scribus.groupObjects()
        print "name = " + scribus.getSelectedObject()
        scribus.setNewName("__player__", scribus.getSelectedObject())
コード例 #9
0
def createPlaceTimePrice(box, string, font, style):

    startLength = scribus.getTextLength(box)
    scribus.insertText(string, startLength, box)
    endLength = scribus.getTextLength(box) - startLength

    if style != "":
        scribus.selectText(startLength, endLength, box)
        scribus.setStyle(style, box)
    if font != "":
        scribus.selectText(startLength, endLength, box)
        scribus.setFont(font, box)
    return endLength
コード例 #10
0
ファイル: pa_maker.py プロジェクト: thresherdj/robo-scribus
    def setPageNumber (self, crds, pageSide, row, pageNumber) :
        '''Place the page number on the page if called for.'''

        if self.pageNumbers :
            # Make the page number box
            pNumBox = scribus.createText(crds[row]['pageNumXPos' + pageSide], crds[row]['pageNumYPos'], crds[row]['pageNumWidth'], crds[row]['pageNumHeight'])
            # Put the page number in it and format according to the page we are on
            scribus.setText(`pageNumber`, pNumBox)
            if pageSide == 'Odd' :
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNumBox)
            else:
                scribus.setTextAlignment(scribus.ALIGN_LEFT, pNumBox)

            scribus.setFont(self.fonts['pageNum']['bold'], pNumBox)
            scribus.setFontSize(self.fonts['pageNum']['size'], pNumBox)
コード例 #11
0
def change_text(text, item):

    l = scribus.getTextLength(item)
    scribus.selectText(0, l, item)
    fs = scribus.getFontSize(item)
    f = scribus.getFont(item)
    
    scribus.insertText(text, 0, item)
    l2 = scribus.getTextLength(item)
    scribus.selectText(0, l2, item)
    scribus.setFontSize(fs, item)
    scribus.setFont(f, item)

    scribus.selectText(l2-l, l, item)
    scribus.deleteText(item)

    scribus.deselectAll()
コード例 #12
0
    def setPageNumber(self, crds, pageSide, row, pageNumber):
        '''Place the page number on the page if called for.'''

        if self.pageNumbers:
            # Make the page number box
            pNumBox = scribus.createText(crds[row]['pageNumXPos' + pageSide],
                                         crds[row]['pageNumYPos'],
                                         crds[row]['pageNumWidth'],
                                         crds[row]['pageNumHeight'])
            # Put the page number in it and format according to the page we are on
            scribus.setText( ` pageNumber `, pNumBox)
            if pageSide == 'Odd':
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNumBox)
            else:
                scribus.setTextAlignment(scribus.ALIGN_LEFT, pNumBox)

            scribus.setFont(self.fonts['pageNum']['bold'], pNumBox)
            scribus.setFontSize(self.fonts['pageNum']['size'], pNumBox)
コード例 #13
0
 def characters(self, content):
     """place text, apply style"""
     start = scribus.getTextLength(self.name)
     go_ahead = self.shouldSetStyle()
     scribus.insertText (content, -1, self.name)
     scribus.selectText(start, len(content), self.name)
     if self.styles[-1] != None and go_ahead:
         try:
             scribus.setStyle(self.styles[-1], self.name)
         except scribus.NotFoundError:
             scribus.createParagraphStyle(self.styles[-1])
             scribus.setStyle(self.styles[-1], self.name)
     if self.overrides[-1] != None:
         try:
             scribus.setFont(self.overrides[-1], self.name)
         except ValueError:
             pass
     self.first = False
コード例 #14
0
ファイル: etiketigu.py プロジェクト: Piervit/etikedo
def fill_page(contacts):
    #where contacts is an array or at most max_contact contacts
    assert(len(contacts) < MAX_PAGE_CONTACTS)
    
    nb_lines = (len(contacts) / (CONST_COL_NUMBER))  
    if((len(contacts) % CONST_COL_NUMBER) != 0):
        nb_lines = nb_lines+1
    for curline in range (0, nb_lines):
        nb_col = min(len(contacts) - (curline * CONST_COL_NUMBER), CONST_COL_NUMBER) 
        for curcol in range (0, nb_col):
            x = CONST_TOP_MARGIN + CONST_COL_SIZE * curline
            y = CONST_LEFT_MARGIN + CONST_LINE_SIZE * curcol
            txtFrameName= "etiketo"+str(curline)+str(curcol)
            scribus.createText(y, x, CONST_LINE_SIZE, CONST_COL_SIZE, txtFrameName)
            contact_idx=curline*CONST_COL_NUMBER+curcol
            scribus.setText(contacts[contact_idx].print_contact(), txtFrameName)
            scribus.setTextDistances(6, 0, 3, 0, txtFrameName) 
            scribus.setFontSize(10, txtFrameName)
            scribus.setFont("Liberation Serif Regular", txtFrameName)
コード例 #15
0
ファイル: etiketigu.py プロジェクト: Piervit/etikedo
def fill_page(contacts):
    #where contacts is an array or at most max_contact contacts
    assert (len(contacts) < MAX_PAGE_CONTACTS)

    nb_lines = (len(contacts) / (CONST_COL_NUMBER))
    if ((len(contacts) % CONST_COL_NUMBER) != 0):
        nb_lines = nb_lines + 1
    for curline in range(0, nb_lines):
        nb_col = min(
            len(contacts) - (curline * CONST_COL_NUMBER), CONST_COL_NUMBER)
        for curcol in range(0, nb_col):
            x = CONST_TOP_MARGIN + CONST_COL_SIZE * curline
            y = CONST_LEFT_MARGIN + CONST_LINE_SIZE * curcol
            txtFrameName = "etiketo" + str(curline) + str(curcol)
            scribus.createText(y, x, CONST_LINE_SIZE, CONST_COL_SIZE,
                               txtFrameName)
            contact_idx = curline * CONST_COL_NUMBER + curcol
            scribus.setText(contacts[contact_idx].print_contact(),
                            txtFrameName)
            scribus.setTextDistances(6, 0, 3, 0, txtFrameName)
            scribus.setFontSize(10, txtFrameName)
            scribus.setFont("Liberation Serif Regular", txtFrameName)
コード例 #16
0
ファイル: pa_maker.py プロジェクト: thresherdj/robo-scribus
    def main (self) :

        # Load up all the file and record information.
        # Use CSV reader to build list of record dicts
        records         = self.loadCSVData(self.dataFile)
        totalRecs       = len(records)

        # Reality check first to see if we have anything to process
        if totalRecs <= 0 :
            scribus.messageBox('Not Found', 'No records found to process!')
            sys.exit()

        pageNumber      = 1
        recCount        = 0
        row             = 0
        pageSide        = 'Odd'
        scribus.progressTotal(totalRecs)
        paIndex         = {}
        lastName        = ''
        firstName       = ''
        photoFirstName  = ''
        verseRef        = ''
        verseText       = ''

        # Get the page layout coordinates for this publication
        crds = self.getCoordinates(self.dimensions)

        # Make a new document to put our records on
        if scribus.newDocument(getattr(scribus, self.dimensions['page']['scribusPageCode']), 
                    (self.dimensions['margins']['left'], self.dimensions['margins']['right'], self.dimensions['margins']['top'], self.dimensions['margins']['bottom']),
                        scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, 
                            scribus.FIRSTPAGERIGHT, 1) :

            self.setPageNumber(crds, pageSide, row, pageNumber)

            while recCount < totalRecs :

                # Output a new page on the first row after we have done the first page
                if row == 0 and recCount != 0:
                    scribus.newPage(-1)
                    if pageSide == 'Odd' :
                        pageSide = 'Even'
                    else :
                        pageSide = 'Odd'

                    self.setPageNumber(crds, pageSide, row, pageNumber)

                ########### Now set the current record in the current row ##########

                # Set the last name
                lastName = records[recCount]['NameLast']

                # Adjust the NameFirst field to include the spouse if there is one
                if records[recCount]['Spouse'] != '' :
                    firstName = records[recCount]['NameFirst'] + ' & ' + records[recCount]['Spouse']
                else :
                    firstName = records[recCount]['NameFirst']
                    
                # Make the photo file name
                photoFirstName = firstName.replace('&', '-').replace('.', '').replace(' ', '')

                # Set our record count for progress display and send a status message
                scribus.progressSet(recCount)
                scribus.statusMessage('Placing record ' + `recCount` + ' of ' + `totalRecs`)

                # Add a watermark if a string is specified
                if self.outputWatermark :
                    self.addWatermark()

                # Put the last name element in this row
                nameLastBox = scribus.createText(crds[row]['nameLastXPos'], crds[row]['nameLastYPos'], crds[row]['nameLastWidth'], crds[row]['nameLastHeight'])
                scribus.setText(lastName, nameLastBox)
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, nameLastBox)
                scribus.setTextDistances(0, 0, 0, 0, nameLastBox)
                scribus.setFont(self.fonts['nameLast']['bold'], nameLastBox)
                scribus.setFontSize(self.fonts['nameLast']['size'], nameLastBox)
                scribus.setTextShade(80, nameLastBox)
                scribus.rotateObject(90, nameLastBox)

                # Place the first name element in this row
                nameFirstBox = scribus.createText(crds[row]['nameFirstXPos'], crds[row]['nameFirstYPos'], crds[row]['nameFirstWidth'], crds[row]['nameFirstHeight'])
                scribus.setText(records[recCount]['Caption'], nameFirstBox)
                scribus.setTextAlignment(scribus.ALIGN_LEFT, nameFirstBox)
                scribus.setFont(self.fonts['nameFirst']['boldItalic'], nameFirstBox)
                scribus.setFontSize(self.fonts['nameFirst']['size'], nameFirstBox)

                # Place the image element in this row
                # We will need to do some processing on the first pass
                # The default output format is JPG
                orgImgFileName = records[recCount]['Photo']
                orgImgFile = os.path.join(self.orgImgDir, orgImgFileName)
                baseImgFileName = lastName + '_' + photoFirstName
                if self.willBePngImg :
                    ext = 'png'
                else :
                    ext = 'jpg'
                if not self.rgbColor :
                    imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '-gray' + '.' + ext)
                else :
                    imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '.' + ext)

                # Process the image now if there is none
                if not os.path.exists(imgFile) :
                    self.img_process.sizePic(orgImgFile, imgFile, self.maxHeight)
#                    self.img_process.outlinePic(imgFile, imgFile)
                    self.img_process.scalePic(imgFile, imgFile, self.imgDensity)
                    self.img_process.addPoloroidBorder(imgFile, imgFile)
                    # Color RGB is the default
                    if not self.rgbColor :
                        self.img_process.makeGray(imgFile, imgFile)

                # Double check the output and substitute with placeholder pic
                if not os.path.exists(imgFile) :
                    imgFile = self.placeholderPic
                # Create the imageBox and load the picture
                imageBox = scribus.createImage(crds[row]['imageXPos'], crds[row]['imageYPos'], crds[row]['imageWidth'], crds[row]['imageHeight'])
                if os.path.isfile(imgFile) :
                    scribus.loadImage(imgFile, imageBox)
                scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=imageBox)

                # Place the country element in this row (add second one if present)
                countryBox = scribus.createText(crds[row]['countryXPos'], crds[row]['countryYPos'], crds[row]['countryWidth'], crds[row]['countryHeight'])
                countryLine = records[recCount]['Country1']
                try :
                    if records[recCount]['Country2'] != '' :
                        countryLine = countryLine + ' & ' + records[recCount]['Country2']
                except :
                    pass
                scribus.setText(countryLine, countryBox)
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, countryBox)
                scribus.setFont(self.fonts['text']['boldItalic'], countryBox)
                scribus.setFontSize(self.fonts['text']['size'], countryBox)

                # Place the assignment element in this row
                assignBox = scribus.createText(crds[row]['assignXPos'], crds[row]['assignYPos'], crds[row]['assignWidth'], crds[row]['assignHeight'])
                scribus.setText(self.fixText(records[recCount]['Assignment']), assignBox)
                # Assign style to box
#                scribus.createParagraphStyle(name='assignStyle', alignment=0, leftmargin=10, firstindent=-10)
#                scribus.setStyle('assignStyle', assignBox)
                # Hard formated box
                scribus.setTextAlignment(scribus.ALIGN_LEFT, assignBox)
                scribus.setFont(self.fonts['text']['italic'], assignBox)
                scribus.setFontSize(self.fonts['text']['size'], assignBox)
                scribus.setLineSpacing(self.fonts['text']['size'] + 1, assignBox)
                scribus.setTextDistances(4, 0, 0, 0, assignBox)
                # Resize the frame height and determine the difference for
                # placing the next frame below it
                assignHeightNew = self.resizeFrame(assignBox)
                assignHeightDiff = crds[row]['assignHeight'] - assignHeightNew

                # Place the verse element in this row
                verseYPosNew = crds[row]['verseYPos'] - assignHeightDiff
                verseBox = scribus.createText(crds[row]['verseXPos'], verseYPosNew, crds[row]['verseWidth'], crds[row]['verseHeight'])
                # The verse element may be either a Scripture verse or a prayer request
                # If it is Scripture, and it has a verse ref, we want to set that
                # seperatly so we need to do a little preprocess on the text to find
                # out if it has a ref. This script will only recognize references
                # at the end of the string that are enclosed in brackets. See the
                # findVerseRef() function for more details
                verseRef = self.findVerseRef(records[recCount]['Prayer'])
                if verseRef :
                    verseText = self.removeVerseRef(self.fixText(records[recCount]['Prayer']))
                    scribus.setText(verseText, verseBox)
                else :
                    scribus.setText(self.fixText(records[recCount]['Prayer']), verseBox)
                # Can't find a way to set alignment to justified using setTextAlignment()
#                scribus.setTextAlignment(scribus.ALIGN_LEFT, verseBox)
                # Because of this, we make a style which seems to work
                scribus.createParagraphStyle(name='vBoxStyle', alignment=3)
                scribus.setStyle('vBoxStyle', verseBox)
                scribus.setFont(self.fonts['verse']['regular'], verseBox)
                scribus.setFontSize(self.fonts['verse']['size'], verseBox)
                scribus.setLineSpacing(self.fonts['verse']['size'] + 1, verseBox)
                scribus.setTextDistances(4, 0, 4, 0, verseBox)
                if self.hyphenate :
                    scribus.hyphenateText(verseBox)
                # Get the height difference in case we need to set ref box
                verseHeightNew = self.resizeFrame(verseBox)
                verseHeightDiff = crds[row]['verseHeight'] - verseHeightNew
                if verseRef :
                    # Set coordinates for this box
                    vRefBoxX = crds[row]['verseXPos']
                    vRefBoxY = (verseYPosNew + verseHeightNew)
                    vRefBoxH = crds[row]['nameFirstHeight'] / 2
                    vRefBoxW = crds[row]['verseWidth']
                    verseRefBox = scribus.createText(vRefBoxX, vRefBoxY, vRefBoxW, vRefBoxH)
                    scribus.setText(verseRef, verseRefBox)
                    scribus.setTextAlignment(scribus.ALIGN_RIGHT, verseRefBox)
                    scribus.setFont(self.fonts['verse']['italic'], verseRefBox)
                    scribus.setFontSize(self.fonts['verse']['size'] - 2, verseRefBox)
                    scribus.setLineSpacing(self.fonts['verse']['size'], verseRefBox)
                    scribus.setTextDistances(2, 0, 0, 0, verseRefBox)

                # Up our counts
                if row >= self.dimensions['rows']['count'] - 1 :
                    row = 0
                    pageNumber +=1
                else :
                    row +=1
                    
                recCount +=1

            # Create the index page here
            # Output a new page for the index
            if row == 0 and recCount != 0:
                scribus.newPage(-1)
                if pageSide == 'Odd' :
                    pageSide = 'Even'
                else :
                    pageSide = 'Odd'

                self.setPageNumber(crds, pageSide, 0, pageNumber)

        # Outut the index entries at this point
#        for key in paIndex.keys() :

        # Report we are done now before we loose focus
        scribus.statusMessage('Process Complete!')

###############################################################################
############################## Output Results #################################
###############################################################################

        # Now we will output the results to PDF if that is desired
        if self.makePdf :
            pdfExport =  scribus.PDFfile()
            pdfExport.info = self.pdfFile
            pdfExport.file = self.pdfFile
            pdfExport.save()

        # View the output if set
        if self.makePdf and self.viewPdf :
            cmd = ['evince', self.pdfFile]
            try :
                subprocess.Popen(cmd)
            except Exception as e :
                result = scribus.messageBox ('View PDF command failed with: ' + str(e), scribus.BUTTON_OK)
コード例 #17
0
def generateContent(string, window):

    #generates all the elements/only one element
    start = 0
    end = 0
    if string == "all":
        #dont include the first line to make the data sort work [1:]
        #sort the the elements by date
        data = sorted(getCSVdata()[1:],
                      key=lambda row: dateFun(str.strip(row[5])),
                      reverse=True)
        end = len(data)
        print(str(end) + "  " + str(start))
        print("generating elements from all lines")
        window.destroy()
    elif RepresentsInt(string):
        start = int(string) - 1  #index shifting
        end = int(string)
        print("only generating line " + string)
        data = getCSVdata()
        window.destroy()
    else:
        print(string + " is not a valid value")
        print("exiting")
        window.destroy()
        sys.exit()

    if not scribus.haveDoc() > 0:  #do we have a doc?
        scribus.messageBox("importcvs2table",
                           "No opened document.\nPlease open one first.")
        sys.exit()
    userdim = scribus.getUnit()  #get unit and change it to mm
    scribus.setUnit(scribus.UNIT_MILLIMETERS)

    lineWidth = 3.92  #aka 1.383mm, kp warum

    rowDate = ""
    for i in range(start, end):

        rowName = str.strip(data[i][0])
        rowCategory = str.strip(data[i][1])
        rowDescription = str.strip(data[i][2])
        rowPrice = str.strip(data[i][3])
        rowPlace = str.strip(data[i][4])
        rowDate = str.strip(data[i][5])
        rowTime = str.strip(data[i][6])

        if rowName == "":  #skip empty csv lines
            continue

        print("add element: " + rowName)

        #random values
        hpos = 120.0
        vpos = 200.0
        hposition = 120.0
        vposition = 200.0

        objectlist = []  #list for all boxes

        x = 0  #sets the progress
        #create the blue box
        print("create the blue line")
        blueBox = scribus.createLine(hposition + 1, vposition, hposition + 1,
                                     vposition + 5.863)
        scribus.setLineColor("Cyan", blueBox)
        scribus.setLineWidth(lineWidth, blueBox)
        objectlist.append(blueBox)
        scribus.progressSet(x)

        x = 1
        #create the data character box
        #these are the width values for the numbers
        zero = 4.608
        one = 2.839
        two = 4.724
        three = 4.393
        four = 4.625
        five = 4.261
        six = 4.278
        seven = 4.261
        eight = 4.625
        nine = 4.708

        lenArray = [zero, one, two, three, four, five, six, seven, eight, nine]

        marginleft = 1.3
        margintop = 0.519  #substract, cause the box is heigher that the blue line
        cellwidthright = 10.951
        cellHeight = 8.282
        hposition = hposition + marginleft + 1
        textbox = scribus.createText(hposition, vposition - margintop,
                                     cellwidthright, cellHeight)
        scribus.setFont("Quicksand Regular", textbox)
        scribus.setFontSize(20.0, textbox)
        finalDate = ""
        rowDateLength = 0
        #checks if the rowDate is from 01-09, in that case remove the zero
        if rowDate[0] == '0':
            finalDate = rowDate[1]
            rowDateLength = lenArray[int(rowDate[1])]

        else:
            finalDate = rowDate[:2]
            rowDateLength = lenArray[int(rowDate[0])] + lenArray[int(
                rowDate[1])]

        scribus.insertText(finalDate, 0, textbox)
        print("day: " + finalDate)
        objectlist.append(textbox)
        scribus.progressSet(x)

        x = 2
        #create the month/day box
        print("create the box with the day and month")
        width = 19.447
        height = 8.025
        marginleft = rowDateLength  #gain that from the calculations above, depends on the width of the rowDate characters

        monthBox = scribus.createText(hposition + marginleft + 0.7, vposition,
                                      width, height)
        scribus.setFont("Quicksand Regular", monthBox)
        scribus.setFontSize(8.5, monthBox)

        month = ""
        m = rowDate[3:5]
        if m == '01':
            month = "Januar"
        elif m == '02':
            month = "Februar"
        elif m == '03':
            month = "März"
        elif m == '04':
            month = "April"
        elif m == '05':
            month = "Mai"
        elif m == '06':
            month = "Juni"
        elif m == '07':
            month = "Juli"
        elif m == '08':
            month = "August"
        elif m == '09':
            month = "September"
        elif m == '10':
            month = "Oktober"
        elif m == '11':
            month = "November"
        elif m == '12':
            month = "Dezember"
        else:
            print("cant determine month!")

        day = datetime.date(int(rowDate[6:]), int(m),
                            int(rowDate[:2])).weekday()
        dayName = ""

        if day == 0:
            dayName = "Montag"
        elif day == 1:
            dayName = "Dienstag"
        elif day == 2:
            dayName = "Mittwoch"
        elif day == 3:
            dayName = "Donnerstag"
        elif day == 4:
            dayName = "Freitag"
        elif day == 5:
            dayName = "Samstag"
        elif day == 6:
            dayName = "Sonntag"
        else:
            print("cant determine day!")

        text = month + "\n" + dayName
        scribus.setStyle("Kalender_neu_Monat und Tag", monthBox)
        scribus.insertText(text, 0, monthBox)
        print("month: " + month + " day: " + dayName)
        objectlist.append(monthBox)
        scribus.progressSet(x)

        x = 3
        #create the main text box
        print("create the main text box")
        margintop = 5.5
        hpos = hpos - 0.383  #i dont know why but scribus always places the element 0.383 right than it should be :/
        mainTextBox = scribus.createText(
            hpos, vposition + margintop, 43.0,
            45.0)  #minus eins weil der blaue balken seinen kasten overflowed

        #insert category
        print("insert the category: " + rowCategory)
        scribus.insertText(rowCategory, 0, mainTextBox)
        endCategory = scribus.getTextLength(mainTextBox)
        scribus.selectText(0, endCategory, mainTextBox)
        scribus.setFontSize(10.5, mainTextBox)
        scribus.selectText(0, endCategory, mainTextBox)
        scribus.setStyle("Kalender_Eventname", mainTextBox)

        #insert main text
        print("insert the main text")
        scribus.insertText("\n" + rowDescription, endCategory, mainTextBox)
        endMainText = scribus.getTextLength(mainTextBox) - endCategory
        scribus.selectText(endCategory, endMainText, mainTextBox)
        scribus.setStyle("Kalender_Eventbeschreibung", mainTextBox)

        #get start length to color everything black and set font size
        startAll = scribus.getTextLength(mainTextBox)
        createPlaceTimePrice(mainTextBox, "\n| Ort: ", "",
                             "Kalender_Eventname")

        #insert value for place
        createPlaceTimePrice(mainTextBox, rowPlace, "Heuristica Regular", "")

        #insert time letters
        createPlaceTimePrice(mainTextBox, " | Zeit: ", "Quicksand Regular", "")

        #insert time value
        createPlaceTimePrice(mainTextBox, rowTime, "Heuristica Regular", "")

        #insert price letters
        createPlaceTimePrice(mainTextBox, " | Eintritt: ", "Quicksand Regular",
                             "")

        #insert price value
        createPlaceTimePrice(mainTextBox, rowPrice, "Heuristica Regular", "")

        #setFontSize and black color for the whole detail box
        endAll = scribus.getTextLength(mainTextBox) - startAll
        scribus.selectText(startAll, endAll, mainTextBox)
        scribus.setFontSize(8.5, mainTextBox)
        scribus.selectText(startAll, endAll, mainTextBox)
        scribus.setTextColor("Black", mainTextBox)

        objectlist.append(mainTextBox)
        scribus.progressSet(x)

        #do some generell stuff
        scribus.groupObjects(objectlist)
        scribus.progressReset()
        scribus.setUnit(userdim)  # reset unit to previous value
        scribus.docChanged(True)
        scribus.statusMessage("Done")
        scribus.setRedraw(True)

    print("done")
    return 0
コード例 #18
0
def load_song(data, offset, settings):
    page_num = scribus.pageCount()
    page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(
        page_num)
    start_point = margin_top + offset

    new_width = page_width - margin_left - margin_right
    if not FAST:
        scribus.placeEPS(os.path.join(FILES, data["filename"]), 0, 0)
        eps = scribus.getSelectedObject()
        eps_width, eps_height = scribus.getSize(eps)
        #scribus.scaleGroup(new_width/eps_width) # slow on scribus 1.4; does something else on scribus 1.5
        scribus.sizeObject(eps_width * 0.86, eps_height * 0.86, eps)
        scribus.moveObjectAbs(margin_left, start_point + SPACING_HEADLINE_SONG,
                              eps)
        eps_width, eps_height = scribus.getSize(eps)
    else:
        eps_height = 0

    scribus.deselectAll()
    textbox = scribus.createText(margin_left, start_point, new_width, 20)

    style_suffix = get_style_suffix()

    if data["composer"]:
        scribus.deselectAll()
        scribus.insertText(u"{}\n".format(data["composer"]), 0, textbox)
        scribus.selectText(0, 1, textbox)
        scribus.setStyle("subline_{}".format(style_suffix), textbox)

    if data["poet"]:
        scribus.deselectAll()
        scribus.insertText(u"{}\n".format(data["poet"]), 0, textbox)
        scribus.selectText(0, 1, textbox)
        scribus.setStyle("subline_{}".format(style_suffix), textbox)

    scribus.deselectAll()
    scribus.insertText(u"{}\n".format(data["name"]), 0, textbox)
    scribus.selectText(0, 1, textbox)
    scribus.setStyle("headline_{}".format(style_suffix), textbox)

    text = data["text"]
    text = [t.strip() for t in text if t.strip() != ""]

    # TODO: exit if text == []

    textbox = scribus.createText(
        margin_left,
        start_point + eps_height + SPACING_HEADLINE_SONG + SPACING_SONG_TEXT,
        new_width, 50)
    scribus.setStyle("text", textbox)
    # let's see how many digits are in there:
    num_verses = len([l for l in text if l.isdigit()])
    num_chars = 0
    num_line_total = len(text)
    num_line_actually = 0
    no_new_line = False
    verse_counter = 0
    text_columns_height = 0  # TODO: should be None
    for num_line, line in enumerate(text):
        if line.strip == "":
            continue
        num_line_actually += 1
        if line.isdigit():

            print "#", verse_counter, math.ceil(
                num_verses * 0.5), num_verses, data["filename"]
            if verse_counter == math.ceil(
                    num_verses * 0.5
            ):  # this is the first verse that should be in the new column, so let's see what's the height
                print text_columns_height, num_line_actually
                text_columns_height = BASELINE_GRID * (num_line_actually - 1)

            first_char = "\n"
            if num_line == 0:
                first_char = ""
            no_new_line = True
            line = u"{}{}.\t".format(first_char, line)
            scribus.insertText(line, -1, textbox)
            scribus.deselectAll()
            scribus.selectText(num_chars, len(line), textbox)
            #scribus.setStyle("num", textbox) # no character styles available
            #scribus.setFontSize(5, textbox)  # TODO: testing only # BUG?
            scribus.setFont("Linux Libertine O Bold", textbox)
            num_chars += len(line)
            verse_counter += 1
        else:
            if no_new_line:
                first_char = ""
            else:
                first_char = chr(28)
            no_new_line = False
            line = u"{}{}".format(first_char, line)
            scribus.insertText(line, -1, textbox)
            #scribus.deselectAll()
            #scribus.selectText(num_chars, len(line), textbox)
            #scribus.setStyle("text", textbox)
            num_chars += len(line)

    scribus.setColumnGap(5, textbox)
    columns = settings.get("columns", 2)
    scribus.setColumns(columns, textbox)
    if columns != 2:
        fit_height(textbox)
    else:
        scribus.sizeObject(new_width, text_columns_height, textbox)
        l, t = scribus.getPosition(textbox)
        scribus.moveObjectAbs(l,
                              round(t / BASELINE_GRID) * BASELINE_GRID,
                              textbox)
        if scribus.textOverflows(textbox):
            fit_height(textbox)  # there are some cases,..
    text_width, text_height = scribus.getSize(textbox)
    text_left, text_top = scribus.getPosition(textbox)
    return text_top + text_height - start_point + SPACING_SONGS, page_num
コード例 #19
0
ファイル: eotizer.py プロジェクト: pa3/eot
        fileName = scribus.fileDialog("Open odt file", 'ODT files (*.odt)')
        text = removeEmptyStrings(parse(fileName))
        header = detag(header(text))
        body = body(text)

        scribus.deleteText(bodyText)
        scribus.insertText(lines(detag(body))[0], -1, bodyText)
        scribus.setStyle("first_paragraph", bodyText)

        for p in lines(detag(body))[1:]:
            scribus.insertText("\n" + p, -1, bodyText)
            scribus.setStyle("eot", bodyText)
        for tag in extractModifiers(body):
            scribus.selectText(tag['start'], tag['length'], bodyText)
            if tag['tag'] == "bold":
                scribus.setFont("Mysl Bold Cyrillic", bodyText)
            elif tag['tag'] == "italic":
                scribus.setFont("Mysl Italic Cyrillic", bodyText)
            else:
                scribus.setFont("Mysl BoldItalic Cyrillic", bodyText)

        scribus.insertText("\n" + authorName(detag(text)), -1, bodyText)
        scribus.setStyle("author name", bodyText)

        scribus.insertText("\n" + authorEmail(detag(text)), -1, bodyText)
        scribus.setStyle("author emali", bodyText)

        scribus.hyphenateText(bodyText)

        scribus.insertText(header, -1, headerText)
        scribus.setStyle("article header", headerText)
コード例 #20
0
offsetXX = 0.2
offsetY = 0.15
minResultA = 0
maxResultA = 14
minResultB = 1
maxResultB = 3
rx = [[0 for col in range(100)] for row in range(100)]
ry = [[0 for col in range(100)] for row in range(100)]

scribus.newDocument((pageX, pageY), (0.0, 0.0, 0.0, 0.0), scribus.PORTRAIT, 1, scribus.UNIT_INCHES, scribus.PAGE_1, 0, 1)
scribus.defineColor("gray",21,21,21,21)

for x in range(0,maxX):
	for y in range(0,maxY):
		q = scribus.createText((x*((pageX*0.9)/maxX))+offsetX, (y*(pageY/maxY))+offsetY, (pageX*0.9)/maxX, pageY/maxY)
		scribus.setFont('Arial Regular',q)
		scribus.setFontSize(48, q)
		if random.randint(0, 1) == 0:
			rx[x][y] = random.randint(minResultB, maxResultB) 
			ry[x][y] = random.randint(minResultA, maxResultA)
		else:
			rx[x][y] = random.randint(minResultA, maxResultA)
			ry[x][y] = random.randint(minResultB, maxResultB)
		rxx = rx[x][y]
		ryy = ry[x][y]
		scribus.insertText('%(rxx)d + %(ryy)d =__' % locals(), 0, q)
scribus.newPage(-1)
xx = 0
for x in range(maxX-1,-1,-1):
	for y in range(0,maxY):
		q = scribus.createText((xx*((pageX/6)/maxX))+offsetXX, (y*(pageY/maxY))+offsetY, (pageX/6)/maxX, pageY/maxY)
コード例 #21
0
    
    for row in data:
        #if i > 0 :
	  #sys.exit(1)
	#scribus.messageBox("csv2table", row)
	roseid = row[0]
	rosenameger = row[1]
	rosenamelat = row[2]
        #scribus.messageBox("csv2table", roseid+' '+rosenameger+' ('+rosenamelat+')')
        
        #Insert the Right Text into the Right Position
        
        #Write ID into ID Field
	scribus.deleteText(idtextstring)
	scribus.setText(roseid, idtextstring)
	scribus.setFont(idfont, idtextstring)
	scribus.setFontSize(idfonSize, idtextstring)
	scribus.setTextColor(idtextcolor, idtextstring)
	scribus.setTextShade(idtextshade, idtextstring)
	
	#Write German Name into german Name Field
	scribus.deleteText(gertextstring)
	scribus.setText(rosenameger, gertextstring)
	scribus.setFont(gerfont, gertextstring)
	scribus.setFontSize(gerfonSize, gertextstring)
	scribus.setTextColor(gertextcolor, gertextstring)
	scribus.setTextShade(gertextshade, gertextstring)
	
	#Write Latin Name into Latin Name field
	scribus.deleteText(lattextstring)
	scribus.setText(rosenamelat, lattextstring)
コード例 #22
0
    def main(self):

        # Load up all the file and record information.
        # Use CSV reader to build list of record dicts
        records = self.loadCSVData(self.dataFile)
        totalRecs = len(records)

        # Reality check first to see if we have anything to process
        if totalRecs <= 0:
            scribus.messageBox('Not Found', 'No records found to process!')
            sys.exit()

        pageNumber = 1
        recCount = 0
        row = 0
        pageSide = 'Odd'
        scribus.progressTotal(totalRecs)
        paIndex = {}
        lastName = ''
        firstName = ''
        photoFirstName = ''
        verseRef = ''
        verseText = ''

        # Get the page layout coordinates for this publication
        crds = self.getCoordinates(self.dimensions)

        # Make a new document to put our records on
        if scribus.newDocument(
                getattr(scribus, self.dimensions['page']['scribusPageCode']),
            (self.dimensions['margins']['left'],
             self.dimensions['margins']['right'],
             self.dimensions['margins']['top'],
             self.dimensions['margins']['bottom']), scribus.PORTRAIT, 1,
                scribus.UNIT_POINTS, scribus.NOFACINGPAGES,
                scribus.FIRSTPAGERIGHT, 1):

            self.setPageNumber(crds, pageSide, row, pageNumber)

            while recCount < totalRecs:

                # Output a new page on the first row after we have done the first page
                if row == 0 and recCount != 0:
                    scribus.newPage(-1)
                    if pageSide == 'Odd':
                        pageSide = 'Even'
                    else:
                        pageSide = 'Odd'

                    self.setPageNumber(crds, pageSide, row, pageNumber)

                ########### Now set the current record in the current row ##########

                # Set the last name
                lastName = records[recCount]['NameLast']

                # Adjust the NameFirst field to include the spouse if there is one
                if records[recCount]['Spouse'] != '':
                    firstName = records[recCount][
                        'NameFirst'] + ' & ' + records[recCount]['Spouse']
                else:
                    firstName = records[recCount]['NameFirst']

                # Make the photo file name
                photoFirstName = firstName.replace('&', '-').replace(
                    '.', '').replace(' ', '')

                # Set our record count for progress display and send a status message
                scribus.progressSet(recCount)
                scribus.statusMessage('Placing record ' + ` recCount ` +
                                      ' of ' + ` totalRecs `)

                # Add a watermark if a string is specified
                if self.outputWatermark:
                    self.addWatermark()

                # Put the last name element in this row
                nameLastBox = scribus.createText(crds[row]['nameLastXPos'],
                                                 crds[row]['nameLastYPos'],
                                                 crds[row]['nameLastWidth'],
                                                 crds[row]['nameLastHeight'])
                scribus.setText(lastName, nameLastBox)
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, nameLastBox)
                scribus.setTextDistances(0, 0, 0, 0, nameLastBox)
                scribus.setFont(self.fonts['nameLast']['bold'], nameLastBox)
                scribus.setFontSize(self.fonts['nameLast']['size'],
                                    nameLastBox)
                scribus.setTextShade(80, nameLastBox)
                scribus.rotateObject(90, nameLastBox)

                # Place the first name element in this row
                nameFirstBox = scribus.createText(crds[row]['nameFirstXPos'],
                                                  crds[row]['nameFirstYPos'],
                                                  crds[row]['nameFirstWidth'],
                                                  crds[row]['nameFirstHeight'])
                scribus.setText(records[recCount]['Caption'], nameFirstBox)
                scribus.setTextAlignment(scribus.ALIGN_LEFT, nameFirstBox)
                scribus.setFont(self.fonts['nameFirst']['boldItalic'],
                                nameFirstBox)
                scribus.setFontSize(self.fonts['nameFirst']['size'],
                                    nameFirstBox)

                # Place the image element in this row
                # We will need to do some processing on the first pass
                # The default output format is JPG
                orgImgFileName = records[recCount]['Photo']
                orgImgFile = os.path.join(self.orgImgDir, orgImgFileName)
                baseImgFileName = lastName + '_' + photoFirstName
                if self.willBePngImg:
                    ext = 'png'
                else:
                    ext = 'jpg'
                if not self.rgbColor:
                    imgFile = os.path.join(
                        getattr(self, ext + 'ImgDir'),
                        baseImgFileName + '-gray' + '.' + ext)
                else:
                    imgFile = os.path.join(getattr(self, ext + 'ImgDir'),
                                           baseImgFileName + '.' + ext)

                # Process the image now if there is none
                if not os.path.exists(imgFile):
                    self.img_process.sizePic(orgImgFile, imgFile,
                                             self.maxHeight)
                    #                    self.img_process.outlinePic(imgFile, imgFile)
                    self.img_process.scalePic(imgFile, imgFile,
                                              self.imgDensity)
                    self.img_process.addPoloroidBorder(imgFile, imgFile)
                    # Color RGB is the default
                    if not self.rgbColor:
                        self.img_process.makeGray(imgFile, imgFile)

                # Double check the output and substitute with placeholder pic
                if not os.path.exists(imgFile):
                    imgFile = self.placeholderPic
                # Create the imageBox and load the picture
                imageBox = scribus.createImage(crds[row]['imageXPos'],
                                               crds[row]['imageYPos'],
                                               crds[row]['imageWidth'],
                                               crds[row]['imageHeight'])
                if os.path.isfile(imgFile):
                    scribus.loadImage(imgFile, imageBox)
                scribus.setScaleImageToFrame(scaletoframe=1,
                                             proportional=1,
                                             name=imageBox)

                # Place the country element in this row (add second one if present)
                countryBox = scribus.createText(crds[row]['countryXPos'],
                                                crds[row]['countryYPos'],
                                                crds[row]['countryWidth'],
                                                crds[row]['countryHeight'])
                countryLine = records[recCount]['Country1']
                try:
                    if records[recCount]['Country2'] != '':
                        countryLine = countryLine + ' & ' + records[recCount][
                            'Country2']
                except:
                    pass
                scribus.setText(countryLine, countryBox)
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, countryBox)
                scribus.setFont(self.fonts['text']['boldItalic'], countryBox)
                scribus.setFontSize(self.fonts['text']['size'], countryBox)

                # Place the assignment element in this row
                assignBox = scribus.createText(crds[row]['assignXPos'],
                                               crds[row]['assignYPos'],
                                               crds[row]['assignWidth'],
                                               crds[row]['assignHeight'])
                scribus.setText(self.fixText(records[recCount]['Assignment']),
                                assignBox)
                # Assign style to box
                #                scribus.createParagraphStyle(name='assignStyle', alignment=0, leftmargin=10, firstindent=-10)
                #                scribus.setStyle('assignStyle', assignBox)
                # Hard formated box
                scribus.setTextAlignment(scribus.ALIGN_LEFT, assignBox)
                scribus.setFont(self.fonts['text']['italic'], assignBox)
                scribus.setFontSize(self.fonts['text']['size'], assignBox)
                scribus.setLineSpacing(self.fonts['text']['size'] + 1,
                                       assignBox)
                scribus.setTextDistances(4, 0, 0, 0, assignBox)
                # Resize the frame height and determine the difference for
                # placing the next frame below it
                assignHeightNew = self.resizeFrame(assignBox)
                assignHeightDiff = crds[row]['assignHeight'] - assignHeightNew

                # Place the verse element in this row
                verseYPosNew = crds[row]['verseYPos'] - assignHeightDiff
                verseBox = scribus.createText(crds[row]['verseXPos'],
                                              verseYPosNew,
                                              crds[row]['verseWidth'],
                                              crds[row]['verseHeight'])
                # The verse element may be either a Scripture verse or a prayer request
                # If it is Scripture, and it has a verse ref, we want to set that
                # seperatly so we need to do a little preprocess on the text to find
                # out if it has a ref. This script will only recognize references
                # at the end of the string that are enclosed in brackets. See the
                # findVerseRef() function for more details
                verseRef = self.findVerseRef(records[recCount]['Prayer'])
                if verseRef:
                    verseText = self.removeVerseRef(
                        self.fixText(records[recCount]['Prayer']))
                    scribus.setText(verseText, verseBox)
                else:
                    scribus.setText(self.fixText(records[recCount]['Prayer']),
                                    verseBox)
                # Can't find a way to set alignment to justified using setTextAlignment()
#                scribus.setTextAlignment(scribus.ALIGN_LEFT, verseBox)
# Because of this, we make a style which seems to work
                scribus.createParagraphStyle(name='vBoxStyle', alignment=3)
                scribus.setStyle('vBoxStyle', verseBox)
                scribus.setFont(self.fonts['verse']['regular'], verseBox)
                scribus.setFontSize(self.fonts['verse']['size'], verseBox)
                scribus.setLineSpacing(self.fonts['verse']['size'] + 1,
                                       verseBox)
                scribus.setTextDistances(4, 0, 4, 0, verseBox)
                if self.hyphenate:
                    scribus.hyphenateText(verseBox)
                # Get the height difference in case we need to set ref box
                verseHeightNew = self.resizeFrame(verseBox)
                verseHeightDiff = crds[row]['verseHeight'] - verseHeightNew
                if verseRef:
                    # Set coordinates for this box
                    vRefBoxX = crds[row]['verseXPos']
                    vRefBoxY = (verseYPosNew + verseHeightNew)
                    vRefBoxH = crds[row]['nameFirstHeight'] / 2
                    vRefBoxW = crds[row]['verseWidth']
                    verseRefBox = scribus.createText(vRefBoxX, vRefBoxY,
                                                     vRefBoxW, vRefBoxH)
                    scribus.setText(verseRef, verseRefBox)
                    scribus.setTextAlignment(scribus.ALIGN_RIGHT, verseRefBox)
                    scribus.setFont(self.fonts['verse']['italic'], verseRefBox)
                    scribus.setFontSize(self.fonts['verse']['size'] - 2,
                                        verseRefBox)
                    scribus.setLineSpacing(self.fonts['verse']['size'],
                                           verseRefBox)
                    scribus.setTextDistances(2, 0, 0, 0, verseRefBox)

                # Up our counts
                if row >= self.dimensions['rows']['count'] - 1:
                    row = 0
                    pageNumber += 1
                else:
                    row += 1

                recCount += 1

            # Create the index page here
            # Output a new page for the index
            if row == 0 and recCount != 0:
                scribus.newPage(-1)
                if pageSide == 'Odd':
                    pageSide = 'Even'
                else:
                    pageSide = 'Odd'

                self.setPageNumber(crds, pageSide, 0, pageNumber)

        # Outut the index entries at this point
#        for key in paIndex.keys() :

# Report we are done now before we loose focus
        scribus.statusMessage('Process Complete!')

        ###############################################################################
        ############################## Output Results #################################
        ###############################################################################

        # Now we will output the results to PDF if that is desired
        if self.makePdf:
            pdfExport = scribus.PDFfile()
            pdfExport.info = self.pdfFile
            pdfExport.file = self.pdfFile
            pdfExport.save()

        # View the output if set
        if self.makePdf and self.viewPdf:
            cmd = ['evince', self.pdfFile]
            try:
                subprocess.Popen(cmd)
            except Exception as e:
                result = scribus.messageBox(
                    'View PDF command failed with: ' + str(e),
                    scribus.BUTTON_OK)
コード例 #23
0
def load_song(data, offset, settings):
    page_num = scribus.pageCount()
    page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(page_num)
    start_point = margin_top + offset

    new_width = page_width - margin_left - margin_right
    if not FAST:
        scribus.placeEPS(os.path.join(FILES, data["filename"]), 0, 0)
        eps = scribus.getSelectedObject()
        eps_width, eps_height = scribus.getSize(eps)
        #scribus.scaleGroup(new_width/eps_width) # slow on scribus 1.4; does something else on scribus 1.5
        scribus.sizeObject(eps_width*0.86, eps_height*0.86, eps)
        scribus.moveObjectAbs(margin_left, start_point+SPACING_HEADLINE_SONG, eps)
        eps_width, eps_height = scribus.getSize(eps)
    else:
        eps_height = 0

    scribus.deselectAll()
    textbox = scribus.createText(margin_left, start_point, new_width, 20)

    style_suffix = get_style_suffix()

    if data["composer"]:
        scribus.deselectAll()
        scribus.insertText(u"{}\n".format(data["composer"]), 0, textbox)
        scribus.selectText(0, 1, textbox)
        scribus.setStyle("subline_{}".format(style_suffix), textbox)

    if data["poet"]:
        scribus.deselectAll()
        scribus.insertText(u"{}\n".format(data["poet"]), 0, textbox)
        scribus.selectText(0, 1, textbox)
        scribus.setStyle("subline_{}".format(style_suffix), textbox)

    scribus.deselectAll()
    scribus.insertText(u"{}\n".format(data["name"]), 0, textbox)
    scribus.selectText(0, 1, textbox)
    scribus.setStyle("headline_{}".format(style_suffix), textbox)

    text = data["text"]
    text = [t.strip() for t in text if t.strip() != ""]

    # TODO: exit if text == []

    textbox = scribus.createText(margin_left, start_point + eps_height + SPACING_HEADLINE_SONG + SPACING_SONG_TEXT, new_width, 50)
    scribus.setStyle("text", textbox)
    # let's see how many digits are in there:
    num_verses = len([l for l in text if l.isdigit()])
    num_chars = 0
    num_line_total = len(text)
    num_line_actually = 0
    no_new_line = False
    verse_counter = 0
    text_columns_height = 0 # TODO: should be None
    for num_line, line in enumerate(text):
        if line.strip == "":
            continue
        num_line_actually += 1
        if line.isdigit():

            print "#", verse_counter, math.ceil(num_verses * 0.5), num_verses, data["filename"]
            if verse_counter == math.ceil(num_verses*0.5): # this is the first verse that should be in the new column, so let's see what's the height
                print text_columns_height, num_line_actually
                text_columns_height = BASELINE_GRID * (num_line_actually -1)

            first_char = "\n"
            if num_line == 0:
                first_char = ""
            no_new_line = True
            line = u"{}{}.\t".format(first_char, line)
            scribus.insertText(line, -1, textbox)
            scribus.deselectAll()
            scribus.selectText(num_chars, len(line), textbox)
            #scribus.setStyle("num", textbox) # no character styles available
            #scribus.setFontSize(5, textbox)  # TODO: testing only # BUG?
            scribus.setFont("Linux Libertine O Bold", textbox)
            num_chars += len(line)
            verse_counter += 1
        else:
            if no_new_line:
                first_char = ""
            else:
                first_char = chr(28)
            no_new_line = False
            line = u"{}{}".format(first_char, line)
            scribus.insertText(line, -1, textbox)
            #scribus.deselectAll()
            #scribus.selectText(num_chars, len(line), textbox)
            #scribus.setStyle("text", textbox)
            num_chars += len(line)

    scribus.setColumnGap(5, textbox)
    columns = settings.get("columns", 2)
    scribus.setColumns(columns, textbox)
    if columns != 2:
        fit_height(textbox)
    else:
        scribus.sizeObject(new_width, text_columns_height, textbox)
        l, t = scribus.getPosition(textbox)
        scribus.moveObjectAbs(l, round(t/BASELINE_GRID)*BASELINE_GRID, textbox)
        if scribus.textOverflows(textbox):
            fit_height(textbox) # there are some cases,.. 
    text_width, text_height = scribus.getSize(textbox)
    text_left, text_top = scribus.getPosition(textbox)
    return text_top + text_height - start_point + SPACING_SONGS, page_num
コード例 #24
0
ファイル: parse120buntu.py プロジェクト: fleshgordo/120days
	scribus.createLayer("textlayer")


distros.keys().sort()

for distro in sorted(distros.iterkeys()):
	# extract the dictionary content
	description = distros[distro][0]
	filesizeiso = distros[distro][1]
	md5sum = distros[distro][2]
	modified = distros[distro][3]

	# create page title/header
	B = scribus.createText(left_page_x, 10, 100, 10)
	scribus.setText(distro, B)
	scribus.setFont("Gentium Plus Compact Regular", B)
	scribus.setTextAlignment(scribus.ALIGN_LEFT, B)
	scribus.setFontSize(18, B)
	
	# load small-logo into page
	imagedir = "./logos/"
	f = scribus.createImage(left_page_x, 23, 65, 65)
	scribus.loadImage(imagedir + distro + ".png", f)
	scribus.setScaleImageToFrame(1,1,f)
	scribus.sentToLayer("textlayer", f)

	# get description text for each distro
	scribus.createText(left_page_x, 92, 120, 80,distro)
	scribus.setText(description, distro)
	scribus.setLineSpacing(12,distro)
	linespacing = scribus.getLineSpacing(distro)