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
def add_page_number(): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(page_num) textbox = scribus.createText(margin_left, page_height-margin_bottom, page_width-margin_left-margin_right, PAGE_NUM_HEIGHT) scribus.setStyle("pagenumber_{}".format(get_style_suffix()), textbox) scribus.insertText(str(page_num), 0, textbox) scribus.deselectAll()
def drawHeaderFooter(pagetitle): """draw some info on the pages""" # get page size pageSize=scribus.getPageSize() pageWidth=pageSize[0] pageHeight=pageSize[1] #pageMargins pageMargins=scribus.getPageMargins() topMargin=pageMargins[0] leftMargin=pageMargins[1] rightMargin=pageMargins[2] bottomMargin=pageMargins[3] #create textbox and insert text for header textbox=scribus.createText(leftMargin, topMargin, pageWidth-leftMargin-rightMargin, HEADERSIZE) #set proper font size and alignment scribus.setFontSize(18, textbox) scribus.setTextAlignment(scribus.ALIGN_CENTERED, textbox) #load the string into the textbox headerstring=pagetitle scribus.insertText(headerstring, 0, textbox) scribus.setTextColor("Black", textbox) #create textbox and insert text for footer textbox=scribus.createText(leftMargin, pageHeight-bottomMargin-FOOTERSIZE, pageWidth-leftMargin-rightMargin, FOOTERSIZE) #set proper font size and alignment scribus.setFontSize(9, textbox) scribus.setTextAlignment(scribus.ALIGN_LEFT, textbox) #load the string into the textbox footerstring="Created using ColorChart.py V %s script for Scribus by Sebastian Stetter - http://www.sebastianstetter.de" % str(__version__) scribus.insertText(footerstring, 0, textbox) scribus.setTextColor("Black", textbox)
def insertText(self, text, run): if text is None or text == "": return pos = self.insertPos scribus.insertText(text, pos, self.textbox) tlen = len(text) logger.debug( "insert pos=%d len=%d npos=%d text='%s' style=%s cstyle=%s", pos, tlen, pos + tlen, text, run.pstyle, run.cstyle) global lastPStyle, lastCStyle if run.pstyle != lastPStyle: scribus.selectText(pos, tlen, self.textbox) scribus.setParagraphStyle( noPStyle if run.pstyle is None else run.pstyle, self.textbox) lastPStyle = run.pstyle if run.cstyle != lastCStyle: scribus.selectText(pos, tlen, self.textbox) scribus.setCharacterStyle( noCStyle if run.cstyle is None else run.cstyle, self.textbox) lastCStyle = run.cstyle if False and self.url is not None: # TODO logger.debug("URL: %s", self.url) scribus.selectText(pos, tlen, self.textbox) frame = None # see http://forums.scribus.net/index.php/topic,3487.0.html scribus.setURIAnnotation(self.url, frame) self.url = None self.insertPos += tlen
def insertTextWithStyle(txt,style,frame): start = scribus.getTextLength(frame) scribus.insertText(txt, -1, frame) scribus.selectText(start, len(txt), frame) try: scribus.setStyle(style, frame) except scribus.NotFoundError: scribus.createParagraphStyle(style) scribus.setStyle(style, frame) scribus.insertText("\n", -1, frame)
def add_page_number(): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin( page_num) textbox = scribus.createText(margin_left, page_height - margin_bottom, page_width - margin_left - margin_right, PAGE_NUM_HEIGHT) scribus.setStyle("pagenumber_{}".format(get_style_suffix()), textbox) scribus.insertText(str(page_num), 0, textbox) scribus.deselectAll()
def insertTextWithStyle(txt, style, frame): start = scribus.getTextLength(frame) scribus.insertText(txt, -1, frame) scribus.selectText(start, len(txt), frame) try: scribus.setStyle(style, frame) except scribus.NotFoundError: scribus.createParagraphStyle(style) scribus.setStyle(style, frame) scribus.insertText("\n", -1, frame)
def create_toc(data): if not scribus.objectExists("TOC"): new_page() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(1) toc = scribus.createText(margin_left, margin_top, page_width-margin_right-margin_left, page_height-margin_top-margin_bottom) scribus.setNewName("TOC", toc) scribus.insertText("provide a textframe with name 'TOC' in front_matter.sla and i will not create the toc at the end of the document", 0, "TOC") text = "\n".join(("{}\t{}".format(title, pagenum) for (title, pagenum) in data)) scribus.insertText(text, -1, "TOC")
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
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 # ######################### userdim = scribus.getUnit() # get unit and change it to mm scribus.setUnit(scribus.UNIT_MILLIMETERS) cellwidthleft = 0 cellwidthright = 0 cellHeight = 0 pos = getPosition() while cellwidthleft <= 0: cellwidthL = scribus.valueDialog("Left Cell Width", "How wide (mm) do you wish left cells to be?", "30.0") cellwidthleft = float(cellwidthL) while cellwidthright <= 0: cellwidthR = scribus.valueDialog("Right Cell Width", "How wide (mm) do you wish right cells to be?", "30.0") cellwidthright = float(cellwidthR) while cellHeight <= 0: cellheight = scribus.valueDialog("Cell Height", "How tall (mm) do you wish cells to be?", "10.0") cellHeight = float(cellheight) data = getCSVdata() di = getDataInformation(data) hposition = pos[1] vposition = pos[0] 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) for row in data: c = 0 for cell in row: cell = cell.strip() cellsize = cellwidthleft if c == 1: cellsize = cellwidthright textbox = scribus.createText(hposition, vposition, cellsize, cellHeight) # create a textbox objectlist.append(textbox) scribus.insertText(cell, 0, textbox) # insert the text into the textbox hposition = hposition + cellwidthleft # move the position for the next cell c = 1 vposition = vposition + cellHeight # set vertical position for next row hposition = pos[1] # reset vertical position for next row i = i + 1 scribus.progressSet(i) scribus.groupObjects(objectlist) scribus.progressReset() scribus.setUnit(userdim) # reset unit to previous value scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)
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
def fill_text_placeholders(frame, fields, row): for field in fields: # TODO: currently, if the fields is not found it's left as is, with no warning if field['key'] in row: scribus.insertText(row[field['key']], field['start'] + 1, frame) # delete "key}" scribus.selectText(field['start'] + len(row[field['key']]) + 1, field['end'] - field['start'], frame) scribus.deleteText(frame) # delete "{" scribus.selectText(field['start'], 1, frame) scribus.deleteText(frame)
def replaceText(text, code): if text is None or text is u'': logger.warn(".. empty content for elem [%s]", code) text = ' ' l = scribus.getTextLength(code) scribus.selectText(0, l - 1, code) scribus.deleteText(code) scribus.insertText(text, 0, code) l = scribus.getTextLength(code) scribus.selectText(l - 1, 1, code) scribus.deleteText(code)
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
def insertText(self, text, pStyle): if text is None or text == "": return pos = self.insertPos scribus.insertText(text, pos, self.textbox) tlen = len(text) if pStyle is None: pStyle = self.lastPStyle # if cStyle is None: # cStyle = self.lastCStyle scribus.selectText(pos, tlen, self.textbox) scribus.setParagraphStyle(pStyle, self.textbox) self.lastPStyle = pStyle # scribus.setCharacterStyle(cStyle, self.textbox) # self.lastCStyle = cStyle self.insertPos += tlen
def create_toc(data): if not scribus.objectExists("TOC"): new_page() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin( 1) toc = scribus.createText(margin_left, margin_top, page_width - margin_right - margin_left, page_height - margin_top - margin_bottom) scribus.setNewName("TOC", toc) scribus.insertText( "provide a textframe with name 'TOC' in front_matter.sla and i will not create the toc at the end of the document", 0, "TOC") text = "\n".join( ("{}\t{}".format(title, pagenum) for (title, pagenum) in data)) scribus.insertText(text, -1, "TOC")
def drawColor(colorname, h, v, width, height): # h horizontal position, v vertical position """draws a color chart field with its caption for the given colorname at the h and v position """ # get cmyk values and convert them to 0 - 255 values color = scribus.getColor(colorname) c = int(round(color[0] / 2.55)) m = int(round(color[1] / 2.55)) y = int(round(color[2] / 2.55)) k = int(round(color[3] / 2.55)) # get rgb color rgbcolor = scribus.getColorAsRGB(colorname) r = rgbcolor[0] g = rgbcolor[1] b = rgbcolor[2] # get webcolor webcolor = rgbhex(r, g, b) # but String for Textbox together colorDisplay = colorname if scribus.isSpotColor(colorname): colorDisplay += " (Spot Color)" colorstring = "%s\nC %i, M %i, Y %i, K %i, \nR %i, G %i, B %i \nRGB: %s" % ( colorDisplay, c, m, y, k, r, g, b, webcolor, ) # draw rectangle and set colors rect = scribus.createRect(h, v, width, height) scribus.setFillColor(colorname, rect) # if total amount of color is < 20 draw outline in Black for rectangle, else in same color if c + m + y + k < 20: scribus.setLineColor("Black", rect) else: scribus.setLineColor(colorname, rect) # create textbox and insert text textbox = scribus.createText(h + width + 5, v, 50, height) # set proper font size scribus.setFontSize(11, textbox) scribus.setTextAlignment(scribus.ALIGN_LEFT, textbox) # load the string into the textbox scribus.insertText(colorstring, 0, textbox)
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()
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
def draw(self): if self.txt != "": if scribus.currentPage() % 2 == 0: r = scribus.createRect(-1,self.y,8,self.height) t = scribus.createText(2,self.y + self.height,self.height,6) else: (pagewidth, pageheight) = scribus.getPageSize() r = scribus.createRect(pagewidth-7,self.y,8,self.height) t = scribus.createText(pagewidth-5,self.y + self.height,self.height,6) scribus.setFillColor("Black",r) scribus.setFillShade(20,r) scribus.setLineColor("None",r) scribus.setCornerRadius(ROUNDS,r) scribus.insertText(self.txt, -1, t) scribus.deselectAll() scribus.selectObject(t) scribus.selectText(0, len(self.txt), t) scribus.setStyle("Sidebar", t) scribus.rotateObject(90,t) self.frames.append(r) self.frames.append(t)
def drawColor(colorname, h, v, width, height): #h horizontal position, v vertical position """draws a color chart field with its caption for the given colorname at the h and v position """ #get cmyk values and convert them to 0 - 255 values color = scribus.getColor(colorname) c = int(round(color[0] / 2.55)) m = int(round(color[1] / 2.55)) y = int(round(color[2] / 2.55)) k = int(round(color[3] / 2.55)) #get rgb color rgbcolor = scribus.getColorAsRGB(colorname) r = rgbcolor[0] g = rgbcolor[1] b = rgbcolor[2] #get webcolor webcolor = rgbhex(r, g, b) #but String for Textbox together colorDisplay = colorname if scribus.isSpotColor(colorname): colorDisplay += " (Spot Color)" colorstring = "%s\nC %i, M %i, Y %i, K %i, \nR %i, G %i, B %i \nRGB: %s" % ( colorDisplay, c, m, y, k, r, g, b, webcolor) #draw rectangle and set colors rect = scribus.createRect(h, v, width, height) scribus.setFillColor(colorname, rect) #if total amount of color is < 20 draw outline in Black for rectangle, else in same color if c + m + y + k < 20: scribus.setLineColor("Black", rect) else: scribus.setLineColor(colorname, rect) #create textbox and insert text textbox = scribus.createText(h + width + 5, v, 50, height) #set proper font size scribus.setFontSize(11, textbox) scribus.setTextAlignment(scribus.ALIGN_LEFT, textbox) #load the string into the textbox scribus.insertText(colorstring, 0, textbox) scribus.setTextColor("Black", textbox)
def draw(self): if self.txt != "": if scribus.currentPage() % 2 == 0: r = scribus.createRect(-1, self.y, 8, self.height) t = scribus.createText(2, self.y + self.height, self.height, 6) else: (pagewidth, pageheight) = scribus.getPageSize() r = scribus.createRect(pagewidth - 7, self.y, 8, self.height) t = scribus.createText(pagewidth - 5, self.y + self.height, self.height, 6) scribus.setFillColor("Black", r) scribus.setFillShade(20, r) scribus.setLineColor("None", r) scribus.setCornerRadius(ROUNDS, r) scribus.insertText(self.txt, -1, t) scribus.deselectAll() scribus.selectObject(t) scribus.selectText(0, len(self.txt), t) scribus.setStyle("Sidebar", t) scribus.rotateObject(90, t) self.frames.append(r) self.frames.append(t)
for item in scribus.getPageItems(): if item[1] == 4: scribus.deselectAll() scribus.selectObject(item[0]) content = scribus.getFrameText() next_line_feed = content.find('\r') start_selection = 0 while next_line_feed >= 0: line = content[start_selection:next_line_feed] if len(line) > 0: scribus.selectFrameText(start_selection, 1) style = scribus.getParagraphStyle() if style in toc_styles: toc_content.append((content[start_selection:next_line_feed], page, toc_styles[style])) start_selection = next_line_feed + 1 next_line_feed = content.find('\r', next_line_feed + 1) scribus.deselectAll() scribus.selectObject(toc_frame) # print(toc_content) scribus.deleteText() position = 0 for toc_item in toc_content: toc_item_content = toc_item[0] + '\t' + str(toc_item[1]) scribus.insertText(toc_item_content, -1) scribus.selectText(position, 1) scribus.setParagraphStyle(toc_item[2]) scribus.insertText('\r', -1) position += len(toc_item_content) + 1
def appendText(strTxt, strStyle, strName): #log(strName+"<- "+strTxt) scribus.setStyle(strStyle, strName) scribus.insertText(strTxt, -1, strName)
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
nextchar = ' ' else: scribus.selectText(c+1, 1, textbox) nextchar = scribus.getText(textbox) scribus.selectText(c, 1, textbox) char = scribus.getText(textbox) if (len(char) != 1): c += 1 if (char == '-'): if (prevchar == '-'): if (nextchar == '-'): scribus.selectText(c-1, 3, textbox) scribus.deleteText(textbox) scribus.insertText(mdash, c-1, textbox) char = mdash else: scribus.selectText(c-1, 2, textbox) scribus.deleteText(textbox) scribus.insertText(ndash, c-1, textbox) char = ndash else: c += 1 else: c += 1 prevchar = char contents = scribus.getTextLength(textbox)
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 # ######################### userdim = scribus.getUnit() #get unit and change it to mm scribus.setUnit(scribus.UNIT_MILLIMETERS) cellwidthleft = 0 cellwidthright = 0 cellHeight = 0 pos = getPosition() while cellwidthleft <= 0: cellwidthL = scribus.valueDialog( 'Left Cell Width', 'How wide (mm) do you wish left cells to be?', '30.0') cellwidthleft = float(cellwidthL) while cellwidthright <= 0: cellwidthR = scribus.valueDialog( 'Right Cell Width', 'How wide (mm) do you wish right cells to be?', '30.0') cellwidthright = float(cellwidthR) while cellHeight <= 0: cellheight = scribus.valueDialog( 'Cell Height', 'How tall (mm) do you wish cells to be?', '10.0') cellHeight = float(cellheight) data = getCSVdata() di = getDataInformation(data) hposition = pos[1] vposition = pos[0] 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) for row in data: c = 0 for cell in row: cell = cell.strip() cellsize = cellwidthleft if c == 1: cellsize = cellwidthright textbox = scribus.createText(hposition, vposition, cellsize, cellHeight) #create a textbox objectlist.append(textbox) scribus.insertText(cell, 0, textbox) #insert the text into the textbox hposition = hposition + cellwidthleft #move the position for the next cell c = 1 vposition = vposition + cellHeight #set vertical position for next row hposition = pos[1] #reset vertical position for next row i = i + 1 scribus.progressSet(i) scribus.groupObjects(objectlist) scribus.progressReset() scribus.setUnit(userdim) # reset unit to previous value scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)
sys.exit(2) contents = scribus.getTextLength(textbox) while c <= (contents -1): if ((c + 1) > contents - 1): nextchar = ' ' else: scribus.selectText(c+1, 1, textbox) nextchar = scribus.getText(textbox) scribus.selectText(c, 1, textbox) char = scribus.getText(textbox) if (len(char) != 1): c += 1 continue if ((ord(char) == 34) and (c == 0)): scribus.deleteText(textbox) scribus.insertText(lead_double, c, textbox) elif (ord(char) == 34): if ((prevchar == '.') or (prevchar == ',') or (prevchar == '?') or (prevchar == '!')): scribus.deleteText(textbox) scribus.insertText(follow_double, c, textbox) elif ((ord(prevchar) == 39) and ((nextchar != ' ') and (nextchar != ',') and (nextchar != '.'))): scribus.deleteText(textbox) scribus.insertText(lead_double, c, textbox) elif ((nextchar == '.') or (nextchar == ',')): scribus.deleteText(textbox) scribus.insertText(follow_double, c, textbox) elif ((prevchar == ' ') or ((nextchar != ' ') and (ord(nextchar) != 39))): scribus.deleteText(textbox) scribus.insertText(lead_double, c, textbox) else:
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.ICON_WARNING, scribus.BUTTON_OK) if (char==ouvrant_double): if (lastchange=='open'): if (lang=='fr'): scribus.messageBox("Oups !", 'Incohérence dans les enchainements de guillemets ouvrant et fermant. Une guillement fermante manque avant la position '+str(c) +'\nOn continue quand même', scribus.ICON_WARNING, scribus.BUTTON_OK) else: scribus.messageBox("Oops !", 'text is not consistent. Closing doublequote missing before position '+str(c), scribus.ICON_WARNING, scribus.BUTTON_OK) lastchange='open' if ((replace_existing == 1) and (nextchar != spacenquotes) and (alafin==0)): if (est_espace(nextchar)): scribus.selectText(c+1, 1, textbox) scribus.deleteText(textbox) scribus.insertText(spacenquotes, c+1, textbox) nbchange = nbchange+1 elif (char==fermant_double): if (lastchange=='close'): if (lang=='fr'): scribus.messageBox("Oups !", 'Incohérence dans les enchainements de guillemets ouvrant et fermant. Une guillemet ouvrante manque avant la position '+str(c) +'\nOn continue quand même', scribus.ICON_WARNING, scribus.BUTTON_OK) else: scribus.messageBox("Oops !", 'text is not consistent. Opening doublequote missing before position '+str(c), scribus.ICON_WARNING, scribus.BUTTON_OK) lastchange = 'close' if ((replace_existing == 1) and (prevchar != spacenquotes) and (c > 1)): if (est_espace(prevchar)): scribus.selectText(c-1, 1, textbox) scribus.deleteText(textbox)
# encoding: utf-8 try: import scribus except ImportError: print('This script must be run from inside Scribus') text = scribus.getText() print(text) i = text.find('{') j = text.find('}', i) print(i) print(j) print(text[i+1:j]) scribus.selectText(i, j - i) text = scribus.getText() print('>>>>' + text) value = 'replacement' scribus.insertText(value, i + 1) # delete placelholder} scribus.selectText(i + len(value) + 1, j - i) scribus.deleteText() # { scribus.selectText(i, 1) scribus.deleteText()
"Oups !", 'Incohérence dans les enchainements de guillemets ouvrant et fermant. Une guillement fermante manque avant la position ' + str(c) + '\nOn continue quand même', scribus.ICON_WARNING, scribus.BUTTON_OK) else: scribus.messageBox( "Oops !", 'The text is not consistent. Closing doublequote missing before position ' + str(c), scribus.ICON_WARNING, scribus.BUTTON_OK) lastchange = 'open' if ((replace_existing == 1) and (nextchar != spacenquotes) and (alafin == 0)): if (est_espace(nextchar)): scribus.selectText(c + 1, 1, textbox) scribus.deleteText(textbox) scribus.insertText(spacenquotes, c + 1, textbox) nbchange = nbchange + 1 elif (char == fermant_double): if (lastchange == 'close'): if (lang == 'fr'): scribus.messageBox( "Oups !", 'Incohérence dans les enchainements de guillemets ouvrant et fermant. Une guillemet ouvrante manque avant la position ' + str(c) + '\nOn continue quand même', scribus.ICON_WARNING, scribus.BUTTON_OK) else: scribus.messageBox( "Oops !", 'The text is not consistent. Opening doublequote missing before position ' + str(c), scribus.ICON_WARNING, scribus.BUTTON_OK)
for item in textFrame: scribus.messagebarText("Processing text frame " + item) scribus.redrawAll() print item scribus.deselectAll() scribus.selectObject(item) n = scribus.getTextLength() print n for i in range(n): scribus.selectText(i, 1) original = scribus.getText() if original not in charsIgnore and len(original) > 0: shuffled = chars.pop(0) if original.isupper(): shuffled = shuffled.upper() scribus.insertText(shuffled, i) scribus.selectText(i + 1, 1) scribus.deleteText() for item in imageFrame: print item scribus.messagebarText("Processing image frame " + item) scribus.redrawAll() imageFile = scribus.getImageFile(item) fileName, fileExtension = os.path.splitext(imageFile) imageFileBlurred = fileName + "_blurred" + fileExtension # TODO: instead of using image magick we should expos scribus' own blur to the scripter if distutils.spawn.find_executable("convert") != "": command = "identify " + imageFile result = os.popen(command).read() if result != "":
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) scribus.setFont('Arial Regular',q) scribus.setFontSize(20, q) scribus.setTextColor("gray", q) rr = rx[x][y] + ry[x][y] # scribus.setTextAlignment(scribus.ALIGN_CENTERED, q) scribus.insertText('%(rr)d' % locals(), 0, q) xx+=1
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) 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)
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)
nextchar = ' ' else: scribus.selectText(c + 1, 1, textbox) nextchar = scribus.getText(textbox) scribus.selectText(c, 1, textbox) char = scribus.getText(textbox) if (len(char) != 1): c += 1 if (char == '-'): if (prevchar == '-'): if (nextchar == '-'): scribus.selectText(c - 1, 3, textbox) scribus.deleteText(textbox) scribus.insertText(mdash, c - 1, textbox) char = mdash else: scribus.selectText(c - 1, 2, textbox) scribus.deleteText(textbox) scribus.insertText(ndash, c - 1, textbox) char = ndash else: c += 1 else: c += 1 prevchar = char contents = scribus.getTextLength(textbox)
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
for item in textFrame : scribus.messagebarText("Processing text frame "+item) scribus.redrawAll() print item scribus.deselectAll() scribus.selectObject(item) n = scribus.getTextLength() print n for i in range(n) : scribus.selectText(i, 1) original = scribus.getText() if original not in charsIgnore and len(original) > 0: shuffled = chars.pop(0) if original.isupper() : shuffled = shuffled.upper() scribus.insertText(shuffled, i) scribus.selectText(i + 1, 1) scribus.deleteText() for item in imageFrame : print item scribus.messagebarText("Processing image frame "+item) scribus.redrawAll() imageFile = scribus.getImageFile(item) fileName, fileExtension = os.path.splitext(imageFile) imageFileBlurred = fileName+"_blurred"+fileExtension # TODO: instead of using image magick we should expos scribus' own blur to the scripter if distutils.spawn.find_executable("convert") != "" : command = "identify "+imageFile result = os.popen(command).read(); if result != "" :
contents = scribus.getTextLength(textbox) while 1: if ((c == contents) or (c > contents)): break if ((c + 1) > contents - 1): nextchar = ' ' else: scribus.selectText(c + 1, 1, textbox) nextchar = scribus.getText(textbox) scribus.selectText(c, 1, textbox) char = scribus.getText(textbox) if (len(char) != 1): c += 1 continue alpha = random.randint(1, 26) letter = chr(alpha + 96) LETTER = chr(alpha + 64) if ((ord(char) > 96) and (ord(char) < 123)): scribus.deleteText(textbox) scribus.insertText(letter, c, textbox) if ((ord(char) > 64) and (ord(char) < 91)): scribus.deleteText(textbox) scribus.insertText(LETTER, c, textbox) c += 1 contents = scribus.getTextLength(textbox) scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Finished", "That should do it!", icon=0, button1=1)
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
while 1: if ((c == contents) or (c > contents)): break if ((c + 1) > contents - 1): nextchar = ' ' else: scribus.selectText(c+1, 1, textbox) nextchar = scribus.getText(textbox) scribus.selectText(c, 1, textbox) char = scribus.getText(textbox) if (len(char) != 1): c += 1 continue alpha = random.randint(1,26) letter = chr(alpha + 96) LETTER = chr(alpha + 64) if ((ord(char)>96)and(ord(char)<123)): scribus.deleteText(textbox) scribus.insertText(letter, c, textbox) if ((ord(char)>64)and(ord(char)<91)): scribus.deleteText(textbox) scribus.insertText(LETTER, c, textbox) c += 1 contents = scribus.getTextLength(textbox) scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Finished", "That should do it!",icon=0,button1=1)
for x in range(0,13): #1,12,6 for final for y in range(1,12,6): rx = x ry = y for zx in range(0,2): for zy in range(0,3): a = scribus.createText(2.25+((zx+0)*(pageX/1.55)), 0.75+(zy*(pageY/3.84)), 1.25, 0.25) scribus.setFont('Arial Regular',a) scribus.setFontSize(12, a) scribus.setTextColor("gray", a) scribus.setTextAlignment(scribus.ALIGN_CENTERED, a) scribus.rotateObject(180, a); rxy = rx-ry scribus.insertText('%(rx)d - %(ry)d = %(rxy)d' % locals(), 0, a) q = scribus.createText(1.0+((zx+0)*(pageX/1.55)), 1.125+(zy*(pageY/3.84)), 4, 1) scribus.setFont('Arial Regular',q) scribus.setFontSize(55, q) scribus.setTextAlignment(scribus.ALIGN_CENTERED, q) scribus.insertText('%(rx)d + %(ry)d =' % locals(), 0, q) ry = ry + 1 l = scribus.createLine(0.0,2.833333,11,2.833333) scribus.setLineColor("gray", l) l = scribus.createLine(0.0,5.666666,11,5.666666) scribus.setLineColor("gray", l) l = scribus.createLine(5.5,0.0,5.5,8.5) scribus.setLineColor("gray", l) scribus.newPage(-1) rx = x