Esempio n. 1
0
    def draw(self, tolevel):
        contents = []
        for (label, level, page) in self.sections:
            if level <= tolevel:
                text = label + chr(TAB) + str(page)
                style = "Contents" + str(level)
                contents.append((text, style))

        page = self.contentspage
        scribus.gotoPage(page)
        (width, height) = scribus.getPageSize()
        (top, left, right, bottom) = getCurrentPageMargins()
        frame = scribus.createText(left, top, width - right - left, TITLESIZE)
        insertTextWithStyle("Contents", "Title", frame)

        frame = scribus.createText(left, top + TITLESIZE, width - right - left,
                                   height - top - bottom - TITLESIZE)
        scribus.setColumns(2, frame)
        scribus.setColumnGap(COLUMNGAP, frame)
        for (text, style) in contents:
            insertTextWithStyle(text, style, frame)
            if scribus.textOverflows(frame):
                oldframe = frame
                page = page + 1
                scribus.gotoPage(page)
                (top, left, right, bottom) = getCurrentPageMargins()
                frame = scribus.createText(left, top + TITLESIZE,
                                           width - right - left,
                                           height - top - bottom - TITLESIZE)
                scribus.setColumns(2, frame)
                scribus.setColumnGap(COLUMNGAP, frame)
                scribus.linkTextFrames(oldframe, frame)
Esempio n. 2
0
    def drawIndexByName(self):
        contents = {}
        climbnames = []
        for (route, grade, stars, crag, page) in self.climbs:
            text = route + chr(TAB) + str(page)
            contents[route] = (text, "Index")
            climbnames.append(route)
        climbnames.sort()

        (width, height) = scribus.getPageSize()
        (top, left, right, bottom) = getCurrentPageMargins()
        frame = scribus.createText(left, top, width - right - left, TITLESIZE)
        insertTextWithStyle("Index by Route Name", "Title", frame)

        frame = scribus.createText(left, top + TITLESIZE, width - right - left,
                                   height - top - bottom - TITLESIZE)
        scribus.setColumns(2, frame)
        scribus.setColumnGap(COLUMNGAP, frame)
        for route in climbnames:
            (text, style) = contents[route]
            insertTextWithStyle(text, style, frame)
            if scribus.textOverflows(frame):
                oldframe = frame
                scribus.newPage(-1)
                (top, left, right, bottom) = getCurrentPageMargins()
                frame = scribus.createText(left, top + TITLESIZE,
                                           width - right - left,
                                           height - top - bottom - TITLESIZE)
                scribus.setColumns(2, frame)
                scribus.setColumnGap(COLUMNGAP, frame)
                scribus.linkTextFrames(oldframe, frame)
Esempio n. 3
0
 def drawIndexByName(self):
    contents = {}
    climbnames = []
    for (route, grade, stars, crag, page) in self.climbs:
       text = route + chr(TAB) + str(page)
       contents[route] = (text,"Index")
       climbnames.append(route)
    climbnames.sort() 
    
    (width,height) = scribus.getPageSize()
    (top,left,right,bottom) = getCurrentPageMargins()
    frame = scribus.createText(left, top, width-right-left, TITLESIZE)
    insertTextWithStyle("Index by Route Name","Title",frame)
    
    frame = scribus.createText(left, top+TITLESIZE, width-right-left, height-top-bottom-TITLESIZE)
    scribus.setColumns(2,frame)
    scribus.setColumnGap(COLUMNGAP,frame)
    for route in climbnames:
       (text,style) = contents[route]
       insertTextWithStyle(text,style,frame)
       if scribus.textOverflows(frame):
          oldframe = frame
          scribus.newPage(-1)
          (top,left,right,bottom) = getCurrentPageMargins()
          frame = scribus.createText(left, top+TITLESIZE, width-right-left, height-top-bottom-TITLESIZE)
          scribus.setColumns(2,frame)
          scribus.setColumnGap(COLUMNGAP,frame)
          scribus.linkTextFrames(oldframe,frame)
Esempio n. 4
0
 def draw(self, tolevel):
    contents = []
    for (label,level,page) in self.sections:
       if level <= tolevel:
          text = label + chr(TAB) + str(page)
          style = "Contents" + str(level)
          contents.append((text,style))
    
    page = self.contentspage
    scribus.gotoPage(page)
    (width,height) = scribus.getPageSize()
    (top,left,right,bottom) = getCurrentPageMargins()
    frame = scribus.createText(left, top, width-right-left, TITLESIZE)
    insertTextWithStyle("Contents","Title",frame)
    
    frame = scribus.createText(left, top+TITLESIZE, width-right-left, height-top-bottom-TITLESIZE)
    scribus.setColumns(2,frame)
    scribus.setColumnGap(COLUMNGAP,frame)
    for (text,style) in contents:
       insertTextWithStyle(text,style,frame)
       if scribus.textOverflows(frame):
          oldframe = frame
          page = page + 1
          scribus.gotoPage(page)
          (top,left,right,bottom) = getCurrentPageMargins()
          frame = scribus.createText(left, top+TITLESIZE, width-right-left, height-top-bottom-TITLESIZE)
          scribus.setColumns(2,frame)
          scribus.setColumnGap(COLUMNGAP,frame)
          scribus.linkTextFrames(oldframe,frame)
