def run(self): selCount = scribus.selectionCount() if selCount == 0: scribus.messageBox('Scribus Data Merger- Usage Error', "There is no objects selected.\nPlease try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) csvData = self.loadCsvData() # Create a list with the names of the selected objects: selectedObjects = [] # Loop through the selected objects and put their names into the list selectedObjects o = 0 while (o < selCount): selectedObjects.append(scribus.getSelectedObject(o)) o = o + 1 startingPage = scribus.currentPage() lastRow = len(csvData) if(self.__dataObject.getNumberOfLinesToMerge() != 'All'): lastRow = int(self.__dataObject.getNumberOfLinesToMerge()) lastRow = min(lastRow, len(csvData)) # This will prevent the script from trying to merge data from non-existing rows in the data file currentPage = scribus.currentPage() rowNumber = 0 insertPageBeforeThis = -1 while (rowNumber < lastRow): if(scribus.pageCount() > currentPage): insertPageBeforeThis = currentPage + 1 scribus.newPage(insertPageBeforeThis) # Inserts a page before the page given as an argument currentPage = currentPage + 1 for selectedObject in selectedObjects: # Loop through the names of all the selected objects scribus.gotoPage(startingPage) # Set the working page to the one we want to copy objects from scribus.copyObject(selectedObject) scribus.gotoPage(currentPage) scribus.pasteObject() # Paste the copied object on the new page scribus.docChanged(1) scribus.gotoPage(currentPage) # Make sure ware are on the current page before we call getAllObjects() newPageObejcts = scribus.getAllObjects() for pastedObject in newPageObejcts: # Loop through all the items on the current page objType = scribus.getObjectType(pastedObject) text = CONST.EMPTY if(objType == 'TextFrame'): text = scribus.getAllText(pastedObject) # This should have used getText but getText does not return the text values of just pasted objects text = self.replaceText(csvData[rowNumber], text) scribus.setText(text, pastedObject) if(objType == 'ImageFrame'): text = scribus.getImageFile(pastedObject) # self.info("Image text", text) # Todo: Find out if it is possible to replace text in the ImageFile property rowNumber = rowNumber + 1 scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Merge Completed", "Merge Completed", icon=scribus.ICON_INFORMATION, button1=scribus.BUTTON_OK)
def setGuidesRow(n, gap): print "setGuidesRow should be a scribus API function" (margin_top, margin_left, margin_right, margin_bottom) = scribus.getPageNMargins(scribus.currentPage()) (width, height) = scribus.getPageNSize(scribus.currentPage()) cell_height = (height - (margin_top + margin_bottom) - (gap * (n - 1))) / n guide = [] previous_guide = margin_top for i in range(0, n - 1): guide.append(previous_guide + cell_height) guide.append(previous_guide + cell_height + gap) previous_guide = previous_guide + cell_height + gap scribus.setHGuides(guide)
def setGuidesColumn(n, gap): print "setGuidesColumn should be a scribus API function" (margin_top, margin_left, margin_right, margin_bottom) = scribus.getPageNMargins(scribus.currentPage()) (width, height) = scribus.getPageNSize(scribus.currentPage()) cell_width = (width - (margin_left + margin_right) - (gap * (n - 1))) / n guide = [] previous_guide = margin_left for i in range(0, n - 1): guide.append(previous_guide + cell_width) guide.append(previous_guide + cell_width + gap) previous_guide = previous_guide + cell_width + gap scribus.setVGuides(guide)
def get_imageframes_on_page(page_number, empty_only=False, name_filter=None): """ page_number: if 0 use current page, otherwise the given page set emty_only to return empty frames only name_filter: return frame if name conatins filter string returns a list of the image objects on the current page get all the items on the page """ current_page = sc.currentPage() if page_number > 0: if page_number <= sc.pageCount(): sc.gotoPage(page_number) else: logging.warning('Page {} out of rage.'.format(page_number)) return [] item_list = sc.getPageItems() # refine it to a list of only image objects objs = [] for item in item_list: if item[1] == 2: #type 2 == image add_image = True if empty_only: add_image = is_imageframe_empty(item[0]) and add_image if name_filter: if name_filter in item[0]: add_image = True and add_image else: add_image = False and add_image if add_image: objs.append(item[0]) sc.gotoPage(current_page) return objs
def copyPlayer(sourceName, destinationName): if scribus.objectExists(sourceName): doc = scribus.getDocName() unit = scribus.getUnit() (PageWidth, PageHeight) = scribus.getPageSize() (iT, iI, iO, iB) = scribus.getPageMargins() NewPagepoint = PageHeight - iT - iB player = scribus.selectObject(sourceName) #Duplicate the object... scribus.duplicateObject(sourceName) x = scribus.getSelectedObject() newObjectName = str(x) size = scribus.getSize(newObjectName) scribus.moveObject(0, size[1], newObjectName) (x, y) = scribus.getPosition(newObjectName) scribus.setRedraw(1) scribus.docChanged(1) if (y + size[1] > NewPagepoint): currentPage = scribus.currentPage() scribus.newPage(-1) newPage = currentPage + 1 scribus.copyObject(newObjectName) scribus.deleteObject(newObjectName) scribus.gotoPage(newPage) scribus.pasteObject(newObjectName) scribus.moveObjectAbs(iO, iT, newObjectName) scribus.setNewName(destinationName, sourceName) scribus.setNewName(sourceName, newObjectName)
def getCurrentPageMargins(): """This is a fix for the Scribus 'feature' with getPageMargins() Scribus seems to return document margins, not page margins for current page""" (top, left, right, bottom) = scribus.getPageMargins() if scribus.currentPage() % 2 == 1: # odd page return (top,left,right,bottom) else: return (top,right,left,bottom)
def getCurrentPageMargins(): """This is a fix for the Scribus 'feature' with getPageMargins() Scribus seems to return document margins, not page margins for current page""" (top, left, right, bottom) = scribus.getPageMargins() if scribus.currentPage() % 2 == 1: # odd page return (top, left, right, bottom) else: return (top, right, left, bottom)
def setGuidesRow(n, gap): print "setGuidesRow should be a scribus API function" (margin_top, margin_left, margin_right, margin_bottom) = scribus.getPageNMargins(scribus.currentPage()) print "left " + str(margin_left) print "right " + str(margin_right) (width, height) = scribus.getPageNSize(scribus.currentPage()) print "width " + str(width) print "height " + str(height) cell_width = (width - (margin_left + margin_right) - (gap * (n - 1))) / n print cell_width guide = [] previous_guide = margin_left for i in range(0, n - 1): guide.append(previous_guide + cell_width) guide.append(previous_guide + cell_width + gap) previous_guide = previous_guide + cell_width + gap scribus.setHGuides(guide)
def placeImage(self, src, imgattr): if "fullpage" in imgattr: # we may need to flip these 180 depending on left or right page page = scribus.currentPage() cframe = self.frame self.newPage() imgwidth = imgattr["width"] imgheight = imgattr["height"] ratio = float(imgheight) / float(imgwidth) xpos = self.leftmargin if imgheight > imgwidth: width = self.pagewidth - self.leftmargin - self.rightmargin height = width * ratio if height > self.pageheight - self.topmargin - self.bottommargin: height = self.pageheight - self.topmargin - self.bottommargin xpos = xpos + (width - (height / ratio)) / 2 width = height / ratio self.pasteImage(src, xpos, self.topmargin, width, height, rotate=False) if "title" in imgattr: self.pasteCaption(xpos, self.topmargin, imgattr["title"], width) if "footer" in imgattr: self.pasteCaption(xpos, self.topmargin + height - COLUMNGAP, imgattr["footer"], width) else: width = self.pageheight - self.topmargin - self.bottommargin height = width * ratio self.pasteImage(src, xpos, self.pageheight - self.bottommargin, width, height, rotate=True) self.gotoPage(page) self.frame = cframe else: self.imagebuffer.append((src, imgattr)) #if self.frame == None: # always flush images here self.flushImages()
def insert_text_frame(): page_size = scribus.getPageSize() page_margins_right = scribus.getPageMargins() page_margins_left = (page_margins_right[0], page_margins_right[2], page_margins_right[1], page_margins_right[3]) if (scribus.currentPage() % 2) == 1: page_margins = page_margins_right else: page_margins = page_margins_left name = 'test%d' % random.randint(100, 999) # x, y, width, height scribus.createText(page_margins[0], page_margins[1], page_size[0] - (page_margins[0] + page_margins[2]), page_size[1] - (page_margins[1] + page_margins[3]), name) scribus.setText("test", name)
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 createNewPage(self, tbox): curPage = scribus.currentPage() if curPage < scribus.pageCount() - 1: where = curPage + 1 else: where = -1 logger.debug("cur=%d name=%s pc=%d wh=%d", curPage, tbox, scribus.pageCount(), where) cols = scribus.getColumns(tbox) colgap = scribus.getColumnGap(tbox) x, y = scribus.getPosition(tbox) w, h = scribus.getSize(tbox) mp = scribus.getMasterPage(curPage) scribus.newPage(where, mp) # return val? scribus.gotoPage(curPage + 1) newBox = scribus.createText(x, y, w, h) scribus.setColumns(cols, newBox) scribus.setColumnGap(colgap, newBox) scribus.linkTextFrames(tbox, newBox) logger.debug("link from %s to %s", tbox, newBox) return newBox
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 main(): if not scribus.haveDoc(): return filename = scribus.fileDialog('Select a document', 'Scribus document (*.sla)') if not filename: return # find the masterpages in use in the source document scribus.openDoc(filename) pages = tuple(range(1, scribus.pageCount() + 1)) masterpages = [scribus.getMasterPage(p) for p in pages] scribus.closeDoc() # the current page before importing page = scribus.currentPage() # import pages by creating them after the current one scribus.importPage(filename, pages, 1, 1) for i, masterpage in enumerate(masterpages): scribus.applyMasterPage(masterpage, page + 1 + i)
def placeImage(self, src, imgattr): if "fullpage" in imgattr: # we may need to flip these 180 depending on left or right page page = scribus.currentPage() cframe = self.frame self.newPage() imgwidth = imgattr["width"] imgheight = imgattr["height"] ratio = float(imgheight) / float(imgwidth) xpos = self.leftmargin if imgheight > imgwidth: width = self.pagewidth - self.leftmargin - self.rightmargin height = width * ratio if height > self.pageheight - self.topmargin - self.bottommargin: height = self.pageheight - self.topmargin - self.bottommargin xpos = xpos + (width - (height / ratio)) / 2 width = height / ratio self.pasteImage(src, xpos, self.topmargin, width, height, rotate=False) if "title" in imgattr: self.pasteCaption(xpos, self.topmargin, imgattr["title"], width) if "footer" in imgattr: self.pasteCaption(xpos, self.topmargin+height-COLUMNGAP, imgattr["footer"], width) else: width = self.pageheight - self.topmargin - self.bottommargin height = width * ratio self.pasteImage(src, xpos, self.pageheight - self.bottommargin, width, height, rotate=True) self.gotoPage(page) self.frame = cframe else: self.imagebuffer.append( (src,imgattr) ) #if self.frame == None: # always flush images here self.flushImages()
def get_page_margins(): if (scribus.currentPage() % 2) == 1: return page_margins_right else: return page_margins_left
def create_guide(gp): fh = FrameHandler() toc = TableOfContents(gp.numpagesforcontents) index = ClimbIndex() scribus.statusMessage("Creating document...") nchapters = len(gp.chapters) scribus.progressTotal(nchapters) scribus.progressReset() progress = 0 currentregion = "" crag = "" for (xmlid, region) in gp.chapters: scribus.statusMessage("Parsing " + xmlid + "...") progress = progress + 1 scribus.progressTotal(nchapters) scribus.progressSet(progress) p = xml.dom.minidom.parse(gp.path + os.sep + xmlid + os.sep + xmlid + ".xml") for g in p.getElementsByTagName("guide"): for n in g.childNodes: if n.nodeName == "header": intro = n.getAttribute("intro") name = n.getAttribute("name") rock = n.getAttribute("rock") sun = n.getAttribute("sun") access = n.getAttribute("access") acknow = n.getAttribute("acknowledgement") walk = n.getAttribute("walk") camping = n.getAttribute("camping") history = n.getAttribute("history") stars = g.getAttribute("guidestars").replace( "*", GLYPH_STAR) scribus.statusMessage("Parsing " + xmlid + " (" + name + ")...") scribus.progressTotal(nchapters) scribus.progressSet(progress) fh.endFrame() #fh.sidebar.setText("") fh.sidebar.setText(name) fh.newPage() fh.setColumns(1) #if scribus.currentPage() % 2 != 0: # fh.newPage() fh.placeText(name, "Title", columns=1, keepwithnext=True, nosplit=True) if region != currentregion: toc.add(region, 1, scribus.currentPage()) currentregion = region toc.add(name + " " + stars, 2, scribus.currentPage()) crag = name #fh.sidebar.setText(crag) graphpath = gp.path + os.sep + xmlid + os.sep + "graph.pdf" fh.placeGuide(rock, sun, walk, graphpath, iconpath=gp.path) if len(acknow) > 0: fh.placeText("Contributors", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(acknow, "Intro", nosplit=True) if len(intro) > 0: fh.placeText("General Rave", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(intro, "Intro") if len(history) > 0: fh.placeText("History", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(history, "Intro") if len(access) > 0: fh.placeText("Access", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(access, "Intro") if len(camping) > 0: fh.placeText("Camping", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(camping, "Intro") fh.endFrame() fh.setColumns(2) elif n.nodeName == "climb" or n.nodeName == "problem": extra = n.getAttribute("extra") grade = n.getAttribute("grade") length = n.getAttribute("length") name = n.getAttribute("name") fa = n.getAttribute("fa") stars = n.getAttribute("stars").replace("*", GLYPH_STAR) number = n.getAttribute("number") scribus.statusMessage("Parsing " + xmlid + " (" + crag + ") " + name) scribus.progressTotal(nchapters) scribus.progressSet(progress) # OK for now, but we will want to break this up later routename = stars + " " + name + " " + length + " " + grade + " " + extra if number != "": routename = "(" + number + ") " + routename #routename = chr(TAB) + stars + chr(TAB) + name + chr(TAB) + length + chr(TAB) + grade + chr(TAB) + extra #if number != "": # routename = "(" + number + ")" + routename fh.placeText(routename, "Route Name", columns=2, nosplit=True, keepwithnext=True) for t in n.childNodes: if t.nodeType == 3: txt = t.nodeValue #fh.placeText(t.nodeValue, "Route Description", columns=2, nosplit=True, keepwithnext=(len(fa)>0)) fh.placeText(txt, "Route Description", columns=2, nosplit=(len(txt) < NOSPLIT_LIMIT), keepwithnext=(len(fa) > 0)) if len(fa) > 0: fh.placeText(fa, "FA Details", columns=2, nosplit=True) if n.nodeName == "climb": index.add(name, grade, stars, crag, scribus.currentPage()) if name[:3] == "The": index.add(name[4:] + ", The", grade, stars, crag, scribus.currentPage()) #if name in gp.aliases: # index.add(gp.aliases[name].decode("utf-8"), grade, stars, crag, scribus.currentPage()) # print "Alias Match (via key): " + name + " matches " + route + " substitute " + alternatename for (route, alternatename) in gp.aliases.iteritems(): if name == route: # print "Alias Match(via unrolled niceness): " + name + " matches " + route + " substitute " + alternatename index.add(alternatename.decode("utf-8"), grade, stars, crag, scribus.currentPage()) elif n.nodeName == "text": # class can be one of... # text, heading1, heading2, heading3, intro, indentedHeader # Editor, Discussion, DiscussionNoIndents, noPrint # assign Style to class name & control layout from Scribus Style Editor clss = n.getAttribute("class") if clss == "": clss = "text" for t in n.childNodes: if t.nodeType == 3: txt = t.nodeValue if clss == "indentedHeader": firstline = txt.split("\n")[0] rest = txt[len(firstline) + 1:] if firstline[-1] == ":": fh.placeText(firstline[:-1], "heading3", nosplit=True, keepwithnext=True) fh.placeText(rest, "Intro") else: fh.placeText(txt, "Intro") elif clss == "heading3": fh.placeText(GLYPH_RIGHTPOINTER + " " + txt, clss, nosplit=True, keepwithnext=True) #if txt != currentregion: toc.add(txt, 4, scribus.currentPage()) elif clss == "heading2": #fh.endFrame() fh.placeText(txt, clss, columns=2, nosplit=True, keepwithnext=True) #if txt != currentregion: toc.add(txt, 3, scribus.currentPage()) elif clss == "heading1": fh.endFrame() fh.sidebar.setText("") #fh.sidebar.setText(txt) fh.newPage() fh.placeText(txt, "Title", columns=1, nosplit=True, keepwithnext=True) if region != currentregion: toc.add(region, 1, scribus.currentPage()) currentregion = region toc.add(txt, 2, scribus.currentPage()) elif clss == "intro": fh.placeText(txt, "Intro", nosplit=True, keepwithnext=True) elif clss == "text": fh.placeText(txt, clss, columns=2, nosplit=True, keepwithnext=True) #fh.placeText(txt, clss, nosplit=True, keepwithnext=False) elif n.nodeName == "image": src = n.getAttribute("src") legend = n.getAttribute("legend") legendtitle = n.getAttribute("legendTitle") legendfooter = n.getAttribute("legendFooter") noprint = n.getAttribute("noPrint") scribus.statusMessage("Parsing " + xmlid + " (" + crag + ") image=" + src) scribus.progressTotal(nchapters) scribus.progressSet(progress) if src in gp.images: attr = gp.images[src] else: attr = {} if noprint != "true": fullsrc = gp.path + os.sep + xmlid + os.sep + src if not os.path.exists(fullsrc): scribus.messageBox('Bummer, dude', 'Image file missing: ' + fullsrc, icon=scribus.ICON_WARNING) else: try: i = Image.open(fullsrc) (width, height) = i.size attr["width"] = width attr["height"] = height if legend == "true": if len(legendtitle.strip()) > 0: attr["title"] = legendtitle if len(legendfooter.strip()) > 0: attr["footer"] = legendfooter fh.placeImage(fullsrc, attr) except IOError: scribus.messageBox( "Bummer, dude", "Image file corrupt: " + fullsrc) fh.expandFrame() fh.endGuide() if gp.includeindexbyname: scribus.statusMessage("Creating index by name...") scribus.progressReset() scribus.newPage(-1) if scribus.currentPage() % 2 == 0: # even page scribus.newPage(-1) page = scribus.currentPage() index.drawIndexByName() toc.add("Index by Route Name", 1, page) if gp.includeindexbygrade: scribus.statusMessage("Creating index by grade...") scribus.progressReset() scribus.newPage(-1) page = scribus.currentPage() index.drawIndexByGrade() toc.add("Index by Grade", 1, page) if gp.levelsofcontents > 0: scribus.statusMessage("Creating table of contents...") scribus.progressReset() toc.draw(gp.levelsofcontents)
def __init__(self,page): scribus.newPage(-1) self.contentspage = scribus.currentPage() for i in range(1,page): scribus.newPage(-1) self.sections = []
def __init__(self, page): scribus.newPage(-1) self.contentspage = scribus.currentPage() for i in range(1, page): scribus.newPage(-1) self.sections = []
def create_guide(gp): fh = FrameHandler() toc = TableOfContents(gp.numpagesforcontents) index = ClimbIndex() scribus.statusMessage("Creating document...") nchapters = len(gp.chapters) scribus.progressTotal(nchapters) scribus.progressReset() progress = 0 currentregion = "" crag = "" for (xmlid,region) in gp.chapters: scribus.statusMessage("Parsing " + xmlid + "...") progress = progress + 1 scribus.progressTotal(nchapters) scribus.progressSet(progress) p = xml.dom.minidom.parse(gp.path + os.sep + xmlid + os.sep + xmlid + ".xml") for g in p.getElementsByTagName("guide"): for n in g.childNodes: if n.nodeName == "header": intro = n.getAttribute("intro") name = n.getAttribute("name") rock = n.getAttribute("rock") sun = n.getAttribute("sun") access = n.getAttribute("access") acknow = n.getAttribute("acknowledgement") walk = n.getAttribute("walk") camping = n.getAttribute("camping") history = n.getAttribute("history") stars = g.getAttribute("guidestars").replace("*",GLYPH_STAR) scribus.statusMessage("Parsing " + xmlid + " (" + name + ")...") scribus.progressTotal(nchapters) scribus.progressSet(progress) fh.endFrame() #fh.sidebar.setText("") fh.sidebar.setText(name) fh.newPage() fh.setColumns(1) #if scribus.currentPage() % 2 != 0: # fh.newPage() fh.placeText(name, "Title", columns=1, keepwithnext=True, nosplit=True) if region != currentregion: toc.add(region, 1, scribus.currentPage()) currentregion = region toc.add(name + " " + stars,2,scribus.currentPage()) crag = name #fh.sidebar.setText(crag) graphpath = gp.path + os.sep + xmlid + os.sep + "graph.pdf" fh.placeGuide(rock, sun, walk, graphpath, iconpath=gp.path) if len(acknow) > 0: fh.placeText("Contributors", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(acknow, "Intro", nosplit=True) if len(intro) > 0: fh.placeText("General Rave", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(intro, "Intro") if len(history) > 0: fh.placeText("History", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(history, "Intro") if len(access) > 0: fh.placeText("Access", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(access, "Intro") if len(camping) > 0: fh.placeText("Camping", "IntroTitle", nosplit=True, keepwithnext=True) fh.placeText(camping, "Intro") fh.endFrame() fh.setColumns(2) elif n.nodeName == "climb" or n.nodeName == "problem": extra = n.getAttribute("extra") grade = n.getAttribute("grade") length = n.getAttribute("length") name = n.getAttribute("name") fa = n.getAttribute("fa") stars = n.getAttribute("stars").replace("*",GLYPH_STAR) number = n.getAttribute("number") scribus.statusMessage("Parsing " + xmlid + " (" + crag + ") " + name) scribus.progressTotal(nchapters) scribus.progressSet(progress) # OK for now, but we will want to break this up later routename = stars + " " + name + " " + length + " " + grade + " " + extra if number != "": routename = "(" + number + ") " + routename #routename = chr(TAB) + stars + chr(TAB) + name + chr(TAB) + length + chr(TAB) + grade + chr(TAB) + extra #if number != "": # routename = "(" + number + ")" + routename fh.placeText(routename, "Route Name", columns=2, nosplit=True, keepwithnext=True) for t in n.childNodes: if t.nodeType == 3: txt = t.nodeValue #fh.placeText(t.nodeValue, "Route Description", columns=2, nosplit=True, keepwithnext=(len(fa)>0)) fh.placeText(txt, "Route Description", columns=2, nosplit=(len(txt)<NOSPLIT_LIMIT), keepwithnext=(len(fa)>0)) if len(fa) > 0: fh.placeText(fa, "FA Details", columns=2, nosplit=True) if n.nodeName == "climb": index.add(name, grade, stars, crag, scribus.currentPage()) if name[:3] == "The": index.add(name[4:] + ", The", grade, stars, crag, scribus.currentPage()) #if name in gp.aliases: # index.add(gp.aliases[name].decode("utf-8"), grade, stars, crag, scribus.currentPage()) # print "Alias Match (via key): " + name + " matches " + route + " substitute " + alternatename for (route, alternatename) in gp.aliases.iteritems(): if name == route: # print "Alias Match(via unrolled niceness): " + name + " matches " + route + " substitute " + alternatename index.add(alternatename.decode("utf-8"), grade, stars, crag, scribus.currentPage()) elif n.nodeName == "text": # class can be one of... # text, heading1, heading2, heading3, intro, indentedHeader # Editor, Discussion, DiscussionNoIndents, noPrint # assign Style to class name & control layout from Scribus Style Editor clss = n.getAttribute("class") if clss == "": clss = "text" for t in n.childNodes: if t.nodeType == 3: txt = t.nodeValue if clss == "indentedHeader": firstline = txt.split("\n")[0] rest = txt[len(firstline)+1:] if firstline[-1] == ":": fh.placeText(firstline[:-1], "heading3", nosplit=True, keepwithnext=True) fh.placeText(rest, "Intro") else: fh.placeText(txt, "Intro") elif clss == "heading3": fh.placeText(GLYPH_RIGHTPOINTER + " " + txt, clss, nosplit=True, keepwithnext=True) #if txt != currentregion: toc.add(txt,4,scribus.currentPage()) elif clss == "heading2": #fh.endFrame() fh.placeText(txt, clss, columns=2, nosplit=True, keepwithnext=True) #if txt != currentregion: toc.add(txt,3,scribus.currentPage()) elif clss == "heading1": fh.endFrame() fh.sidebar.setText("") #fh.sidebar.setText(txt) fh.newPage() fh.placeText(txt, "Title", columns=1, nosplit=True, keepwithnext=True) if region != currentregion: toc.add(region, 1, scribus.currentPage()) currentregion = region toc.add(txt,2,scribus.currentPage()) elif clss == "intro": fh.placeText(txt, "Intro", nosplit=True, keepwithnext=True) elif clss == "text": fh.placeText(txt, clss, columns=2, nosplit=True, keepwithnext=True) #fh.placeText(txt, clss, nosplit=True, keepwithnext=False) elif n.nodeName == "image": src = n.getAttribute("src") legend = n.getAttribute("legend") legendtitle = n.getAttribute("legendTitle") legendfooter = n.getAttribute("legendFooter") noprint = n.getAttribute("noPrint") scribus.statusMessage("Parsing " + xmlid + " (" + crag + ") image=" + src) scribus.progressTotal(nchapters) scribus.progressSet(progress) if src in gp.images: attr = gp.images[src] else: attr = {} if noprint != "true": fullsrc = gp.path + os.sep + xmlid + os.sep + src if not os.path.exists(fullsrc): scribus.messageBox('Bummer, dude', 'Image file missing: ' + fullsrc, icon=scribus.ICON_WARNING) else: try: i = Image.open(fullsrc) (width,height) = i.size attr["width"] = width attr["height"] = height if legend == "true": if len(legendtitle.strip()) > 0: attr["title"] = legendtitle if len(legendfooter.strip()) > 0: attr["footer"] = legendfooter fh.placeImage(fullsrc, attr) except IOError: scribus.messageBox("Bummer, dude", "Image file corrupt: " + fullsrc) fh.expandFrame() fh.endGuide() if gp.includeindexbyname: scribus.statusMessage("Creating index by name...") scribus.progressReset() scribus.newPage(-1) if scribus.currentPage() % 2 == 0: # even page scribus.newPage(-1) page = scribus.currentPage() index.drawIndexByName() toc.add("Index by Route Name",1,page) if gp.includeindexbygrade: scribus.statusMessage("Creating index by grade...") scribus.progressReset() scribus.newPage(-1) page = scribus.currentPage() index.drawIndexByGrade() toc.add("Index by Grade",1,page) if gp.levelsofcontents > 0: scribus.statusMessage("Creating table of contents...") scribus.progressReset() toc.draw(gp.levelsofcontents)
extensions = ['jpg', 'png', 'tif'] filenames = [ f for f in os.listdir(path) if any(f.endswith(ext) for ext in extensions) ] if not filenames: scribus.messagebarText("No image found.") sys.exit() # sorted(filenames) filenames.sort() scribus.loadImage(filenames[0]) filenames = filenames[1:] page = scribus.currentPage() + 1 n_pages = scribus.pageCount() for filename in filenames: print(filename) if page <= n_pages: scribus.gotoPage(page) else: # TODO: currently this does not work if the names of the default master pages # are not in the language of the GUI. # if it's the case you need to create all pages before loading the images. scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) new_image = scribus.createImage(x, y, width, height) scribus.setScaleImageToFrame(True, True, new_image) scribus.loadImage(filename, new_image)
font_size_main_text = get_int_from_dialog_value(font_size_main_text) horizontal_cells = scribus.messageBox( 'Cells orientation', 'Should the cells be wider than higer?', scribus.ICON_NONE, scribus.BUTTON_YES, scribus.BUTTON_NO, ) if horizontal_cells == scribus.BUTTON_YES: # doc of return value of messageBox is wrong: it returns the value of the button horizontal_cells = True else: horizontal_cells = False # get the measurements from the current page (page_width, page_height) = scribus.getPageNSize(scribus.currentPage()) (margin_top, margin_left, margin_right, margin_bottom) = scribus.getPageNMargins(scribus.currentPage()) page_inner_width = page_width - margin_left - margin_right page_inner_height = page_height - margin_top - margin_bottom # calculate the basic values line_height = font_size_main_text * 1.5 # real ratio 1.618 line_height_mm = line_height * pt_to_mm_ratio debug("line_height", line_height) debug("line_height_mm", line_height_mm) gap = line_height_mm
extensions = ['jpg', 'png', 'tif'] filenames = [f for f in os.listdir(path) if any(f.endswith(ext) for ext in extensions)] if not filenames: scribus.messagebarText("No image found.") sys.exit() # sorted(filenames) filenames.sort() scribus.loadImage(filenames[0]) filenames = filenames[1:] page = scribus.currentPage() + 1 n_pages = scribus.pageCount() for filename in filenames: print(filename) if page <= n_pages: scribus.gotoPage(page) else: # TODO: currently this does not work if the names of the default master pages # are not in the language of the GUI. # if it's the case you need to create all pages before loading the images. scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) new_image = scribus.createImage(x, y, width, height) scribus.setScaleImageToFrame(True, True, new_image) scribus.loadImage(filename, new_image)
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 # ######################### script = "Aufschlussdoku.py" version = "20140107" csvfile = scribus.fileDialog("csv2table :: open file", "*.csv") fname_ext = csvfile[csvfile.rfind("/") + 1:] fname_noext = fname_ext[:fname_ext.rfind(".")] reader = csv.reader(open(csvfile, "rb"), delimiter=";") boxes = [["strat_d", 2.25], ["strat_n", 2.25], ["strat_b", 6.5], ["strat_p", 2.3], ["strat_a", 3.9]] start_x = float(1.9075) start_y = float(10.5) strats = [] strat_ct = int(0) strat_ok = float(0.0) print getpass.getuser() for line in reader: if line[0].find("Tiefe bis [m]") <> 0: start_x_0 = start_x strat_ct = strat_ct + 1 strat_d = line[0].replace(",", "."); strat_uk = float(strat_d) + float(strat_ok) strat_draw = float(strat_d) * 2.0 strat_uk_draw = start_y + strat_draw if strat_uk_draw > 26.4: nPage = scribus.currentPage() + 1 pageendtext = "Fortsetzung nächste Seite" #print nPage scribus.createText(start_x_0 + 0.1, start_y + 0.1, 17, 0.5, "box_txt_pageend") scribus.sentToLayer("profil_txt", "box_txt_pageend") scribus.setText(pageendtext, "box_txt_pageend") scribus.setStyle("Buchner_sehrklein", "box_txt_pageend") scribus.newPage(-1,"Buchner_Standard") scribus.gotoPage(nPage) start_y = float(5.5) strat_uk_draw = start_y + strat_draw box_nr = int(0) #print strat_uk #print "aktuelle Seite:", scribus.currentPage() #print strat_uk strat_uk_txt = str(strat_uk).replace(".", ","); #print strat_uk_txt strat_h = line[0] strat_n = line[1] strat_b = line[2] strat_p = line[3] strat_a = line[4] strat = [strat_d, strat_uk, strat_h, strat_n, strat_b, strat_p, strat_a] #print strat strats.append(strat) for box in boxes: box_n = box[0] + str(strat_ct) box_txt = strat[box_nr + 2] box_txt_n = box_n + "txt" #print box_nr #print box_txt #print box_n, box_txt_n, dimensions[1], position scribus.createRect(start_x_0, start_y, float(box[1]), strat_draw, box_n) scribus.setLineWidth(0.567, box_n) scribus.sentToLayer("profil_rahmen", box_n) if box_nr == 0: scribus.createText(start_x_0 + 0.1, start_y + (strat_draw) - 0.4, float(box[1]) - 0.2, 0.4, box_txt_n) #print strat_uk_txt scribus.setText(strat_uk_txt, box_txt_n) else: scribus.createText(start_x_0 + 0.1, start_y + 0.1, float(box[1]) - 0.2, (strat_draw) - 0.1, box_txt_n) scribus.setText(box_txt, box_txt_n) scribus.setStyle("Buchner_Standard schmal", box_txt_n) scribus.sentToLayer("profil_txt", box_txt_n) start_x_0 = start_x_0 + float(box[1]) box_nr = box_nr + 1 #print "end: strat count:", strat_ct start_y = strat_uk_draw start_x_0 = start_x strat_ok = strat_ok + float(strat_d) print "end: all" scribus.createText(start_x_0 + 0.1, start_y + 0.1, 17, 0.5, "box_txt_end") scribus.sentToLayer("profil_txt", "box_txt_end") endtext = "Erstellt von " + getpass.getuser() + " mit " + fname_ext + ", " + script + " (V" + version + ")" scribus.setText(endtext, "box_txt_end") scribus.setStyle("Buchner_sehrklein", "box_txt_end") scribus.saveDocAs(fname_noext + ".sla")
# input values column_count = scribus.valueDialog('Number of columns', 'Please set the number of columns\n(sane values are 6, 9, 12, 24)', '6') column_count = get_int_from_dialog_value(column_count) font_size_main_text = scribus.valueDialog('Text size', 'Please set the font size for the main text\n(this value will be used)', '12') font_size_main_text = get_int_from_dialog_value(font_size_main_text) horizontal_cells = scribus.messageBox('Cells orientation', 'Should the cells be wider than higer?', scribus.ICON_NONE, scribus.BUTTON_YES, scribus.BUTTON_NO,) if horizontal_cells == scribus.BUTTON_YES : # doc of return value of messageBox is wrong: it returns the value of the button horizontal_cells = True else : horizontal_cells = False # get the measurements from the current page (page_width, page_height) = scribus.getPageNSize(scribus.currentPage()) (margin_top, margin_left, margin_right, margin_bottom) = scribus.getPageNMargins(scribus.currentPage()) page_inner_width = page_width - margin_left - margin_right page_inner_height = page_height - margin_top - margin_bottom # calculate the basic values line_height = font_size_main_text * 1.5 # real ratio 1.618 line_height_mm = line_height * pt_to_mm_ratio debug("line_height", line_height) debug("line_height_mm", line_height_mm) gap = line_height_mm # calculate number of lines fitting the page and the number of rows
'start': detagedPosition, 'length': tagedTextLen }) detagedPosition += tagedTextLen return result def getX(pageNumber): if pageNumber % 2 == 0: return 50 return 40 if __name__ == "__main__": x = getX(scribus.currentPage()) headerText = scribus.createText(x, 80, 750, 30) headerUnderline = scribus.createLine(x, 110, 160, 110) bodyText = scribus.createText(x, 120, 750, 1030) scribus.setColumns(4, bodyText) scribus.setColumnGap(10, bodyText) if scribus.getObjectType(bodyText) == "TextFrame": fileName = scribus.fileDialog("Open odt file", 'ODT files (*.odt)') text = removeEmptyStrings(parse(fileName)) header = detag(header(text)) body = body(text) scribus.deleteText(bodyText) scribus.insertText(lines(detag(body))[0], -1, bodyText)