def placeGuide(self, rock, sun, walk, graph, iconpath): """Build the header section of a guide""" if self.frame != None: (w, h) = scribus.getSize(self.frame) scribus.sizeObject(w, h + HEADERSIZE, self.frame) if os.path.exists(graph): img = scribus.createImage(self.leftmargin + 5, self.topmargin + 10, GRAPHSIZE, GRAPHSIZE) scribus.loadImage(graph, img) scribus.setScaleImageToFrame(True, True, img) offset = 13 iconleft = self.leftmargin + 10 + GRAPHSIZE + 3 txtleft = iconleft + ICONSIZE + 3 framewidth = self.pagewidth - self.leftmargin - self.rightmargin if sun != "": img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE) scribus.loadImage(iconpath + os.sep + "sun1.png", img) scribus.setScaleImageToFrame(True, True, img) #scribus.setCornerRadius(ROUNDS,img) icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE) self.styleText(sun, "IconText", icontxtframe) offset = offset + ICONSIZE + 3 if walk != "": img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE) scribus.loadImage(iconpath + os.sep + "walk1.png", img) scribus.setScaleImageToFrame(True, True, img) #scribus.setCornerRadius(ROUNDS,img) icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE) self.styleText(walk, "IconText", icontxtframe) offset = offset + ICONSIZE + 3 if rock != "": img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE) scribus.loadImage(iconpath + os.sep + "rock1.png", img) scribus.setScaleImageToFrame(True, True, img) #scribus.setCornerRadius(ROUNDS,img) icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE) self.styleText(rock, "IconText", icontxtframe) offset = offset + ICONSIZE + 3 self.endFrame()
def placeGuide(self, rock, sun, walk, graph, iconpath): """Build the header section of a guide""" if self.frame != None: (w,h) = scribus.getSize(self.frame) scribus.sizeObject(w, h + HEADERSIZE, self.frame) if os.path.exists(graph): img = scribus.createImage(self.leftmargin + 5, self.topmargin + 10, GRAPHSIZE, GRAPHSIZE) scribus.loadImage(graph, img) scribus.setScaleImageToFrame(True,True,img) offset = 13 iconleft = self.leftmargin + 10 + GRAPHSIZE + 3 txtleft = iconleft + ICONSIZE + 3 framewidth = self.pagewidth - self.leftmargin - self.rightmargin if sun != "": img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE) scribus.loadImage(iconpath + os.sep + "sun1.png", img) scribus.setScaleImageToFrame(True,True,img) #scribus.setCornerRadius(ROUNDS,img) icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE) self.styleText(sun, "IconText", icontxtframe) offset = offset + ICONSIZE + 3 if walk != "": img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE) scribus.loadImage(iconpath + os.sep + "walk1.png", img) scribus.setScaleImageToFrame(True,True,img) #scribus.setCornerRadius(ROUNDS,img) icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE) self.styleText(walk, "IconText", icontxtframe) offset = offset + ICONSIZE + 3 if rock != "": img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE) scribus.loadImage(iconpath + os.sep + "rock1.png", img) scribus.setScaleImageToFrame(True,True,img) #scribus.setCornerRadius(ROUNDS,img) icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE) self.styleText(rock, "IconText", icontxtframe) offset = offset + ICONSIZE + 3 self.endFrame()
def pasteImage(self, src, xpos, ypos, width, height, rotate=False): img = scribus.createImage(xpos, ypos, width, height) scribus.loadImage(src, img) scribus.setScaleImageToFrame(True,True,img) scribus.textFlowMode(img, 1) if src[-3:] == "jpg": scribus.setLineColor("Black",img) scribus.setLineWidth(0.2,img) #scribus.setLineShade(50,img) if rotate: scribus.rotateObject(90,img) #scribus.setCornerRadius(ROUNDS,img) self.imageframes.append(img)
def pasteImage(self, src, xpos, ypos, width, height, rotate=False): img = scribus.createImage(xpos, ypos, width, height) scribus.loadImage(src, img) scribus.setScaleImageToFrame(True, True, img) scribus.textFlowMode(img, 1) if src[-3:] == "jpg": scribus.setLineColor("Black", img) scribus.setLineWidth(0.2, img) #scribus.setLineShade(50,img) if rotate: scribus.rotateObject(90, img) #scribus.setCornerRadius(ROUNDS,img) self.imageframes.append(img)
def slotOkClicked(self): global CWD text = self.text.text() preamble = self.preamble.text() scale = self.scale.value() CWD = self.cwd.text() DPI = 600.0 os.chdir(CWD) try: img = scribus.getSelectedObject() scribus.getImageFile(img) except scribus.NoValidObjectError: img = self.get_new_image_name() scribus.createImage(0, 0, 10, 10, img) img_file = os.path.abspath('%s.png' % img) self.generate_latex(text, preamble, scale, img_file, DPI*scale) info = open(img_file + '.info', 'w') info.write("%s\n" % preamble) info.write("%g\n" % scale) info.write(text) info.close() x = Image.open(img_file, 'r') w, h = x.size del x scribus.setUnit(scribus.UNIT_MILLIMETERS) scribus.loadImage(img_file, img) scribus.setScaleImageToFrame(True, True, img) x, y = scribus.getPosition(img) scribus.sizeObject(x + w*25.4/DPI, y + h*25.4/DPI, img) self.accept()
def add_image(f): global page_size, page_margins_right, max_width, max_width_px, max_height, max_height_px try: im = Image.open(f) except: return False scribus.messagebarText("Adding " + f) ## # determine best frame width ## w, h = im.size print 'image: %s x %s px' % (w, h) # find the scale coeff coeff = 1 # FIXME: cas où image aussi large que haute mais page en portrait if w > h: # scale on width if w >= max_width_px: coeff = max_width_px / w else: # scale on height if h >= max_height_px: coeff = max_height_px / h print 'coeff:', coeff # scaling and conversion to mm frameW = int(((coeff * w) / min_ppi) * 25.4) frameH = int(((coeff * h) / min_ppi) * 25.4) print 'frame: %s x %s mm' % (frameW, frameH) # center frame frameX = get_page_margins()[1] + (max_width - frameW) / 2 frameY = get_page_margins()[0] + (max_height - frameH) / 2 frame = scribus.createImage(frameX, frameY, frameW, frameH) scribus.loadImage(f, frame) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=frame) return True
def add_image(f): global page_size, page_margins_right, max_width, max_width_px, max_height, max_height_px try: im = Image.open(f) except: return False scribus.messagebarText("Adding " + f) ## # determine best frame width ## w, h = im.size print "image: %s x %s px" % (w, h) # find the scale coeff coeff = 1 # FIXME: cas où image aussi large que haute mais page en portrait if w > h: # scale on width if w >= max_width_px: coeff = max_width_px / w else: # scale on height if h >= max_height_px: coeff = max_height_px / h print "coeff:", coeff # scaling and conversion to mm frameW = int(((coeff * w) / min_ppi) * 25.4) frameH = int(((coeff * h) / min_ppi) * 25.4) print "frame: %s x %s mm" % (frameW, frameH) # center frame frameX = get_page_margins()[1] + (max_width - frameW) / 2 frameY = get_page_margins()[0] + (max_height - frameH) / 2 frame = scribus.createImage(frameX, frameY, frameW, frameH) scribus.loadImage(f, frame) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=frame) return True
def placerandom(iteration): for i in range(iteration): imagedir = "./elements/" random_x = random.randint(-20,int(document_width)) random_y = random.randint(-20,int(document_height)) randomsize_x = random.randint(30,50) circles = scribus.createImage(random_x, random_y, randomsize_x,randomsize_x) scribus.loadImage(imagedir + "ubuntu_circle.png", circles) scribus.setScaleImageToFrame(1,1,circles) random_degree = random.randint(0,180) scribus.rotateObject(random_degree, circles) scribus.sentToLayer("randomcircles", circles)
def drawNameTagBox(xOff, yOff): logoPos = {"x": xOff+75.0-LOGO_WIDTH, "y": yOff+10.5} metaEventPos = {"x": xOff+5.0, "y": yOff+39.795} metaLocationPos = {"x": xOff+5.0, "y": yOff+43.6} #swkLogo = scribus.createImage(xOff+5.0, yOff+5.0, 70, 40) #scribus.loadImage("softwerkskammer.png", swkLogo) #scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=swkLogo) #scribus.setProperty(swkLogo, "fillTransparency", 0.9) metaEvent = scribus.createText(metaEventPos["x"], metaEventPos["y"], 70, 9) scribus.setText(EVENT_NAME, metaEvent) scribus.setStyle(STYLE_META, metaEvent) metaLocation = scribus.createText(metaLocationPos["x"], metaLocationPos["y"], 70, 9) scribus.setText(EVENT_LOCATION, metaLocation) scribus.setStyle(STYLE_META, metaLocation) metaLogo = scribus.createImage(logoPos["x"], logoPos["y"], LOGO_WIDTH, LOGO_HEIGHT) scribus.loadImage("logo.png", metaLogo) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=metaLogo)
def placerandom_bars(iteration): for i in range(iteration): imagedir = "./elements/" random_x = random.randint(0,int(document_width)) random_y = random.randint(0,int(document_height)) randomsize_x = random.randint(100,105) randomsize_y = random.randint(50,50) bars = scribus.createImage(random_x, random_y, randomsize_x, randomsize_y) scribus.loadImage(imagedir + "ubuntu_bar.png", bars) scribus.setScaleImageToFrame(1,1,bars) i = random.randint(0,2) if i == 0: random_degree = 0 elif i == 1: random_degree = 120 elif i == 2: random_degree = 240 scribus.rotateObject(random_degree, bars) scribus.sentToLayer("randombars", bars)
# extract the dictionary content description = distros[distro][0] filesizeiso = distros[distro][1] md5sum = distros[distro][2] modified = distros[distro][3] # create page title/header B = scribus.createText(left_page_x, 10, 100, 10) scribus.setText(distro, B) scribus.setFont("Gentium Plus Compact Regular", B) scribus.setTextAlignment(scribus.ALIGN_LEFT, B) scribus.setFontSize(18, B) # load small-logo into page imagedir = "./logos/" f = scribus.createImage(left_page_x, 23, 65, 65) scribus.loadImage(imagedir + distro + ".png", f) scribus.setScaleImageToFrame(1,1,f) scribus.sentToLayer("textlayer", f) # get description text for each distro scribus.createText(left_page_x, 92, 120, 80,distro) scribus.setText(description, distro) scribus.setLineSpacing(12,distro) linespacing = scribus.getLineSpacing(distro) scribus.setFont("Gentium Plus Compact Regular", distro) scribus.setTextAlignment(scribus.ALIGN_LEFT, distro) scribus.setFontSize(10, distro) scribus.sentToLayer("textlayer", distro) # place some background stuff
sys.exit(1) print(filename_png) filename_svg = os.path.splitext(filename_png)[0] + '.svg' print(filename_svg) scratchblocks_svg = os.path.join(download_path, 'scratchblocks.svg') print(scratchblocks_svg + ' >> ' + filename_svg) if os.path.isfile(scratchblocks_svg): os.rename(scratchblocks_svg, filename_svg) else: scribus.messageBox('Error:', 'Cannot find ' + filename_svg) # https://gitlab.com/inkscape/inbox/issues/405 # FitCanvasToDrawing cannot be run without a GUI call([ 'inkscape', '--verb=FitCanvasToDrawing', '--verb=FileSave', '--verb=FileQuit', filename_svg ]) call(['inkscape', '-z', '--export-dpi=300', filename_svg, '-e', filename_png]) if (scribus.getObjectType(item) == 'TextFrame'): (x, y) = scribus.getPosition() (w, h) = scribus.getSize() scribus.deleteObject() name = scribus.createImage(x, y, w, h) scribus.selectObject(name) scribus.loadImage(filename_png)
page = 1 pagenum = scribus.pageCount while page <= len(D): scribus.gotoPage(page) # if imagecount > 0: # scribus.newPage(-1) # framecount = 0 # L is the frame at the top of each page showing the directory name # L = scribus.createText(15, 20, 200, 20) # scribus.setText("Dir: " + imagedir, L) # scribus.setTextAlignment(scribus.ALIGN_LEFT, L) # scribus.setFont(labelFont, L) # scribus.setFontSize(10, L) # Here is where we're loading images into the page, four at a time, then go back up for a newPage if imagecount < len(D): f = scribus.createImage(-3.175, -3.175, pwidth, pheight) scribus.loadImage(imagedir + '/' + D[imagecount], f) scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=f) #lenfilename = len(D[imagecount]) #Lpiclen = int(5.3 * lenfilename) # Lpic is the label for each picture, with position and length adjusted # according to the text length, so if you change the font or its size, # you may need to adjust this only approximate calculation. # Lpic = scribus.createText(x, y + 193, Lpiclen, 15) # scribus.setText(D[imagecount], Lpic) # scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic) # scribus.setFont(labelFont, Lpic) # scribus.setFontSize(8, Lpic) # scribus.setFillColor("White", Lpic) imagecount += 1 page += 1
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) page += 1
leftMargin=bleed, topMargin=bleed, rightMargin=bleed, bottomMargin=bleed, orientation=scribus.LANDSCAPE, firstPageNumber=1, unit=scribus.UNIT_INCHES, pagesType=scribus.FACINGPAGES, firstPageOrder=scribus.FIRSTPAGERIGHT, numPages=1 ) create_document() if COVER_PHOTO: frame = scribus.createImage(-0.4723, 0, 12.5788, 8.3681) # après essai, cf F2 scribus.loadImage(COVER_PHOTO, frame) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=frame) scribus.createText(0, 0, cover_width, cover_height, "total") # x, y, width, height scribus.createText((bleed + margin_out), (bleed + margin_out), frame_width, frame_height, "back")
while imagecount < len(D): scribus.gotoPage(page) # if imagecount > 0: # scribus.newPage(-1) # framecount = 0 # L is the frame at the top of each page showing the directory name # L = scribus.createText(15, 20, 200, 20) # scribus.setText("Dir: " + imagedir, L) # scribus.setTextAlignment(scribus.ALIGN_LEFT, L) # scribus.setFont(labelFont, L) # scribus.setFontSize(10, L) # Here is where we're loading images into the page, four at a time, then go back up for a newPage for y in ypos: if imagecount < len(D): for x in xpos: f = scribus.createImage(x, y, pwidth, pheight) scribus.loadImage(imagedir + '/' + D[imagecount], f) scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=f) #lenfilename = len(D[imagecount]) #Lpiclen = int(5.3 * lenfilename) # Lpic is the label for each picture, with position and length adjusted # according to the text length, so if you change the font or its size, # you may need to adjust this only approximate calculation. # Lpic = scribus.createText(x, y + 193, Lpiclen, 15) # scribus.setText(D[imagecount], Lpic) # scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic) # scribus.setFont(labelFont, Lpic) # scribus.setFontSize(8, Lpic) # scribus.setFillColor("White", Lpic)
def main(argv): unit = scribus.getUnit() units = ['pts', 'mm', 'inches', 'picas', 'cm', 'ciceros'] unitlabel = units[unit] #layout_style = "" #frame = 3 #border = 3 # layout style layout_style = scribus.valueDialog("Layout Style", layout_text, mylayout) if layout_style == "h": scribus.messageBox("Help", help_text) sys.exit() if layout_style == "v": createDefaultVal() sys.exit() if layout_style == "": sys.exit() # frame frame_str = scribus.valueDialog( "Set Page Frame", "Set page frame size (" + unitlabel + ") :\n(positive for page margin,\nnegative for page bleed)\n", myframe) if frame_str != "": frame = float(frame_str) else: sys.exit() # border if int(layout_style) > 1: border_str = scribus.valueDialog( "Add Image Border", "Add border around images (" + unitlabel + ") :\n", myborder) if border_str != "": border = float(border_str) else: sys.exit() else: border = 0 bleed = -frame # get page size xysize = scribus.getPageSize() size = (xysize[0] + 2 * bleed, xysize[1] + 2 * bleed) #scribus.createImage(0, 0, size[0]/2, size[1]/2) # layouts # one image on two pages (put it on the left page) if layout_style == "0": scribus.createImage(0 + border - bleed, 0 + border - bleed, (size[0] * 2) - border - bleed * 2, size[1] - border) # one image on one full page if layout_style == "1": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] - border * 2, size[1] - border * 2) # two vertical images if layout_style == "2": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] - border * 2) scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] - border * 2) #guides scribus.setVGuides( [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed]) #scribus.setHGuides([size[1]/2-border-bleed, size[1]/2+border-bleed]) # two horizontal images if layout_style == "22": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] - border * 2, size[1] / 2 - border * 2) scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed, size[0] - border * 2, size[1] / 2 - border * 2) #guides #scribus.setVGuides([size[0]/2-border-bleed, size[0]/2+border-bleed]) scribus.setHGuides( [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed]) # one vertical image left, two horizontal images right if layout_style == "3": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] - border * 2) scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) scribus.createImage(size[0] / 2 + border - bleed, size[1] / 2 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) #guides scribus.setVGuides( [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed]) scribus.setHGuides( [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed]) # one vertical image left, two horizontal images right if layout_style == "33": scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] - border * 2) scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) #guides scribus.setVGuides( [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed]) scribus.setHGuides( [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed]) # one image on top, two images on bottom if layout_style == "333": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] - border * 2, size[1] / 2 - border * 2) scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) scribus.createImage(size[0] / 2 + border - bleed, size[1] / 2 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) #guides scribus.setVGuides( [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed]) scribus.setHGuides( [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed]) # one image on top, two images on bottom if layout_style == "3333": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed, size[0] - border * 2, size[1] / 2 - border * 2) #guides scribus.setVGuides( [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed]) scribus.setHGuides( [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed]) # four horizontal images if layout_style == "4": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) scribus.createImage(size[0] / 2 + border - bleed, size[1] / 2 + border - bleed, size[0] / 2 - border * 2, size[1] / 2 - border * 2) #guides scribus.setVGuides( [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed]) scribus.setHGuides( [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed]) # six images 3 + 3 if layout_style == "6": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] / 3 - border * 2, size[1] / 2 - border * 2) scribus.createImage(size[0] / 3 + border - bleed, 0 + border - bleed, size[0] / 3 - border * 2, size[1] / 2 - border * 2) scribus.createImage((size[0] / 3) * 2 + border - bleed, 0 + border - bleed, size[0] / 3 - border * 2, size[1] / 2 - border * 2) scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed, size[0] / 3 - border * 2, size[1] / 2 - border * 2) scribus.createImage(size[0] / 3 + border - bleed, size[1] / 2 + border - bleed, size[0] / 3 - border * 2, size[1] / 2 - border * 2) scribus.createImage((size[0] / 3) * 2 + border - bleed, size[1] / 2 + border - bleed, size[0] / 3 - border * 2, size[1] / 2 - border * 2) #guides scribus.setVGuides([ size[0] / 3 - border - bleed, size[0] / 3 - bleed + border, (size[0] / 3) * 2 - border - bleed, (size[0] / 3) * 2 + border - bleed ]) scribus.setHGuides( [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed]) # six images 2 +2 + 2 if layout_style == "66": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, size[1] / 3 - border * 2) scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed, size[0] / 2 - border * 2, (size[1] / 3) - border * 2) scribus.createImage(0 + border - bleed, size[1] / 3 + border - bleed, size[0] / 2 - border * 2, size[1] / 3 - border * 2) scribus.createImage(size[0] / 2 + border - bleed, size[1] / 3 + border - bleed, size[0] / 2 - border * 2, (size[1] / 3) - border * 2) scribus.createImage(0 + border - bleed, (size[1] / 3) * 2 + border - bleed, size[0] / 2 - border * 2, size[1] / 3 - border * 2) scribus.createImage(size[0] / 2 + border - bleed, (size[1] / 3) * 2 + border - bleed, size[0] / 2 - border * 2, (size[1] / 3) - border * 2) #guides scribus.setVGuides( [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed]) scribus.setHGuides([ size[1] / 3 - border - bleed, size[1] / 3 + border - bleed, (size[1] / 3) * 2 - border - bleed, (size[1] / 3) * 2 + border - bleed ]) # nine images if layout_style == "9": scribus.createImage(0 + border - bleed, 0 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) scribus.createImage(size[0] / 3 + border - bleed, 0 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) scribus.createImage((size[0] / 3) * 2 + border - bleed, 0 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) scribus.createImage(0 + border - bleed, size[1] / 3 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) scribus.createImage(size[0] / 3 + border - bleed, size[1] / 3 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) scribus.createImage((size[0] / 3) * 2 + border - bleed, size[1] / 3 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) scribus.createImage(0 + border - bleed, (size[1] / 3) * 2 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) scribus.createImage(size[0] / 3 + border - bleed, (size[1] / 3) * 2 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) scribus.createImage((size[0] / 3) * 2 + border - bleed, (size[1] / 3) * 2 + border - bleed, size[0] / 3 - border * 2, size[1] / 3 - border * 2) #guides scribus.setVGuides([ size[0] / 3 - border - bleed, size[0] / 3 - bleed + border, (size[0] / 3) * 2 - border - bleed, (size[0] / 3) * 2 + border - bleed ]) scribus.setHGuides([ size[1] / 3 - border - bleed, size[1] / 3 + border - bleed, (size[1] / 3) * 2 - border - bleed, (size[1] / 3) * 2 + border - bleed ])
def loadimages(img_id, img_x, img_y, img_width, img_height, img_path, layer, scaletoframe): scribus.createImage(img_x, img_y, img_width, img_height, img_id) scribus.loadImage(img_path, img_id) scribus.sentToLayer(layer, img_id)
def loadimages(img_id, img_x, img_y, img_width, img_height, img_path, layer, scaletoframe): scribus.createImage(img_x, img_y, img_width, img_height, img_id) scribus.loadImage(img_path, img_id) scribus.sentToLayer(layer, img_id) # create new document (smallsquare) if scribus.newDocument((document_width,document_height), (0,6.35,3.175,3.175), scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.PAGE_2, 1, 0): i = 0 scribus.createLayer("images") scribus.createLayer("text") textframes("titel", 42.5, 50, 129.7, 17.99, "White","Black", 39, "FreeSans Bold", 0, "DIE SCHWÄRZUNG","text", 0, 0) scribus.createLine(20.2,67.5,190.2,67.5) scribus.createImage(55, 72.7, 99.5, 20.2, "logo") scribus.loadImage("handydandy_logo.eps", "logo") scribus.sentToLayer("images", "logo") scribus.setScaleImageToFrame(1,1,"logo") textframes("jahr", 81.7, 216.7, 46.1, 18.5, "White","Black", 22, "FreeSans Medium", 0, "2006 - 2012","text", 0, 0) scribus.newPage(-1) slike = glob.glob("pics/*.jpg") slike.sort() for slika in slike: img_id = "img_id" + str(i) loadimages(img_id,0,0,209.55,273.1,slika,"images",0) i += 1 if (i > 796): break
# Check also if picture frame is empty, otherwise do not process it: if (albumdata.pages[pagenum].layers[layercount]. elements[elementcount].type == 'PICTURE') and ( albumdata.pages[pagenum].layers[layercount]. elements[elementcount].picture != None): size_x = albumdata.pages[pagenum].layers[ layercount].elements[elementcount].size.width size_y = albumdata.pages[pagenum].layers[ layercount].elements[elementcount].size.height x_pos = albumdata.pages[pagenum].layers[ layercount].elements[elementcount].position.x - ( size_x / 2) y_pos = albumdata.pages[pagenum].layers[ layercount].elements[elementcount].position.y - ( size_y / 2) f = scribus.createImage(x_pos, y_pos, size_x, size_y) scribus.loadImage( imagedir + albumdata.pages[pagenum].layers[layercount]. elements[elementcount].picture.id + ".JPG", f) scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=f) # https://wiki.scribus.net/canvas/Fitting_an_Image_to_its_Frame # fitimage2frame_v2.py --> An advantage of this method is that will work regardless of the proportions of the image. # If you want to use this in Scribus versions >=1.5.0, you will need to change the scaleImage() command to setImageScale(), otherwise with the same parameters inside xscale, yscale = scribus.getImageScale(f) width_pi = int(albumdata.pages[pagenum].layers[layercount]. elements[elementcount].picture.dimension. width) #original image width in pixels height_pi = int( albumdata.pages[pagenum].layers[layercount].
def main (self) : # Load up all the file and record information. # Use CSV reader to build list of record dicts records = self.loadCSVData(self.dataFile) totalRecs = len(records) # Reality check first to see if we have anything to process if totalRecs <= 0 : scribus.messageBox('Not Found', 'No records found to process!') sys.exit() pageNumber = 1 recCount = 0 row = 0 pageSide = 'Odd' scribus.progressTotal(totalRecs) paIndex = {} lastName = '' firstName = '' photoFirstName = '' verseRef = '' verseText = '' # Get the page layout coordinates for this publication crds = self.getCoordinates(self.dimensions) # Make a new document to put our records on if scribus.newDocument(getattr(scribus, self.dimensions['page']['scribusPageCode']), (self.dimensions['margins']['left'], self.dimensions['margins']['right'], self.dimensions['margins']['top'], self.dimensions['margins']['bottom']), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT, 1) : self.setPageNumber(crds, pageSide, row, pageNumber) while recCount < totalRecs : # Output a new page on the first row after we have done the first page if row == 0 and recCount != 0: scribus.newPage(-1) if pageSide == 'Odd' : pageSide = 'Even' else : pageSide = 'Odd' self.setPageNumber(crds, pageSide, row, pageNumber) ########### Now set the current record in the current row ########## # Set the last name lastName = records[recCount]['NameLast'] # Adjust the NameFirst field to include the spouse if there is one if records[recCount]['Spouse'] != '' : firstName = records[recCount]['NameFirst'] + ' & ' + records[recCount]['Spouse'] else : firstName = records[recCount]['NameFirst'] # Make the photo file name photoFirstName = firstName.replace('&', '-').replace('.', '').replace(' ', '') # Set our record count for progress display and send a status message scribus.progressSet(recCount) scribus.statusMessage('Placing record ' + `recCount` + ' of ' + `totalRecs`) # Add a watermark if a string is specified if self.outputWatermark : self.addWatermark() # Put the last name element in this row nameLastBox = scribus.createText(crds[row]['nameLastXPos'], crds[row]['nameLastYPos'], crds[row]['nameLastWidth'], crds[row]['nameLastHeight']) scribus.setText(lastName, nameLastBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, nameLastBox) scribus.setTextDistances(0, 0, 0, 0, nameLastBox) scribus.setFont(self.fonts['nameLast']['bold'], nameLastBox) scribus.setFontSize(self.fonts['nameLast']['size'], nameLastBox) scribus.setTextShade(80, nameLastBox) scribus.rotateObject(90, nameLastBox) # Place the first name element in this row nameFirstBox = scribus.createText(crds[row]['nameFirstXPos'], crds[row]['nameFirstYPos'], crds[row]['nameFirstWidth'], crds[row]['nameFirstHeight']) scribus.setText(records[recCount]['Caption'], nameFirstBox) scribus.setTextAlignment(scribus.ALIGN_LEFT, nameFirstBox) scribus.setFont(self.fonts['nameFirst']['boldItalic'], nameFirstBox) scribus.setFontSize(self.fonts['nameFirst']['size'], nameFirstBox) # Place the image element in this row # We will need to do some processing on the first pass # The default output format is JPG orgImgFileName = records[recCount]['Photo'] orgImgFile = os.path.join(self.orgImgDir, orgImgFileName) baseImgFileName = lastName + '_' + photoFirstName if self.willBePngImg : ext = 'png' else : ext = 'jpg' if not self.rgbColor : imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '-gray' + '.' + ext) else : imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '.' + ext) # Process the image now if there is none if not os.path.exists(imgFile) : self.img_process.sizePic(orgImgFile, imgFile, self.maxHeight) # self.img_process.outlinePic(imgFile, imgFile) self.img_process.scalePic(imgFile, imgFile, self.imgDensity) self.img_process.addPoloroidBorder(imgFile, imgFile) # Color RGB is the default if not self.rgbColor : self.img_process.makeGray(imgFile, imgFile) # Double check the output and substitute with placeholder pic if not os.path.exists(imgFile) : imgFile = self.placeholderPic # Create the imageBox and load the picture imageBox = scribus.createImage(crds[row]['imageXPos'], crds[row]['imageYPos'], crds[row]['imageWidth'], crds[row]['imageHeight']) if os.path.isfile(imgFile) : scribus.loadImage(imgFile, imageBox) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=imageBox) # Place the country element in this row (add second one if present) countryBox = scribus.createText(crds[row]['countryXPos'], crds[row]['countryYPos'], crds[row]['countryWidth'], crds[row]['countryHeight']) countryLine = records[recCount]['Country1'] try : if records[recCount]['Country2'] != '' : countryLine = countryLine + ' & ' + records[recCount]['Country2'] except : pass scribus.setText(countryLine, countryBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, countryBox) scribus.setFont(self.fonts['text']['boldItalic'], countryBox) scribus.setFontSize(self.fonts['text']['size'], countryBox) # Place the assignment element in this row assignBox = scribus.createText(crds[row]['assignXPos'], crds[row]['assignYPos'], crds[row]['assignWidth'], crds[row]['assignHeight']) scribus.setText(self.fixText(records[recCount]['Assignment']), assignBox) # Assign style to box # scribus.createParagraphStyle(name='assignStyle', alignment=0, leftmargin=10, firstindent=-10) # scribus.setStyle('assignStyle', assignBox) # Hard formated box scribus.setTextAlignment(scribus.ALIGN_LEFT, assignBox) scribus.setFont(self.fonts['text']['italic'], assignBox) scribus.setFontSize(self.fonts['text']['size'], assignBox) scribus.setLineSpacing(self.fonts['text']['size'] + 1, assignBox) scribus.setTextDistances(4, 0, 0, 0, assignBox) # Resize the frame height and determine the difference for # placing the next frame below it assignHeightNew = self.resizeFrame(assignBox) assignHeightDiff = crds[row]['assignHeight'] - assignHeightNew # Place the verse element in this row verseYPosNew = crds[row]['verseYPos'] - assignHeightDiff verseBox = scribus.createText(crds[row]['verseXPos'], verseYPosNew, crds[row]['verseWidth'], crds[row]['verseHeight']) # The verse element may be either a Scripture verse or a prayer request # If it is Scripture, and it has a verse ref, we want to set that # seperatly so we need to do a little preprocess on the text to find # out if it has a ref. This script will only recognize references # at the end of the string that are enclosed in brackets. See the # findVerseRef() function for more details verseRef = self.findVerseRef(records[recCount]['Prayer']) if verseRef : verseText = self.removeVerseRef(self.fixText(records[recCount]['Prayer'])) scribus.setText(verseText, verseBox) else : scribus.setText(self.fixText(records[recCount]['Prayer']), verseBox) # Can't find a way to set alignment to justified using setTextAlignment() # scribus.setTextAlignment(scribus.ALIGN_LEFT, verseBox) # Because of this, we make a style which seems to work scribus.createParagraphStyle(name='vBoxStyle', alignment=3) scribus.setStyle('vBoxStyle', verseBox) scribus.setFont(self.fonts['verse']['regular'], verseBox) scribus.setFontSize(self.fonts['verse']['size'], verseBox) scribus.setLineSpacing(self.fonts['verse']['size'] + 1, verseBox) scribus.setTextDistances(4, 0, 4, 0, verseBox) if self.hyphenate : scribus.hyphenateText(verseBox) # Get the height difference in case we need to set ref box verseHeightNew = self.resizeFrame(verseBox) verseHeightDiff = crds[row]['verseHeight'] - verseHeightNew if verseRef : # Set coordinates for this box vRefBoxX = crds[row]['verseXPos'] vRefBoxY = (verseYPosNew + verseHeightNew) vRefBoxH = crds[row]['nameFirstHeight'] / 2 vRefBoxW = crds[row]['verseWidth'] verseRefBox = scribus.createText(vRefBoxX, vRefBoxY, vRefBoxW, vRefBoxH) scribus.setText(verseRef, verseRefBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, verseRefBox) scribus.setFont(self.fonts['verse']['italic'], verseRefBox) scribus.setFontSize(self.fonts['verse']['size'] - 2, verseRefBox) scribus.setLineSpacing(self.fonts['verse']['size'], verseRefBox) scribus.setTextDistances(2, 0, 0, 0, verseRefBox) # Up our counts if row >= self.dimensions['rows']['count'] - 1 : row = 0 pageNumber +=1 else : row +=1 recCount +=1 # Create the index page here # Output a new page for the index if row == 0 and recCount != 0: scribus.newPage(-1) if pageSide == 'Odd' : pageSide = 'Even' else : pageSide = 'Odd' self.setPageNumber(crds, pageSide, 0, pageNumber) # Outut the index entries at this point # for key in paIndex.keys() : # Report we are done now before we loose focus scribus.statusMessage('Process Complete!') ############################################################################### ############################## Output Results ################################# ############################################################################### # Now we will output the results to PDF if that is desired if self.makePdf : pdfExport = scribus.PDFfile() pdfExport.info = self.pdfFile pdfExport.file = self.pdfFile pdfExport.save() # View the output if set if self.makePdf and self.viewPdf : cmd = ['evince', self.pdfFile] try : subprocess.Popen(cmd) except Exception as e : result = scribus.messageBox ('View PDF command failed with: ' + str(e), scribus.BUTTON_OK)
def main(self): # Load up all the file and record information. # Use CSV reader to build list of record dicts records = self.loadCSVData(self.dataFile) totalRecs = len(records) # Reality check first to see if we have anything to process if totalRecs <= 0: scribus.messageBox('Not Found', 'No records found to process!') sys.exit() pageNumber = 1 recCount = 0 row = 0 pageSide = 'Odd' scribus.progressTotal(totalRecs) paIndex = {} lastName = '' firstName = '' photoFirstName = '' verseRef = '' verseText = '' # Get the page layout coordinates for this publication crds = self.getCoordinates(self.dimensions) # Make a new document to put our records on if scribus.newDocument( getattr(scribus, self.dimensions['page']['scribusPageCode']), (self.dimensions['margins']['left'], self.dimensions['margins']['right'], self.dimensions['margins']['top'], self.dimensions['margins']['bottom']), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT, 1): self.setPageNumber(crds, pageSide, row, pageNumber) while recCount < totalRecs: # Output a new page on the first row after we have done the first page if row == 0 and recCount != 0: scribus.newPage(-1) if pageSide == 'Odd': pageSide = 'Even' else: pageSide = 'Odd' self.setPageNumber(crds, pageSide, row, pageNumber) ########### Now set the current record in the current row ########## # Set the last name lastName = records[recCount]['NameLast'] # Adjust the NameFirst field to include the spouse if there is one if records[recCount]['Spouse'] != '': firstName = records[recCount][ 'NameFirst'] + ' & ' + records[recCount]['Spouse'] else: firstName = records[recCount]['NameFirst'] # Make the photo file name photoFirstName = firstName.replace('&', '-').replace( '.', '').replace(' ', '') # Set our record count for progress display and send a status message scribus.progressSet(recCount) scribus.statusMessage('Placing record ' + ` recCount ` + ' of ' + ` totalRecs `) # Add a watermark if a string is specified if self.outputWatermark: self.addWatermark() # Put the last name element in this row nameLastBox = scribus.createText(crds[row]['nameLastXPos'], crds[row]['nameLastYPos'], crds[row]['nameLastWidth'], crds[row]['nameLastHeight']) scribus.setText(lastName, nameLastBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, nameLastBox) scribus.setTextDistances(0, 0, 0, 0, nameLastBox) scribus.setFont(self.fonts['nameLast']['bold'], nameLastBox) scribus.setFontSize(self.fonts['nameLast']['size'], nameLastBox) scribus.setTextShade(80, nameLastBox) scribus.rotateObject(90, nameLastBox) # Place the first name element in this row nameFirstBox = scribus.createText(crds[row]['nameFirstXPos'], crds[row]['nameFirstYPos'], crds[row]['nameFirstWidth'], crds[row]['nameFirstHeight']) scribus.setText(records[recCount]['Caption'], nameFirstBox) scribus.setTextAlignment(scribus.ALIGN_LEFT, nameFirstBox) scribus.setFont(self.fonts['nameFirst']['boldItalic'], nameFirstBox) scribus.setFontSize(self.fonts['nameFirst']['size'], nameFirstBox) # Place the image element in this row # We will need to do some processing on the first pass # The default output format is JPG orgImgFileName = records[recCount]['Photo'] orgImgFile = os.path.join(self.orgImgDir, orgImgFileName) baseImgFileName = lastName + '_' + photoFirstName if self.willBePngImg: ext = 'png' else: ext = 'jpg' if not self.rgbColor: imgFile = os.path.join( getattr(self, ext + 'ImgDir'), baseImgFileName + '-gray' + '.' + ext) else: imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '.' + ext) # Process the image now if there is none if not os.path.exists(imgFile): self.img_process.sizePic(orgImgFile, imgFile, self.maxHeight) # self.img_process.outlinePic(imgFile, imgFile) self.img_process.scalePic(imgFile, imgFile, self.imgDensity) self.img_process.addPoloroidBorder(imgFile, imgFile) # Color RGB is the default if not self.rgbColor: self.img_process.makeGray(imgFile, imgFile) # Double check the output and substitute with placeholder pic if not os.path.exists(imgFile): imgFile = self.placeholderPic # Create the imageBox and load the picture imageBox = scribus.createImage(crds[row]['imageXPos'], crds[row]['imageYPos'], crds[row]['imageWidth'], crds[row]['imageHeight']) if os.path.isfile(imgFile): scribus.loadImage(imgFile, imageBox) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=imageBox) # Place the country element in this row (add second one if present) countryBox = scribus.createText(crds[row]['countryXPos'], crds[row]['countryYPos'], crds[row]['countryWidth'], crds[row]['countryHeight']) countryLine = records[recCount]['Country1'] try: if records[recCount]['Country2'] != '': countryLine = countryLine + ' & ' + records[recCount][ 'Country2'] except: pass scribus.setText(countryLine, countryBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, countryBox) scribus.setFont(self.fonts['text']['boldItalic'], countryBox) scribus.setFontSize(self.fonts['text']['size'], countryBox) # Place the assignment element in this row assignBox = scribus.createText(crds[row]['assignXPos'], crds[row]['assignYPos'], crds[row]['assignWidth'], crds[row]['assignHeight']) scribus.setText(self.fixText(records[recCount]['Assignment']), assignBox) # Assign style to box # scribus.createParagraphStyle(name='assignStyle', alignment=0, leftmargin=10, firstindent=-10) # scribus.setStyle('assignStyle', assignBox) # Hard formated box scribus.setTextAlignment(scribus.ALIGN_LEFT, assignBox) scribus.setFont(self.fonts['text']['italic'], assignBox) scribus.setFontSize(self.fonts['text']['size'], assignBox) scribus.setLineSpacing(self.fonts['text']['size'] + 1, assignBox) scribus.setTextDistances(4, 0, 0, 0, assignBox) # Resize the frame height and determine the difference for # placing the next frame below it assignHeightNew = self.resizeFrame(assignBox) assignHeightDiff = crds[row]['assignHeight'] - assignHeightNew # Place the verse element in this row verseYPosNew = crds[row]['verseYPos'] - assignHeightDiff verseBox = scribus.createText(crds[row]['verseXPos'], verseYPosNew, crds[row]['verseWidth'], crds[row]['verseHeight']) # The verse element may be either a Scripture verse or a prayer request # If it is Scripture, and it has a verse ref, we want to set that # seperatly so we need to do a little preprocess on the text to find # out if it has a ref. This script will only recognize references # at the end of the string that are enclosed in brackets. See the # findVerseRef() function for more details verseRef = self.findVerseRef(records[recCount]['Prayer']) if verseRef: verseText = self.removeVerseRef( self.fixText(records[recCount]['Prayer'])) scribus.setText(verseText, verseBox) else: scribus.setText(self.fixText(records[recCount]['Prayer']), verseBox) # Can't find a way to set alignment to justified using setTextAlignment() # scribus.setTextAlignment(scribus.ALIGN_LEFT, verseBox) # Because of this, we make a style which seems to work scribus.createParagraphStyle(name='vBoxStyle', alignment=3) scribus.setStyle('vBoxStyle', verseBox) scribus.setFont(self.fonts['verse']['regular'], verseBox) scribus.setFontSize(self.fonts['verse']['size'], verseBox) scribus.setLineSpacing(self.fonts['verse']['size'] + 1, verseBox) scribus.setTextDistances(4, 0, 4, 0, verseBox) if self.hyphenate: scribus.hyphenateText(verseBox) # Get the height difference in case we need to set ref box verseHeightNew = self.resizeFrame(verseBox) verseHeightDiff = crds[row]['verseHeight'] - verseHeightNew if verseRef: # Set coordinates for this box vRefBoxX = crds[row]['verseXPos'] vRefBoxY = (verseYPosNew + verseHeightNew) vRefBoxH = crds[row]['nameFirstHeight'] / 2 vRefBoxW = crds[row]['verseWidth'] verseRefBox = scribus.createText(vRefBoxX, vRefBoxY, vRefBoxW, vRefBoxH) scribus.setText(verseRef, verseRefBox) scribus.setTextAlignment(scribus.ALIGN_RIGHT, verseRefBox) scribus.setFont(self.fonts['verse']['italic'], verseRefBox) scribus.setFontSize(self.fonts['verse']['size'] - 2, verseRefBox) scribus.setLineSpacing(self.fonts['verse']['size'], verseRefBox) scribus.setTextDistances(2, 0, 0, 0, verseRefBox) # Up our counts if row >= self.dimensions['rows']['count'] - 1: row = 0 pageNumber += 1 else: row += 1 recCount += 1 # Create the index page here # Output a new page for the index if row == 0 and recCount != 0: scribus.newPage(-1) if pageSide == 'Odd': pageSide = 'Even' else: pageSide = 'Odd' self.setPageNumber(crds, pageSide, 0, pageNumber) # Outut the index entries at this point # for key in paIndex.keys() : # Report we are done now before we loose focus scribus.statusMessage('Process Complete!') ############################################################################### ############################## Output Results ################################# ############################################################################### # Now we will output the results to PDF if that is desired if self.makePdf: pdfExport = scribus.PDFfile() pdfExport.info = self.pdfFile pdfExport.file = self.pdfFile pdfExport.save() # View the output if set if self.makePdf and self.viewPdf: cmd = ['evince', self.pdfFile] try: subprocess.Popen(cmd) except Exception as e: result = scribus.messageBox( 'View PDF command failed with: ' + str(e), scribus.BUTTON_OK)
def main(argv): unit = scribus.getUnit() units = [' pts','mm',' inches',' picas','cm',' ciceros'] unitlabel = units[unit] if scribus.selectionCount() == 0: scribus.messageBox('Scribus - Script Error', "There is no object selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox('Scribus - Script Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) textbox = scribus.getSelectedObject() pageitems = scribus.getPageItems() boxcount = 1 for item in pageitems: if (item[0] == textbox): if (item[1] != 4): scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) # While we're finding out what kind of frame is selected, we'll also make sure we # will come up with a unique name for our infobox frame - it's possible we may want # more than one for a multicolumn frame. if (item[0] == ("infobox" + str(boxcount) + textbox)): boxcount += 1 left, top = scribus.getPosition(textbox) o_width, o_height = scribus.getSize(textbox) o_cols = int(scribus.getColumns(textbox)) o_gap = scribus.getColumnGap(textbox) columns_width = 0 column_pos = 0 o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols if (o_cols > 1): while (columns_width > o_cols or columns_width < 1): columns_width = scribus.valueDialog('Width', 'How many columns width shall the '+ 'box be (max ' + str(o_cols) + ')?','1') columns_width = int(columns_width) if (columns_width < o_cols): max = o_cols - columns_width while (column_pos <= max and column_pos <= 1): column_pos = scribus.valueDialog('Placement', 'In which column do you want ' 'to place the box (1 to ' + str(o_cols) + ')?','1') column_pos = int(column_pos) - 1 if (o_cols == 1): columns_width = 1 new_height = 0 while (new_height == 0): new_height = scribus.valueDialog('Height','Your frame height is '+ str(o_height) + unitlabel +'. How tall\n do you want your ' + 'infobox to be in '+ unitlabel +'?\n If you load an image, height will be\n calculated, so the value here does not\n matter.', str(o_height)) new_top = -1 while (new_top < 0): new_top = scribus.valueDialog('Y-Pos','The top of your infobox is currently\n'+ str(top) + unitlabel +'. Where do you want \n' + 'the top to be in '+ unitlabel +'?', str(top)) framename = scribus.valueDialog('Name of Frame','Name your frame or use this default name',"infobox" + str(boxcount) + textbox) frametype = 'text' frametype = scribus.valueDialog('Frame Type','Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image',frametype) new_width = columns_width * o_colwidth + (columns_width-1) * o_gap new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap) if (frametype == 'text'): new_textbox = scribus.createText(new_left, float(new_top), new_width, float(new_height),framename) scribus.setColumnGap(0, new_textbox) scribus.setColumns(1, new_textbox) scribus.textFlowMode(new_textbox, 1) else: if (frametype == 'imageL'): imageload = scribus.fileDialog('Load image','Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',haspreview=1) new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename) scribus.loadImage(imageload, new_image) scribus.messageBox('Please Note',"Your frame will be created once you click OK.\n\nUse the Context Menu to Adjust Frame to Image.\n\nIf your image does not fill the width completely,\nstretch the frame vertically first.",scribus.BUTTON_OK) else: new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename) scribus.textFlowMode(new_image, 1) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=new_image)
def main(argv): ########################################### info_text = ''' Welcome to Auto-Photobook! 1. Select the process mode: 9f = creates a 9x9 layout on each page and fill them with images. 4f = creates a 4x4 layout on each page and fill them with images. 9e = creates an empty 9x9 layout on each page. 4e = creates an empty 4x4 layout on each page. 9f+4f = creates a filled 9x9 layout on odd pages and a filled 4x4 layout on even pages. 9e+4e = creates an empty 9x9 layout on odd pages and an empty 4x4 layout on even pages. 9f+4e = creates a filled 9x9 layout on odd pages and an empty 4x4 layout on even pages (default). 9e+4f = creates an empty 9x9 layout on odd pages and a filled 4x4 layout on even pages. 2. Select a document layout, the margins (they need to be equal) and the bleed (if needed). Ignore the number of pages. 3. Define the space between the images (default: 6mm). 4a. If "9f" or "4f" is in your mode, you can choose an image folder and an image filter will be prompted. 4b. Otherwise, set the amount of pages you want to create (default: 10 pages). 5. Wait until it is done... 6. Adjust you layouts and move your images as you need. Process mode:''' # start dialog, choose mode #scribus.messageBox("Auto-Photobook", info_text) todo = scribus.valueDialog("Auto-Photobook", info_text, "9f+4e") todo = list(todo.split("+")) # wrong process mode if "9f" not in todo and "9e" not in todo and "4f" not in todo and "9e" not in todo: scribus.messageBox( "Error", "Wrong process mode. Auto-Photobook was cancelled.") sys.exit() # show new document dialog newdoc = scribus.newDocDialog() # exit if cancelled if newdoc == False: scribus.messageBox("Exit", "Auto-Photobook was cancelled.") sys.exit() if scribus.haveDoc: scribus.setUnit(scribus.UNIT_MILLIMETERS) (w, h) = scribus.getPageSize() ################### # delete all pages except the first: pageamount = scribus.pageCount() while pageamount > 1: scribus.deletePage(pageamount) pageamount = scribus.pageCount() # set image border and bleed border = int( scribus.valueDialog("Space between images", "Define the space between the images (mm).", "6")) #border = 6 # reset image border for easier calculations border = border * 0.75 if "9f" in todo or "4f" in todo: # ask for workdir workdir = scribus.fileDialog("Open directory with images", "", haspreview=False, issave=False, isdir=True) #workdir = "/media/sda7/Programming/Python/scribus_auto_photobook/pics" # file filter filefilter = scribus.valueDialog( "File filter", "File filter examples: \n\n* or *.* = add all files\n*.jpg = add .jpg files only\nIMG_*.* = add all files starting with IMG_\n\nThis filter is case sensitive!", "*.*") # get image paths filelist = sorted(glob.glob(os.path.join(workdir, filefilter))) #filelist = sorted(glob.glob(os.path.join(workdir, "*"))) # count files filesinworkdir = len(filelist) scribus.messageBox( "Files in directory", "Images matched in folder: " + str(filesinworkdir)) #error if filesinworkdir == 0: scribus.messageBox("Error", "This directory is empty.") sys.exit() #messagebar text scribus.messagebarText("Importing images...") #progressbar max scribus.progressTotal(filesinworkdir) # set maxpages (not needed here but needs to be assigned) maxpages = len(filelist) else: # ask for page amount maxpages = int( scribus.valueDialog("Set page amount", "How many pages you want to create?", "10")) #progressbar max scribus.progressTotal(maxpages) # get page size (without bleed) size = scribus.getPageSize() # get margins margins = scribus.getPageMargins()[0] # set page final size final_size = (size[0] - margins, size[1] - margins) # simplify calc for 9x9 layout guide_layout_x = final_size[0] / 3 - margins / 3 guide_layout_y = final_size[1] / 3 - margins / 3 # set indexes page = 1 pic = 0 #create pages, add and load images x = True while x == True: scribus.progressSet(page) scribus.gotoPage(page) # create 9x9 layout if "9f" in todo or "9e" in todo: #guides scribus.setVGuides([ margins + guide_layout_x - border, margins + guide_layout_x + border / 2, margins + guide_layout_x * 2 - border / 2, margins + guide_layout_x * 2 + border ]) scribus.setHGuides([ margins + guide_layout_y - border, margins + guide_layout_y + border / 2, margins + guide_layout_y * 2 - border / 2, margins + guide_layout_y * 2 + border ]) # create images scribus.createImage(margins, margins, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image1") scribus.createImage(margins + guide_layout_x + border / 2, margins, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image2") scribus.createImage(margins + guide_layout_x * 2 + border, margins, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image3") scribus.createImage(margins, margins + guide_layout_y + border / 2, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image4") scribus.createImage(margins + guide_layout_x + border / 2, margins + guide_layout_y + border / 2, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image5") scribus.createImage(margins + guide_layout_x * 2 + border, margins + guide_layout_y + border / 2, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image6") scribus.createImage(margins, margins + guide_layout_y * 2 + border, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image7") scribus.createImage(margins + guide_layout_x + border / 2, margins + guide_layout_y * 2 + border, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image8") scribus.createImage(margins + guide_layout_x * 2 + border, margins + guide_layout_y * 2 + border, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image9") #load and scale images if "9f" in todo: try: scribus.loadImage(filelist[pic], "page" + str(page) + "image1") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image1") scribus.loadImage(filelist[pic + 1], "page" + str(page) + "image2") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image2") scribus.loadImage(filelist[pic + 2], "page" + str(page) + "image3") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image3") scribus.loadImage(filelist[pic + 3], "page" + str(page) + "image4") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image4") scribus.loadImage(filelist[pic + 4], "page" + str(page) + "image5") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image5") scribus.loadImage(filelist[pic + 5], "page" + str(page) + "image6") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image6") scribus.loadImage(filelist[pic + 6], "page" + str(page) + "image7") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image7") scribus.loadImage(filelist[pic + 7], "page" + str(page) + "image8") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image8") scribus.loadImage(filelist[pic + 8], "page" + str(page) + "image9") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image9") except: x = False # increase picture index pic += 9 # add page scribus.newPage(-1) page += 1 # create 4x4 layout if "4f" in todo or "4e" in todo: #guides scribus.setVGuides( [size[0] / 2 - border * 0.75, size[0] / 2 + border * 0.75]) scribus.setHGuides( [size[1] / 2 - border * 0.75, size[1] / 2 + border * 0.75]) # create images scribus.createImage(margins, margins, size[0] / 2 - border * 0.75 - margins, size[1] / 2 - border * 0.75 - margins, "page" + str(page) + "image1") scribus.createImage(size[0] / 2 + border * 0.75, margins, size[0] / 2 - border * 0.75 - margins, size[1] / 2 - border * 0.75 - margins, "page" + str(page) + "image2") scribus.createImage(margins, size[1] / 2 + border * 0.75, size[0] / 2 - border * 0.75 - margins, size[1] / 2 - border * 0.75 - margins, "page" + str(page) + "image3") scribus.createImage(size[0] / 2 + border * 0.75, size[1] / 2 + border * 0.75, size[0] / 2 - border * 0.75 - margins, size[1] / 2 - border * 0.75 - margins, "page" + str(page) + "image4") #load and scale images if "4f" in todo: try: scribus.loadImage(filelist[pic], "page" + str(page) + "image1") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image1") scribus.loadImage(filelist[pic + 1], "page" + str(page) + "image2") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image2") scribus.loadImage(filelist[pic + 2], "page" + str(page) + "image3") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image3") scribus.loadImage(filelist[pic + 3], "page" + str(page) + "image4") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image4") except: x = False # increase picture index pic += 4 # add page scribus.newPage(-1) page += 1 #scribus.setImageOffset(0, 0, "imagename"+str(page)) #scribus.setScaleFrameToImage(name="imagename"+str(page)) # stop if maxpages reached if page > maxpages: x = False #delete last blank page scribus.deletePage(page)
def frontPage(LogoPath, ChurchPath, ChurchImage, Citation, CitationLocation): #scribus.setText('Gemeindebrief DIGITAL Buxtehude',"Oben") #Line upper left corner l_line = scribus.createLine(10,10,10,33,"l_Line") scribus.setLineWidth(0.75, l_line) scribus.setLineColor("NAK-blau 100%", l_line) scribus.setLineShade("NAK-blau 100%", l_line) #Headline t_headline = scribus.createText(10,22,128,20,"t_Headline") scribus.setText("Gemeindebrief", t_headline) scribus.selectText(1, 100, t_headline) scribus.setCharacterStyle( "Erste Seite - Gemeindebrief - gross", t_headline) scribus.deselectAll() # Digital - Text t_digitalText = scribus.createText(107,27,30,7, "t_Digital") scribus.selectText(1, 100, t_digitalText) scribus.setCharacterStyle( "Erste Seite - Gemeindebrief - gross", t_digitalText) scribus.deselectAll() # Congregation - Text t_congregationText = scribus.createText(10,35.250, 70, 6, "t_Congregation") scribus.selectText(1, 100, t_congregationText) scribus.setCharacterStyle( "Erste Seite - Gemeindebrief - klein", t_congregationText) scribus.deselectAll() # Month Year t_monthYear = scribus.createText(56, 46.500, 82, 10, "t_MonthYear") scribus.selectText(1, 100, t_monthYear) scribus.setCharacterStyle( "Erste Seite - Gemeindebrief - Monat", t_monthYear) scribus.deselectAll() # Logo charitable i_charitable = scribus.createImage(10, 46, 35.5, 9, "i_NAC_charitable") scribus.loadImage(LogoPath + "Logo_NAK_karitativ_HQ.tiff", i_charitable) scribus.setImageScale(0.0613, 0.0613, i_charitable) # Church image i_churchImage = scribus.createImage(10,57,128,100,"i_Church") scribus.loadImage(ChurchPath + ChurchImage, i_churchImage) scribus.setImageScale(1, 1, i_churchImage) scribus.setImageOffset(-18.244, -0.342, i_churchImage) # Citation t_citation = scribus.createText(42.500, 162.500,95.500,4.500, "t_Citation") # OverflowCheck scribus.setText(Citation, t_citation) scribus.selectText(1, 100, t_citation) scribus.setCharacterStyle("Erste Seite - Bibelzitat - Text", t_citation) scribus.deselectAll() # Citation Location t_citationLocation = scribus.createText(42.500, 170, 95.500, 3, "t_CitationLocation") scribus.setText(CitationLocation, t_citationLocation) scribus.selectText(1, 100, t_citationLocation) scribus.setCharacterStyle( "Erste Seite - Bibelzitat - Ort", t_citationLocation) scribus.deselectAll() # NAC t_nac = scribus.createText(52.500,195,66,5,"t_NAC") scribus.setText("Neuapostolische Kirche", t_nac) scribus.selectText(1, 100, t_nac) scribus.setCharacterStyle("Erste Seite - NAK", t_nac) scribus.deselectAll() # North and east germany t_northEastGermany = scribus.createText(52.500, 195, 66, 5, "t_NorthEastGermany") scribus.setText("Nord- und Ostdeutschland", t_northEastGermany) scribus.selectText(1, 100, t_northEastGermany) scribus.setCharacterStyle( "Erste Seite - Nord- und Ostdeutschland", t_northEastGermany) scribus.deselectAll() # NAC Logo i_nacLogo = scribus.createImage(122, 184, 16, 16,"i_Logo") scribus.loadImage("L:\\GB\\Bilder\\Logos\\Logo_NAK_HQ.tif", i_nacLogo) scribus.setImageScale(0.0384, 0.0384, i_nacLogo) scribus.saveDocAs()
# framecount = 0 if len(D) > 0: if scribus.newDocument((69.35, 94.35), (0, 0, 0, 0), scribus.PORTRAIT, 1, scribus.UNIT_MM, scribus.PAGE_1, 0, 1): while imagecount < len(D): if imagecount > 0: scribus.newPage(-1) framecount = 0 # L is the frame at the top of each page showing the directory name # L = scribus.createText(15, 20, 200, 20) # scribus.setText("Dir: " + imagedir, L) # scribus.setTextAlignment(scribus.ALIGN_LEFT, L) # scribus.setFont(labelFont, L) # scribus.setFontSize(10, L) # Here is where we're loading images into the page, four at a time, then go back up for a newPage if imagecount < len(D): f = scribus.createImage(0, 0, pwidth, pheight) scribus.loadImage(imagedir + '/' + D[imagecount], f) scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=f) lenfilename = len(D[imagecount]) Lpiclen = int(5.3 * lenfilename) # Lpic is the label for each picture, with position and length adjusted # according to the text length, so if you change the font or its size, # you may need to adjust this only approximate calculation. # Lpic = scribus.createText(x, y + 193, Lpiclen, 15) # scribus.setText(D[imagecount], Lpic) # scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic) # scribus.setFont(labelFont, Lpic) # scribus.setFontSize(8, Lpic) # scribus.setFillColor("White", Lpic) imagecount += 1
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) page += 1
def main(argv): unit = scribus.getUnit() units = [' pts', 'mm', ' inches', ' picas', 'cm', ' ciceros'] unitlabel = units[unit] if scribus.selectionCount() == 0: scribus.messageBox( 'Scribus - Script Error', "There is no object selected.\nPlease select a text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) if scribus.selectionCount() > 1: scribus.messageBox( 'Scribus - Script Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) textbox = scribus.getSelectedObject() pageitems = scribus.getPageItems() boxcount = 1 for item in pageitems: if (item[0] == textbox): if (item[1] != 4): scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) # While we're finding out what kind of frame is selected, we'll also make sure we # will come up with a unique name for our infobox frame - it's possible we may want # more than one for a multicolumn frame. if (item[0] == ("infobox" + str(boxcount) + textbox)): boxcount += 1 left, top = scribus.getPosition(textbox) o_width, o_height = scribus.getSize(textbox) o_cols = int(scribus.getColumns(textbox)) o_gap = scribus.getColumnGap(textbox) columns_width = 0 column_pos = 0 o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols if (o_cols > 1): while (columns_width > o_cols or columns_width < 1): columns_width = scribus.valueDialog( 'Width', 'How many columns width shall the ' + 'box be (max ' + str(o_cols) + ')?', '1') columns_width = int(columns_width) if (columns_width < o_cols): max = o_cols - columns_width while (column_pos <= max and column_pos <= 1): column_pos = scribus.valueDialog( 'Placement', 'In which column do you want ' 'to place the box (1 to ' + str(o_cols) + ')?', '1') column_pos = int(column_pos) - 1 if (o_cols == 1): columns_width = 1 new_height = 0 while (new_height <= 0): new_height = scribus.valueDialog( 'Height', 'Your frame height is ' + str(o_height) + unitlabel + '. How tall\n do you want your ' + 'infobox to be in ' + unitlabel + '?\n If you load an image with the script, height will be\n calculated, so the value here will not\n matter in that case.', str(o_height)) if (not new_height): sys.exit(0) new_height = float(new_height) new_top = -1 while (new_top < 0): new_top = scribus.valueDialog( 'Y-Pos', 'The top of your infobox is currently\n' + str(top) + unitlabel + '. Where do you want \n' + 'the top to be in ' + unitlabel + '?', str(top)) if (not new_top): sys.exit(0) new_top = float(new_top) framename = scribus.valueDialog( 'Name of Frame', 'Name your frame or use this default name', "infobox" + str(boxcount) + textbox) if (not framename): sys.exit(0) frametype = 'text' frametype = scribus.valueDialog( 'Frame Type', 'Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image', frametype) if (not frametype): sys.exit(0) new_width = columns_width * o_colwidth + (columns_width - 1) * o_gap new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap) if (frametype == 'text'): new_textbox = scribus.createText(new_left, float(new_top), new_width, float(new_height), framename) scribus.setColumnGap(0, new_textbox) scribus.setColumns(1, new_textbox) scribus.textFlowMode(new_textbox, 1) else: if (frametype == 'imageL'): imageload = scribus.fileDialog( 'Load image', 'Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)', haspreview=1) new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height), framename) scribus.textFlowMode(new_image, 1) scribus.loadImage(imageload, new_image) scribus.setScaleImageToFrame(1, 0, new_image) currwidth, currheight = scribus.getSize(new_image) Xscale, Yscale = scribus.getImageScale(new_image) if (Xscale != Yscale): scribus.sizeObject(currwidth, currheight * Xscale / Yscale, new_image) scribus.setScaleImageToFrame(1, 1, new_image) else: new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height), framename) scribus.textFlowMode(new_image, 1) scribus.setScaleImageToFrame(1, 1, new_image)
ycount = topMargin # Calculate position of images for i in range(1, numRows+1): xcount = leftMargin for i in range(1, numColumns+1): xpos.append(xcount) ypos.append(ycount) xcount = xcount + columnWidth + gap ycount = ycount + rowHeight + gap while imagecount < len(D): if imagecount > 0: scribus.newPage(-1) framecount = 0 # Here is where we're loading images into the page, four at a time, then go back up for a newPage for x,y in zip(xpos,ypos): if imagecount < len(D): f = scribus.createImage(x, y, imageWidth, imageHeight) scribus.loadImage(imagedir + '/' + D[imagecount], f) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) lenfilename = len(D[imagecount]) Lpiclen = int(5.3 * lenfilename) imagecount += 1 scribus.setRedraw(1) scribus.redrawAll() else: result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)
def createImagePage(self, file, name): scribus.createImage(0, 0, 210, 297, name) scribus.loadImage( file, name) scribus.setScaleImageToFrame(True, True, name)
for i in range(1, numRows + 1): xcount = leftMargin for i in range(1, numColumns + 1): xpos.append(xcount) ypos.append(ycount) xcount = xcount + columnWidth + gap ycount = ycount + rowHeight + gap while imagecount < len(D): if imagecount > 0: scribus.newPage(-1) framecount = 0 # Here is where we're loading images into the page, four at a time, then go back up for a newPage for x, y in zip(xpos, ypos): if imagecount < len(D): f = scribus.createImage(x, y, imageWidth, imageHeight) scribus.loadImage(imagedir + '/' + D[imagecount], f) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f) lenfilename = len(D[imagecount]) Lpiclen = int(5.3 * lenfilename) imagecount += 1 scribus.setRedraw(1) scribus.redrawAll() else: result = scribus.messageBox( 'Not Found', 'No Images found with\n this search selection', scribus.BUTTON_OK)
def main(argv): ########################################### scribus.newDocDialog() if scribus.haveDoc: scribus.setUnit(scribus.UNIT_MILLIMETERS) (w, h) = scribus.getPageSize() ################### # ask for workdir workdir = scribus.fileDialog("Open directory with images", "", haspreview=False, issave=False, isdir=True) #workdir = "/media/sda7/StudioSession3/PDFTools/pics" #workdir = "/media/sda7/ISG/Itex/PhotoVisit/Boilerroom" # file filter filefilter = scribus.valueDialog( "File filter", "File filter examples: \n\n* or *.* = add all files\n*.jpg = add .jpg files only\nIMG_*.* = add all files starting with IMG_\n\nThis filter is case sensitive!", "*.*") # get image paths filelist = sorted(glob.glob(os.path.join(workdir, filefilter))) #scribus.messageBox("Help", str(filelist)) # count files filesinworkdir = len(filelist) #scribus.messageBox("Help", str(filesinworkdir)) #messagebar text scribus.messagebarText("Importing images...") #error if filesinworkdir == 0: scribus.messageBox("Error", "This directory is empty.") sys.exit() # add filename text? addfilenames = scribus.messageBox("Import images", "Files found in workdir : " + str(filesinworkdir) + "\n\nAdd file names to images?", button1=scribus.BUTTON_YES, button2=scribus.BUTTON_NO) #create text layer if addfilenames == 16384: activelayer = scribus.getActiveLayer() scribus.createLayer("Filenames") scribus.setActiveLayer(activelayer) #progressbar max scribus.progressTotal(filesinworkdir) page = 1 #create page, add and load image for i in filelist: scribus.progressSet(page) scribus.gotoPage(page) scribus.createImage(0, 0, w, h, "imagename" + str(page)) scribus.loadImage(filelist[page - 1], "imagename" + str(page)) scribus.setScaleImageToFrame(True, proportional=True, name="imagename" + str(page)) #scribus.setImageOffset(0, 0, "imagename"+str(page)) #scribus.setScaleFrameToImage(name="imagename"+str(page)) # add filename on page? if addfilenames == 16384: scribus.setActiveLayer("Filenames") filename = scribus.createText(2, 2, 50, 10, filelist[page - 1]) scribus.setText(os.path.basename(filelist[page - 1]), filename) scribus.setTextColor("White", filename) scribus.setActiveLayer(activelayer) scribus.newPage(-1) page += 1 #delete last blank page scribus.deletePage(filesinworkdir + 1)
pageHeight=cover_height, leftMargin=bleed, topMargin=bleed, rightMargin=bleed, bottomMargin=bleed, orientation=scribus.LANDSCAPE, firstPageNumber=1, unit=scribus.UNIT_INCHES, pagesType=scribus.FACINGPAGES, firstPageOrder=scribus.FIRSTPAGERIGHT, numPages=1) create_document() if COVER_PHOTO: frame = scribus.createImage(-0.4723, 0, 12.5788, 8.3681) # après essai, cf F2 scribus.loadImage(COVER_PHOTO, frame) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=frame) scribus.createText(0, 0, cover_width, cover_height, "total") # x, y, width, height scribus.createText((bleed + margin_out), (bleed + margin_out), frame_width, frame_height, "back") scribus.createText((bleed + interior_width), 0, spine_width, cover_height, "spine") scribus.createText((bleed + interior_width + spine_width + margin_in), (bleed + margin_out), frame_width, frame_height, "front")