Esempio n. 5
0
    def drawIndexByGrade(self):
        grades = []
        climbsatgrade = {}
        for (route, gradestr, stars, crag, page) in self.climbs:
            grade = (" " + gradestr.replace("?", "")).center(3, " ")
            if grade != "   " and route[-5:] != ", The":
                if not grade in grades: grades.append(grade)
                routename = route + " " + stars
                if not grade in climbsatgrade:
                    climbsatgrade[grade] = [(routename, page)]
                else:
                    climbsatgrade[grade] = climbsatgrade[grade] + [
                        (routename, page)
                    ]
        grades.sort()

        (width, height) = scribus.getPageSize()
        (top, left, right, bottom) = getCurrentPageMargins()
        frame = scribus.createText(left, top, width - right - left, TITLESIZE)
        insertTextWithStyle("Index by Grade", "Title", frame)

        frame = scribus.createText(left, top + TITLESIZE, width - right - left,
                                   height - top - bottom - TITLESIZE)
        scribus.setColumns(2, frame)
        scribus.setColumnGap(COLUMNGAP, frame)
        for grade in grades:
            insertTextWithStyle("Grade " + grade, "IndexGrade", frame)

            for climb in climbsatgrade[grade]:
                (route, page) = climb
                text = route + chr(TAB) + str(page)
                insertTextWithStyle(text, "Index", frame)
            if scribus.textOverflows(frame):
                oldframe = frame
                scribus.newPage(-1)
                (top, left, right, bottom) = getCurrentPageMargins()
                frame = scribus.createText(left, top + TITLESIZE,
                                           width - right - left,
                                           height - top - bottom - TITLESIZE)
                scribus.setColumns(2, frame)
                scribus.setColumnGap(COLUMNGAP, frame)
                scribus.linkTextFrames(oldframe, frame)
Esempio n. 6
0
 def createNewPage(self, tbox):
     curPage = scribus.currentPage()
     if curPage < scribus.pageCount() - 1:
         where = curPage + 1
     else:
         where = -1
     logger.debug("cur=%d name=%s pc=%d wh=%d", curPage, tbox,
                  scribus.pageCount(), where)
     cols = scribus.getColumns(tbox)
     colgap = scribus.getColumnGap(tbox)
     x, y = scribus.getPosition(tbox)
     w, h = scribus.getSize(tbox)
     mp = scribus.getMasterPage(curPage)
     scribus.newPage(where, mp)  # return val?
     scribus.gotoPage(curPage + 1)
     newBox = scribus.createText(x, y, w, h)
     scribus.setColumns(cols, newBox)
     scribus.setColumnGap(colgap, newBox)
     scribus.linkTextFrames(tbox, newBox)
     logger.debug("link from %s to %s", tbox, newBox)
     return newBox
Esempio n. 7
0
 def drawIndexByGrade(self):
    grades = []
    climbsatgrade = {}
    for (route, gradestr, stars, crag, page) in self.climbs:
       grade = (" " + gradestr.replace("?","")).center(3," ")
       if grade != "   " and route[-5:] != ", The":
          if not grade in grades: grades.append(grade)
          routename = route + " " + stars
          if not grade in climbsatgrade: 
             climbsatgrade[grade] = [(routename,page)]
          else:
             climbsatgrade[grade] = climbsatgrade[grade] + [(routename,page)]
    grades.sort() 
    
    (width,height) = scribus.getPageSize()
    (top,left,right,bottom) = getCurrentPageMargins()
    frame = scribus.createText(left, top, width-right-left, TITLESIZE)
    insertTextWithStyle("Index by Grade","Title",frame)
    
    frame = scribus.createText(left, top+TITLESIZE, width-right-left, height-top-bottom-TITLESIZE)
    scribus.setColumns(2,frame)
    scribus.setColumnGap(COLUMNGAP,frame)
    for grade in grades:
       insertTextWithStyle("Grade " + grade,"IndexGrade",frame)
    
       for climb in climbsatgrade[grade]:
          (route,page) = climb
          text = route + chr(TAB) + str(page)
          insertTextWithStyle(text,"Index",frame)
       if scribus.textOverflows(frame):
          oldframe = frame
          scribus.newPage(-1)
          (top,left,right,bottom) = getCurrentPageMargins()
          frame = scribus.createText(left, top+TITLESIZE, width-right-left, height-top-bottom-TITLESIZE)
          scribus.setColumns(2,frame)
          scribus.setColumnGap(COLUMNGAP,frame)
          scribus.linkTextFrames(oldframe,frame)
