def resizeFrame (self, frame) : '''Resize a frame in place so that it fits the text inside it. Code for this was take from: http://wiki.scribus.net/canvas/Adjust_a_text_frame_to_fit_its_content''' # Now adjust the frame to fit the text # get some page and frame measure (x, ph) = scribus.getPageSize(); (x, x, x, pm) = scribus.getPageMargins(); # warning: gets the margins from document setup not for the current page (x, y) = scribus.getPosition(frame) bottom = (ph - pm) - y (w, h) = scribus.getSize(frame) # if the frame doesn't overflow, shorten it to make it overflow while (((scribus.textOverflows(frame) == 0) or (h > bottom)) and (h > 0)) : h -= 10 scribus.sizeObject(w, h, frame) # resize the frame in 10pt steps while ((scribus.textOverflows(frame) > 0) and (h < bottom)) : h += 10 scribus.sizeObject(w, h, frame) # undo the latest 10pt step and fine adjust in 1pt steps h -= 10 scribus.sizeObject(w, h, frame) while ((scribus.textOverflows(frame) > 0) and (h < bottom)) : h += 1 scribus.sizeObject(w, h, frame) # For vertical sizing operations return the frame height return int(scribus.getSize(frame)[1])
def pasteCaption(self, xpos, ypos, text, width, imgheight=0, footer=False): height = 5 rect = scribus.createRect(xpos, ypos, width, height) scribus.setFillColor("Black", rect) scribus.setFillTransparency(0.60, rect) scribus.setCornerRadius(ROUNDS, rect) scribus.setLineColor("White", rect) scribus.setLineWidth(0.4, rect) frame = scribus.createText(xpos + 2, ypos + 1, width, height) self.styleText(text, "imageCaption", frame) scribus.setTextColor("White", frame) scribus.setFillColor("None", frame) # there are probably some performance issues in the following section of code if scribus.textOverflows(frame) == 0: # its a one liner, so shrink width while scribus.textOverflows(frame) == 0 and width > 5: width = width - 1 scribus.sizeObject(width, height, frame) scribus.sizeObject(width + 2, height, frame) scribus.sizeObject(width + 4, height, rect) else: # its a multi liner, expand vertically while scribus.textOverflows(frame) > 0: height = height + 1 scribus.sizeObject(width, height, frame) scribus.sizeObject(width, height + 1, rect) if footer: scribus.moveObject(0, imgheight - height - 1, rect) scribus.moveObject(0, imgheight - height - 1, frame) self.imageframes.append(rect) self.imageframes.append(frame)
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
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
def pasteCaption(self, xpos, ypos, text, width, imgheight=0, footer=False): height = 5 rect = scribus.createRect(xpos, ypos, width, height) scribus.setFillColor("Black",rect) scribus.setFillTransparency(0.60,rect) scribus.setCornerRadius(ROUNDS,rect) scribus.setLineColor("White",rect) scribus.setLineWidth(0.4,rect) frame = scribus.createText(xpos+2, ypos+1, width, height) self.styleText(text, "imageCaption", frame) scribus.setTextColor("White",frame) scribus.setFillColor("None",frame) # there are probably some performance issues in the following section of code if scribus.textOverflows(frame) == 0: # its a one liner, so shrink width while scribus.textOverflows(frame) == 0 and width > 5: width = width - 1 scribus.sizeObject(width, height, frame) scribus.sizeObject(width+2, height, frame) scribus.sizeObject(width+4, height, rect) else: # its a multi liner, expand vertically while scribus.textOverflows(frame) > 0: height = height + 1 scribus.sizeObject(width, height, frame) scribus.sizeObject(width, height+1, rect) if footer: scribus.moveObject(0,imgheight - height - 1,rect) scribus.moveObject(0,imgheight - height - 1,frame) self.imageframes.append(rect) self.imageframes.append(frame)
def resizeFrame(self, frame): '''Resize a frame in place so that it fits the text inside it. Code for this was take from: http://wiki.scribus.net/canvas/Adjust_a_text_frame_to_fit_its_content''' # Now adjust the frame to fit the text # get some page and frame measure (x, ph) = scribus.getPageSize() (x, x, x, pm) = scribus.getPageMargins() # warning: gets the margins from document setup not for the current page (x, y) = scribus.getPosition(frame) bottom = (ph - pm) - y (w, h) = scribus.getSize(frame) # if the frame doesn't overflow, shorten it to make it overflow while (((scribus.textOverflows(frame) == 0) or (h > bottom)) and (h > 0)): h -= 10 scribus.sizeObject(w, h, frame) # resize the frame in 10pt steps while ((scribus.textOverflows(frame) > 0) and (h < bottom)): h += 10 scribus.sizeObject(w, h, frame) # undo the latest 10pt step and fine adjust in 1pt steps h -= 10 scribus.sizeObject(w, h, frame) while ((scribus.textOverflows(frame) > 0) and (h < bottom)): h += 1 scribus.sizeObject(w, h, frame) # For vertical sizing operations return the frame height return int(scribus.getSize(frame)[1])
def expandFrame(self): """Text is inserted into a frame without regard to frame size. Later we expand the frame to fit the text, carrying text to a new frame if necessary.""" numcarries = 0 self.raiseImages() if self.frame != None: while scribus.textOverflows(self.frame, ) > 0: (x, y) = scribus.getPosition(self.frame) (width, height) = scribus.getSize(self.frame) if y + height < self.pageheight - self.bottommargin: scribus.sizeObject(width, height + 1, self.frame) else: fullpage = (y <= self.topmargin and self.columns == 1) if self.buffer != [] and not self.framelinked and numcarries < 4 and not fullpage: numcarries = numcarries + 1 scribus.deselectAll() scribus.deleteText(self.frame) for (content, style) in self.contents: self.styleText(content, style, self.frame) newcontents = self.buffer[:] self.newFrame(columns=self.columns) for (content, style) in newcontents: self.styleText(content, style, self.frame) self.buffer = newcontents[:] else: lastframe = self.frame self.newFrame(columns=self.columns) scribus.linkTextFrames(lastframe, self.frame) self.framelinked = True self.raiseImages()
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)
def expandFrame(self): """Text is inserted into a frame without regard to frame size. Later we expand the frame to fit the text, carrying text to a new frame if necessary.""" numcarries = 0 self.raiseImages() if self.frame != None: while scribus.textOverflows(self.frame,) > 0: (x,y) = scribus.getPosition(self.frame) (width,height) = scribus.getSize(self.frame) if y + height < self.pageheight - self.bottommargin: scribus.sizeObject(width, height + 1, self.frame) else: fullpage = (y <= self.topmargin and self.columns == 1) if self.buffer != [] and not self.framelinked and numcarries < 4 and not fullpage: numcarries = numcarries + 1 scribus.deselectAll() scribus.deleteText(self.frame) for (content,style) in self.contents: self.styleText(content,style,self.frame) newcontents = self.buffer[:] self.newFrame(columns=self.columns) for (content,style) in newcontents: self.styleText(content,style,self.frame) self.buffer = newcontents[:] else: lastframe = self.frame self.newFrame(columns=self.columns) scribus.linkTextFrames(lastframe,self.frame) self.framelinked = True self.raiseImages()
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)
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)
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)
def flow(self): while(scribus.textOverflows(self.name) > 0 and scribus.getTextLines(self.name)): current = self.name scribus.newPage(-1) scribus.gotoPage( scribus.pageCount() ) self.name = self.make_textframe() scribus.linkTextFrames(current, self.name)
def fit_height(textbox): # come to a state that the text box does not overflow: width, height = scribus.getSize(textbox) to_add = height + 1 while scribus.textOverflows(textbox): scribus.sizeObject(width, height + to_add, textbox) to_add = to_add * 2 # reduce height step = height / 2 overflows = False counter = 0 while step > 0.05 or overflows: counter += 1 width, old_height = scribus.getSize(textbox) if scribus.textOverflows(textbox): scribus.sizeObject(width, old_height + step, textbox) else: scribus.sizeObject(width, old_height - step, textbox) step = step * 0.5 overflows = scribus.textOverflows(textbox)
def fit_height(textbox): # come to a state that the text box does not overflow: width, height = scribus.getSize(textbox) to_add = height + 1 while scribus.textOverflows(textbox): scribus.sizeObject(width, height + to_add, textbox) to_add = to_add * 2 # reduce height step = height/2 overflows = False counter = 0 while step > 0.05 or overflows: counter += 1 width, old_height = scribus.getSize(textbox) if scribus.textOverflows(textbox): scribus.sizeObject(width, old_height + step, textbox) else: scribus.sizeObject(width, old_height - step, textbox) step = step * 0.5 overflows = scribus.textOverflows(textbox)
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)
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)
elif frame_n > 1 : scribus.messageBox('Error:', 'You may select only one frame'); sys.exit(1) frame = scribus.getSelectedObject(0) try: char_n = scribus.getTextLength(frame) except scribus.WrongFrameTypeError: scribus.messageBox('Error:', 'You may only adjust text frames'); sys.exit(1) if char_n == 0 : scribus.messageBox('Error:', 'You can\'t adjust an empty frame'); sys.exit(1) if (scribus.textOverflows(frame) == 1) : scribus.messageBox('Error:', 'You can\' center a text which is overflowing'); sys.exit(1) # get some page and frame measure (x, y) = scribus.getPosition(frame) (w, h) = scribus.getSize(frame) original_height = h (dl, dr, dt, db) = scribus.getTextDistances(); scribus.setTextDistances(dl, dr, 0, 0);
def importSocietes(filename, fileCat, iPro): arrLines=[]#liste de lignes du fichier csv, chaque ligne est une liste de champs mapCol={}#table de correspondance entre les champs à importer et les numéros de colonne du fichier csv mapCat={}#table de correspondance entre numéro de catégorie et nom de catégorie nbCat=readSocietes(filename, fileCat, mapCat, arrLines, mapCol) (nbChg, nbPro)=(0,0) numPro=1 while scribus.getTextLength("txtPros%d" % numPro)>0 and numPro<=NB_TXT: numPro+=1 if iPro==1 and scribus.objectExists("txtBureauxChange"): scribus.deleteText("txtBureauxChange") scribus.progressTotal(len(arrLines)) strPro="txtPros%d"%numPro scribus.statusMessage("Remplissage du cadre de texte %s..."%strPro) bFirstPro=True strCat="#" for record in arrLines:#Pour chaque pro # log("nbPro=%d\n"%nbPro) if strCat != record[mapCol["cat"]]:#nouvelle categorie strCat=record[mapCol["cat"]] bNewCat=True else: bNewCat=False nbPro+=1 if nbPro<iPro:#déjà importé à l'exécution précédente continue try: scribus.progressSet(nbPro) if record[mapCol["chg"]]=="True" and scribus.objectExists("txtBureauxChange"): try: nbCarBureau=scribus.getTextLength("txtBureauxChange") appendText(u"● "+toUnicode(record[mapCol["nom"]])+"\n","styleChangeTitre","txtBureauxChange") appendText(toUnicode(record[mapCol["adr"]].replace("\\n"," - "))+"\n","styleChangeAdresse","txtBureauxChange") appendText(record[mapCol["post"]]+" "+toUnicode(record[mapCol["ville"]].upper()+"\n"),"styleChangeAdresse","txtBureauxChange") nbChg+=1 except Exception as ex: scribus.messageBox( "Erreur","Une erreur est survenue sur ce bureau de change: \n%s\n\n%s" %(record, str(ex))) sys.exit() else : nbCarBureau=0 nbCar=scribus.getTextLength(strPro) if bNewCat or bFirstPro: if bFirstPro and not bNewCat: appendText(toUnicode(strCat+" (suite)")+"\n","styleProCatSuite",strPro) else: appendText(toUnicode(strCat)+"\n","styleProCat",strPro) bFirstPro=False appendText(u"● "+toUnicode(record[mapCol["nom"]])+"\n","styleProTitre",strPro) if record[mapCol["chg"]]=="True" : appendText(u"\n","styleProBureau",strPro) #icone du bureau de change en police FontAwesome appendText(processDesc(toUnicode(record[mapCol["desc"]]))+"\n","styleProDesc",strPro) if bLivret: strAdr=toUnicode(record[mapCol["adr"]].replace("\\n"," - "))+" - " + toUnicode(record[mapCol["post"]])+" " strAdr+=processDesc(toUnicode(record[mapCol["ville"]].upper())) if record[mapCol["tel"]].strip(): strAdr+=" ("+toUnicode(record[mapCol["tel"]].strip().replace(" ","\xC2\xA0"))+")\n" #numéro de téléphone insécable else: strAdr+="\n" appendText(strAdr, "styleProAdresse", strPro) else: appendText(toUnicode(record[mapCol["adr"]].replace("\\n"," - "))+"\n","styleProAdresse",strPro) appendText(toUnicode(record[mapCol["post"]])+" "+processDesc(toUnicode(record[mapCol["ville"]]).upper())+"\n","styleProAdresse",strPro) if record[mapCol["tel"]].strip(): appendText(processTelephone(record[mapCol["tel"]])+"\n","styleProAdresse",strPro) if scribus.textOverflows(strPro, nolinks=1): #effacement du paragraphe de pro tronqué et du bureau de change en double scribus.selectText(nbCar, scribus.getTextLength(strPro)-nbCar, strPro) scribus.deleteText(strPro) if nbCarBureau: scribus.selectText(nbCarBureau, scribus.getTextLength("txtBureauxChange")-nbCarBureau, "txtBureauxChange") scribus.deleteText("txtBureauxChange") #log("Cadre rempli : le cadre de texte %s est plein à la ligne %d\n" % (strPro, nbPro)) break except Exception as exc: scribus.messageBox( "Erreur","Une erreur est survenue sur ce professionnel: \n%s\n\n%s" %(record, str(exc))) sys.exit() return (nbChg, nbPro, nbCat)
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
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() scribus.setRedraw(False) 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) lines = scribus.getTextLines(textbox) distances = scribus.getTextDistances(textbox) linespace = scribus.getLineSpacing(textbox) dimensions = scribus.getSize(textbox) # (width, height) if (scribus.textOverflows(textbox, 1) > 0): scribus.messageBox('User Error', "This frame is already overflowing", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) newtopdist = (dimensions[1] - linespace * lines) / 2 scribus.setTextDistances(distances[0], distances[1], newtopdist, distances[3], textbox) scribus.setRedraw(True)
item = scribus.getSelectedObject() if (scribus.getObjectType(item) != 'TextFrame'): scribus.messageBox('Usage Error', 'You need to select a text frame') sys.exit(2) print(scribus.getTextLength(item)) if scribus.getTextLength(item) > 0: scribus.messageBox('Usage Error', 'The text frame should be empty') sys.exit(2) answer = scribus.valueDialog('Numbered lines', 'Start number, step', '1,1') start, step = answer.split(',') start = int(start) step = int(step) i = start print(scribus.textOverflows(item)) while scribus.textOverflows(item) == 0: if i == start or i % step == 0: scribus.insertText(str(i) + "\n", -1, item) else: scribus.insertText("\n", -1, item) i += 1 length = scribus.getTextLength(item) while scribus.textOverflows(item) != 0: scribus.selectText(length - 2, 1, item) scribus.deleteText(item) length -= 1
# scribus.openDoc(os.path.dirname(os.path.realpath(__file__)) + '/cards.sla') # scribus.openDoc(os.path.dirname(os.path.realpath(sys.argv[0])) + '/cards.sla') scribus.messageBox("Error", "You should first open the cards.sla file", ICON_WARNING, BUTTON_OK) sys.exit(1) # for page in range(2, scribus.pageCount()) : # scribus.messageBox("Error", str(scribus.pageCount()), ICON_WARNING, BUTTON_OK) for page in range(scribus.pageCount(), 1, -1) : scribus.deletePage(page) for project in projects : scribus.newPage(-1, project['section']) # title: x=10 y=10 w=85mm h=20 # description: x=10 y=40 w=85mm h=80 titleFrame = scribus.createText(10, 10, 85, 20) scribus.setText(project['title'], titleFrame) scribus.setStyle('title', titleFrame) descriptionFrame = scribus.createText(10, 40, 85, 80) scribus.setText(project['description'], descriptionFrame) scribus.setStyle('description', descriptionFrame) # shrink the title and text size if it does not fit in the frame while scribus.textOverflows(titleFrame) != 0 : fontSize = scribus.getFontSize(titleFrame) scribus.setFontSize(fontSize - 1, titleFrame) while scribus.textOverflows(descriptionFrame) != 0 : fontSize = scribus.getFontSize(descriptionFrame) scribus.setFontSize(fontSize - 1, descriptionFrame)
def handleEnd(self): self.linkType = self.gui.getLinkType() self.gliederung = self.gui.getGliederung() self.includeSub = self.gui.getIncludeSub() self.start = self.gui.getStart() self.end = self.gui.getEnd() pos1, pos2, tbox = self.toBeDelPosParam scribus.selectText(pos1, pos2 - pos1, tbox) scribus.deleteText(tbox) pagenum = scribus.pageCount() for page in range(1, pagenum + 1): scribus.gotoPage(page) pageitems = scribus.getPageItems() for item in pageitems: if item[1] != 4: continue self.textbox = item[0] self.evalTemplate() # hyphenate does not work # pagenum = scribus.pageCount() # for page in range(1, pagenum + 1): # scribus.gotoPage(page) # pageitems = scribus.getPageItems() # for item in pageitems: # if item[1] != 4: # continue # self.textbox = item[0] # b = scribus.hyphenateText(self.textbox) # seems to have no effect! pagenum = scribus.pageCount() for page in range(1, pagenum + 1): scribus.gotoPage(page) pageitems = scribus.getPageItems() for item in pageitems: if item[1] != 4: continue tbox = item[0] tbox2 = tbox while scribus.textOverflows(tbox2): tbox2 = self.createNewPage(tbox2) self.frameLinks[ tbox2] = tbox # frame tbox2 has tbox as root scribus.redrawAll() ausgabedatei = self.ausgabedatei if ausgabedatei is None or ausgabedatei == "": ausgabedatei = "ADFC_" + self.gliederung + ( "_I_" if self.includeSub else "_" ) + self.start + "-" + self.end + "_" + self.linkType[0] + ".sla" try: scribus.saveDocAs(ausgabedatei) except Exception as e: print("Ausgabedatei", ausgabedatei, "konnte nicht geschrieben werden") raise e finally: self.touren = [] self.termine = [] # self.gui.destroy() # self.gui.quit() self.gui.disableStart()
def main(argv): userdim = scribus.getUnit() # get unit and change it to mm scribus.setUnit(scribus.UNIT_MILLIMETERS) cellwidthleft = 0 cellwidthright = 0 # Set starting position hposition = 28 vposition = 20 data = getCSVdata() di = getDataInformation(data) ncol = len(data[0]) nrow = len(data) scribus.messageBox("Table", " " + str(ncol) + " columns, " + str(nrow) + " rows ") #jpg ColWidthList = [] TableWidth = 0 RowHeightList = [] TableHeight = 0 i = 0 for row in data: if i == 0: c = 0 for cell in row: ColWidth = 40 ColWidthList.append(ColWidth) TableWidth = TableWidth + ColWidth c = c + 1 RowHeight = 15 RowHeightList.append(RowHeight) TableHeight = TableHeight + RowHeight i = i + 1 objectlist = [ ] # here we keep a record of all the created textboxes so we can group them later i = 0 scribus.progressTotal(len(data)) scribus.setRedraw(False) rowindex = 0 new_row_indication = 1 new_page_indication = 1 firstorigin_indicator = 1 while rowindex < len(data): c = 0 origin_cd = data[rowindex][0].strip() origin = data[rowindex][1].strip() origin_complete = origin + ' (' + origin_cd + ")" headerorigin = origin_complete origin_added = 0 destination_cd = data[rowindex][2].strip() destination = data[rowindex][3].strip() destination_complete = destination + ' (' + destination_cd + ")" fareplan = data[rowindex][4].strip() fareplan_type = data[rowindex][5].strip() fareplan_complete = fareplan + ' ' + fareplan_type[:1] fare = data[rowindex][6].strip() fare = float(fare) fare = "{0:.2f}".format(fare) fare_onboard = data[rowindex][7].strip() fare_onboard = float(fare_onboard) fare_onboard = "{0:.2f}".format(fare_onboard) cellheight_market = 5 cellheight_market_dos = 5 try: last_origin = data[rowindex - 1][1].strip() except: last_origin = origin try: last_destination = data[rowindex - 1][3].strip() except: last_destination = destination cellsize = ColWidthList[c] cellHeight = RowHeightList[i] # Check to see if near bottom of the page, if so wrap it over if (vposition > 227): hposition = hposition + cellsize vposition = 20 new_row_indication = 1 # If at end, reset and create new page if (hposition > 174): scribus.newPage(-1) hposition = 28 vposition = 20 new_page_indication = 1 firstorigin_indicator = 0 if new_row_indication == 1: textbox = scribus.createText(hposition, 16, cellsize / 2, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle('FareplanHeader', textbox) scribus.insertText('Fareplan', 0, textbox) c = c + 1 textbox = scribus.createText(hposition + (cellsize / 2), 16, cellsize / 2, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle('FareplanHeader', textbox) scribus.insertText('Amount', 0, textbox) c = c + 1 # if (firstorigin_indicator == 1): # headerorigin = origin_complete # textbox = scribus.createText(20, 10, cellsize*4, 4) # create a textbox. # objectlist.append(textbox) # scribus.setStyle('HeaderOrigin', textbox) # scribus.insertText(headerorigin, 0, textbox) # c = c + 1 # Origin textbox if (rowindex < len(data)): if ((origin != last_origin) or (rowindex == 0)): # Add 'btwn' text textbox = scribus.createText(hposition, vposition, cellsize, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle( 'Headings', textbox ) # set it in the style 'Headings' as defined in Scribus. scribus.insertText( 'btwn', 0, textbox) # insert the origin into the textbox. # scribus.setDistances(1,1,1,1) # set the distances. vposition = vposition + 4 # Shift position of cell down. c = c + 1 textbox = scribus.createText( hposition, vposition, cellsize, cellheight_market_dos) # create a textbox. objectlist.append(textbox) scribus.setStyle( 'Headings', textbox ) # set it in the style 'Headings' as defined in Scribus. scribus.insertText( origin_complete, 0, textbox) # insert the origin into the textbox. while (scribus.textOverflows(textbox) > 0): cellheight_market_dos += 1 scribus.sizeObject(cellsize, cellheight_market_dos, textbox) vposition = vposition + cellheight_market_dos # Shift position of cell down. c = c + 1 # Add 'and' text textbox = scribus.createText(hposition, vposition, cellsize, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle( 'andStyle', textbox ) # set it in the style 'andStyle' as defined in Scribus. scribus.insertText( 'and', 0, textbox) # insert the origin into the textbox. vposition = vposition + 4 # Shift position of cell down. c = c + 1 origin_added = 1 firstorigin_indicator = firstorigin_indicator + 1 # Insert the origin at the top margin if (firstorigin_indicator == 1 or rowindex == 0): headerorigin = origin_complete textbox = scribus.createText(28, 10, cellsize * 4, 4) # create a textbox. objectlist.append(textbox) scribus.setStyle('HeaderOrigin', textbox) scribus.insertText(headerorigin, 0, textbox) c = c + 1 # Destination textbox if ((destination != last_destination) or (rowindex == 0) or (origin_added == 1)): textbox = scribus.createText( hposition, vposition, cellsize, cellheight_market) # create a textbox. objectlist.append(textbox) scribus.setStyle( 'Headings', textbox ) # set it in the style 'Headings' as defined in Scribus. scribus.insertText( destination_complete, 0, textbox) # insert the destination into the textbox. while (scribus.textOverflows(textbox) > 0): cellheight_market += 1 scribus.sizeObject(cellsize, cellheight_market, textbox) vposition = vposition + cellheight_market # Shift position of cell down. c = c + 1 rowindex = rowindex + 1 # Fareplan textbox fareplan_box_height = 5 if fare_onboard != '0.00': fareplan_box_height = 10 textbox = scribus.createText(hposition, vposition, cellsize / 2, fareplan_box_height) # create a textbox. objectlist.append(textbox) scribus.insertText(fareplan_complete, 0, textbox) # insert the fareplan into the textbox. hposition = hposition + (cellsize / 2) # Shift position of cell right. c = c + 1 # Fare textbox textbox = scribus.createText(hposition, vposition, cellsize / 2, 5) # create a textbox. objectlist.append(textbox) scribus.insertText(fare, 0, textbox) # insert the fare into the textbox. c = c + 1 if fare_onboard != '0.00': vposition = vposition + 5 # Shift position of cell down. textbox = scribus.createText(hposition, vposition, cellsize / 2, 5) # create a textbox. objectlist.append(textbox) scribus.setStyle('OnBoard', textbox) scribus.insertText(fare_onboard, 0, textbox) # insert the fare into the textbox. hposition = hposition - (cellsize / 2 ) # Shift position of cell back. vposition = vposition + 5 # Shift position of cell down. c = c + 1 else: hposition = hposition - (cellsize / 2 ) # Shift position of cell back. vposition = vposition + 5 # Shift position of cell down. i = i + 1 new_row_indication = 0 new_page_indication = 0 scribus.deselectAll() scribus.groupObjects(objectlist) scribus.progressReset() scribus.setUnit(userdim) # reset unit to previous value scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)