Esempio n. 8
0
def main(argv):
    unit = scribus.getUnit()
    units = [' pts','mm',' inches',' picas','cm',' ciceros']
    unitlabel = units[unit]
    if scribus.selectionCount() == 0:
        scribus.messageBox('Scribus - Script Error',
            "There is no object selected.\nPlease select a text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox('Scribus - Script Error',
            "You have more than one object selected.\nPlease select one text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    textbox = scribus.getSelectedObject()
    pageitems = scribus.getPageItems()
    boxcount = 1
    for item in pageitems:
        if (item[0] == textbox):
            if (item[1] != 4):
                scribus.messageBox('Scribus - Script Error', 
                          "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
                sys.exit(2)

# While we're finding out what kind of frame is selected, we'll also make sure we
# will come up with a unique name for our infobox frame - it's possible we may want
# more than one for a multicolumn frame.
        if (item[0] == ("infobox" + str(boxcount) + textbox)):
                boxcount += 1
    left, top = scribus.getPosition(textbox)
    o_width, o_height = scribus.getSize(textbox)
    o_cols = int(scribus.getColumns(textbox))
    o_gap = scribus.getColumnGap(textbox)
            
    columns_width = 0
    column_pos = 0
    o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols
    if (o_cols > 1):
        while (columns_width > o_cols or columns_width < 1):
            columns_width = scribus.valueDialog('Width',
                                            'How many columns width shall the '+
                                            'box be (max ' + str(o_cols) + ')?','1')
            columns_width = int(columns_width)
        if (columns_width < o_cols):
            max = o_cols - columns_width
            while (column_pos <= max and column_pos <= 1):
                column_pos = scribus.valueDialog('Placement',
                                         'In which column do you want '
                                         'to place the box (1 to ' +
                                         str(o_cols) + ')?','1')
            column_pos = int(column_pos) - 1 
    if (o_cols == 1):
	columns_width = 1
    new_height = 0
    while (new_height == 0):
        new_height = scribus.valueDialog('Height','Your frame height is '+ str(o_height) +
                                                 unitlabel +'. How tall\n do you want your ' +
                                                 'infobox to be in '+ unitlabel +'?\n If you load an image, height will be\n calculated, so the value here does not\n matter.', str(o_height))
    new_top = -1
    while (new_top < 0):
        new_top = scribus.valueDialog('Y-Pos','The top of your infobox is currently\n'+ str(top) +
                                                 unitlabel +'. Where do you want \n' +
                                                 'the top to be in '+ unitlabel +'?', str(top))
    framename = scribus.valueDialog('Name of Frame','Name your frame or use this default name',"infobox" + str(boxcount) + textbox)
    frametype = 'text'
    frametype = scribus.valueDialog('Frame Type','Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image',frametype)
    new_width = columns_width * o_colwidth + (columns_width-1) * o_gap
    new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap)
    if (frametype == 'text'):
        new_textbox = scribus.createText(new_left, float(new_top), new_width, float(new_height),framename)
        scribus.setColumnGap(0, new_textbox)
        scribus.setColumns(1, new_textbox)
        scribus.textFlowMode(new_textbox, 1)
    else:
        if (frametype == 'imageL'):
	    imageload = scribus.fileDialog('Load image','Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',haspreview=1)
	    new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename)
	    scribus.loadImage(imageload, new_image)
            scribus.messageBox('Please Note',"Your frame will be created once you click OK.\n\nUse the Context Menu to Adjust Frame to Image.\n\nIf your image does not fill the width completely,\nstretch the frame vertically first.",scribus.BUTTON_OK)
        else:
	    new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename)
        scribus.textFlowMode(new_image, 1)
        scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=new_image)
Esempio n. 9
0
def main(argv):
    unit = scribus.getUnit()
    units = [' pts', 'mm', ' inches', ' picas', 'cm', ' ciceros']
    unitlabel = units[unit]
    if scribus.selectionCount() == 0:
        scribus.messageBox(
            'Scribus - Script Error',
            "There is no object selected.\nPlease select a text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox(
            'Scribus - Script Error',
            "You have more than one object selected.\nPlease select one text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    textbox = scribus.getSelectedObject()
    pageitems = scribus.getPageItems()
    boxcount = 1
    for item in pageitems:
        if (item[0] == textbox):
            if (item[1] != 4):
                scribus.messageBox('Scribus - Script Error',
                                   "This is not a textframe. Try again.",
                                   scribus.ICON_WARNING, scribus.BUTTON_OK)
                sys.exit(2)


# While we're finding out what kind of frame is selected, we'll also make sure we
# will come up with a unique name for our infobox frame - it's possible we may want
# more than one for a multicolumn frame.
        if (item[0] == ("infobox" + str(boxcount) + textbox)):
            boxcount += 1
    left, top = scribus.getPosition(textbox)
    o_width, o_height = scribus.getSize(textbox)
    o_cols = int(scribus.getColumns(textbox))
    o_gap = scribus.getColumnGap(textbox)

    columns_width = 0
    column_pos = 0
    o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols
    if (o_cols > 1):
        while (columns_width > o_cols or columns_width < 1):
            columns_width = scribus.valueDialog(
                'Width', 'How many columns width shall the ' + 'box be (max ' +
                str(o_cols) + ')?', '1')
            columns_width = int(columns_width)
        if (columns_width < o_cols):
            max = o_cols - columns_width
            while (column_pos <= max and column_pos <= 1):
                column_pos = scribus.valueDialog(
                    'Placement', 'In which column do you want '
                    'to place the box (1 to ' + str(o_cols) + ')?', '1')
            column_pos = int(column_pos) - 1
    if (o_cols == 1):
        columns_width = 1
    new_height = 0
    while (new_height <= 0):
        new_height = scribus.valueDialog(
            'Height', 'Your frame height is ' + str(o_height) + unitlabel +
            '. How tall\n do you want your ' + 'infobox to be in ' +
            unitlabel +
            '?\n If you load an image with the script, height will be\n calculated, so the value here will not\n matter in that case.',
            str(o_height))
        if (not new_height):
            sys.exit(0)
        new_height = float(new_height)
    new_top = -1
    while (new_top < 0):
        new_top = scribus.valueDialog(
            'Y-Pos',
            'The top of your infobox is currently\n' + str(top) + unitlabel +
            '. Where do you want \n' + 'the top to be in ' + unitlabel + '?',
            str(top))
        if (not new_top):
            sys.exit(0)
        new_top = float(new_top)
    framename = scribus.valueDialog(
        'Name of Frame', 'Name your frame or use this default name',
        "infobox" + str(boxcount) + textbox)
    if (not framename):
        sys.exit(0)
    frametype = 'text'
    frametype = scribus.valueDialog(
        'Frame Type',
        'Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image',
        frametype)
    if (not frametype):
        sys.exit(0)
    new_width = columns_width * o_colwidth + (columns_width - 1) * o_gap
    new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap)
    if (frametype == 'text'):
        new_textbox = scribus.createText(new_left, float(new_top), new_width,
                                         float(new_height), framename)
        scribus.setColumnGap(0, new_textbox)
        scribus.setColumns(1, new_textbox)
        scribus.textFlowMode(new_textbox, 1)
    else:
        if (frametype == 'imageL'):
            imageload = scribus.fileDialog(
                'Load image',
                'Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',
                haspreview=1)
            new_image = scribus.createImage(new_left,
                                            float(new_top), new_width,
                                            float(new_height), framename)
            scribus.textFlowMode(new_image, 1)
            scribus.loadImage(imageload, new_image)
            scribus.setScaleImageToFrame(1, 0, new_image)
            currwidth, currheight = scribus.getSize(new_image)
            Xscale, Yscale = scribus.getImageScale(new_image)
            if (Xscale != Yscale):
                scribus.sizeObject(currwidth, currheight * Xscale / Yscale,
                                   new_image)
            scribus.setScaleImageToFrame(1, 1, new_image)
        else:
            new_image = scribus.createImage(new_left,
                                            float(new_top), new_width,
                                            float(new_height), framename)
            scribus.textFlowMode(new_image, 1)
            scribus.setScaleImageToFrame(1, 1, new_image)
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
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
Esempio n. 12
0
File: eotizer.py Progetto: pa3/eot

def getX(pageNumber):
    if pageNumber % 2 == 0:
        return 50
    return 40


if __name__ == "__main__":

    x = getX(scribus.currentPage())

    headerText = scribus.createText(x, 80, 750, 30)
    headerUnderline = scribus.createLine(x, 110, 160, 110)
    bodyText = scribus.createText(x, 120, 750, 1030)
    scribus.setColumns(4, bodyText)
    scribus.setColumnGap(10, bodyText)

    if scribus.getObjectType(bodyText) == "TextFrame":
        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)