def resizeFrame (self, frame) : '''Resize a frame in place so that it fits the text inside it. Code for this was take from: http://wiki.scribus.net/canvas/Adjust_a_text_frame_to_fit_its_content''' # Now adjust the frame to fit the text # get some page and frame measure (x, ph) = scribus.getPageSize(); (x, x, x, pm) = scribus.getPageMargins(); # warning: gets the margins from document setup not for the current page (x, y) = scribus.getPosition(frame) bottom = (ph - pm) - y (w, h) = scribus.getSize(frame) # if the frame doesn't overflow, shorten it to make it overflow while (((scribus.textOverflows(frame) == 0) or (h > bottom)) and (h > 0)) : h -= 10 scribus.sizeObject(w, h, frame) # resize the frame in 10pt steps while ((scribus.textOverflows(frame) > 0) and (h < bottom)) : h += 10 scribus.sizeObject(w, h, frame) # undo the latest 10pt step and fine adjust in 1pt steps h -= 10 scribus.sizeObject(w, h, frame) while ((scribus.textOverflows(frame) > 0) and (h < bottom)) : h += 1 scribus.sizeObject(w, h, frame) # For vertical sizing operations return the frame height return int(scribus.getSize(frame)[1])
def newWikiTextBlock(cont, x, y, w): h = 0 #title title = scribus.createText(x, y, w, 1) scribus.setText(cont["wp"].title, title) scribus.setTextAlignment(scribus.ALIGN_LEFT, title) scribus.setFont("Open Sans Bold", title) scribus.setFontSize(14, title) scribus.setLineSpacing(14, title) tw, th = scribus.getSize(title) while scribus.textOverflows(title): scribus.sizeObject(tw, th + 1, title) tw, th = scribus.getSize(title) h = th #content content = scribus.createText(x, y + h + 1, w, 1) scribus.setText(cont["summary"], content) scribus.setTextAlignment(scribus.ALIGN_LEFT, content) scribus.setFont("Open Sans Regular", content) scribus.setFontSize(10, content) tw, th = scribus.getSize(content) while scribus.textOverflows(content): scribus.sizeObject(tw, th + 1, content) tw, th = scribus.getSize(content) if h + th > bH: break h = h + th return h
def resizeFrame(self, frame): '''Resize a frame in place so that it fits the text inside it. Code for this was take from: http://wiki.scribus.net/canvas/Adjust_a_text_frame_to_fit_its_content''' # Now adjust the frame to fit the text # get some page and frame measure (x, ph) = scribus.getPageSize() (x, x, x, pm) = scribus.getPageMargins() # warning: gets the margins from document setup not for the current page (x, y) = scribus.getPosition(frame) bottom = (ph - pm) - y (w, h) = scribus.getSize(frame) # if the frame doesn't overflow, shorten it to make it overflow while (((scribus.textOverflows(frame) == 0) or (h > bottom)) and (h > 0)): h -= 10 scribus.sizeObject(w, h, frame) # resize the frame in 10pt steps while ((scribus.textOverflows(frame) > 0) and (h < bottom)): h += 10 scribus.sizeObject(w, h, frame) # undo the latest 10pt step and fine adjust in 1pt steps h -= 10 scribus.sizeObject(w, h, frame) while ((scribus.textOverflows(frame) > 0) and (h < bottom)): h += 1 scribus.sizeObject(w, h, frame) # For vertical sizing operations return the frame height return int(scribus.getSize(frame)[1])
def newWikiTextBlock(cont,x,y,w): h = 0 #title title = scribus.createText(x, y, w, 1) scribus.setText(cont["wp"].title, title) scribus.setTextAlignment(scribus.ALIGN_LEFT, title) scribus.setFont("Open Sans Bold", title) scribus.setFontSize(14, title) scribus.setLineSpacing(14, title) tw,th = scribus.getSize(title) while scribus.textOverflows(title): scribus.sizeObject(tw, th+1, title) tw,th = scribus.getSize(title) h = th #content content = scribus.createText(x, y+h+1, w, 1) scribus.setText(cont["summary"], content) scribus.setTextAlignment(scribus.ALIGN_LEFT, content) scribus.setFont("Open Sans Regular", content) scribus.setFontSize(10, content) tw,th = scribus.getSize(content) while scribus.textOverflows(content): scribus.sizeObject(tw, th+1, content) tw,th = scribus.getSize(content) if h+th > bH: break h = h+th return h
def expandFrame(self): """Text is inserted into a frame without regard to frame size. Later we expand the frame to fit the text, carrying text to a new frame if necessary.""" numcarries = 0 self.raiseImages() if self.frame != None: while scribus.textOverflows(self.frame, ) > 0: (x, y) = scribus.getPosition(self.frame) (width, height) = scribus.getSize(self.frame) if y + height < self.pageheight - self.bottommargin: scribus.sizeObject(width, height + 1, self.frame) else: fullpage = (y <= self.topmargin and self.columns == 1) if self.buffer != [] and not self.framelinked and numcarries < 4 and not fullpage: numcarries = numcarries + 1 scribus.deselectAll() scribus.deleteText(self.frame) for (content, style) in self.contents: self.styleText(content, style, self.frame) newcontents = self.buffer[:] self.newFrame(columns=self.columns) for (content, style) in newcontents: self.styleText(content, style, self.frame) self.buffer = newcontents[:] else: lastframe = self.frame self.newFrame(columns=self.columns) scribus.linkTextFrames(lastframe, self.frame) self.framelinked = True self.raiseImages()
def expandFrame(self): """Text is inserted into a frame without regard to frame size. Later we expand the frame to fit the text, carrying text to a new frame if necessary.""" numcarries = 0 self.raiseImages() if self.frame != None: while scribus.textOverflows(self.frame,) > 0: (x,y) = scribus.getPosition(self.frame) (width,height) = scribus.getSize(self.frame) if y + height < self.pageheight - self.bottommargin: scribus.sizeObject(width, height + 1, self.frame) else: fullpage = (y <= self.topmargin and self.columns == 1) if self.buffer != [] and not self.framelinked and numcarries < 4 and not fullpage: numcarries = numcarries + 1 scribus.deselectAll() scribus.deleteText(self.frame) for (content,style) in self.contents: self.styleText(content,style,self.frame) newcontents = self.buffer[:] self.newFrame(columns=self.columns) for (content,style) in newcontents: self.styleText(content,style,self.frame) self.buffer = newcontents[:] else: lastframe = self.frame self.newFrame(columns=self.columns) scribus.linkTextFrames(lastframe,self.frame) self.framelinked = True self.raiseImages()
def 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 newFrame(self, height=MINFRAMESIZE, columns=2): """Start a new text frame. If we are working with 2 columns, we build each column as a seperate frame. Scribus does support multi column text frames, but with no keep-with-next functionality its of no use.""" self.flushImages() if columns == 2 and self.frame != None and self.currentcolumn == 1: # Start the second column. (x,y) = scribus.getPosition(self.frame) (w,h) = scribus.getSize(self.frame) width = w xpos = x + w + COLUMNGAP ypos = y self.currentcolumn = 2 else: # First column or full width frame while True: ypos = self.topmargin for obj in scribus.getAllObjects(): if obj in self.textframes: (x,y) = scribus.getPosition(obj) (w,h) = scribus.getSize(obj) if y + h > ypos: ypos = y + h + FRAMEGAP if ypos + height > self.pageheight - self.bottommargin: self.newPage() self.flushImages() else: break xpos = self.leftmargin if columns == 1: width = self.pagewidth - self.leftmargin - self.rightmargin self.currentcolumn = 0 else: width = self.columnwidth self.currentcolumn = 1 self.frame = scribus.createText(xpos, ypos, width, height) self.contents = [] self.buffer = [] self.columns = columns self.framelinked = False self.textframes.append(self.frame)
def newFrame(self, height=MINFRAMESIZE, columns=2): """Start a new text frame. If we are working with 2 columns, we build each column as a seperate frame. Scribus does support multi column text frames, but with no keep-with-next functionality its of no use.""" self.flushImages() if columns == 2 and self.frame != None and self.currentcolumn == 1: # Start the second column. (x, y) = scribus.getPosition(self.frame) (w, h) = scribus.getSize(self.frame) width = w xpos = x + w + COLUMNGAP ypos = y self.currentcolumn = 2 else: # First column or full width frame while True: ypos = self.topmargin for obj in scribus.getAllObjects(): if obj in self.textframes: (x, y) = scribus.getPosition(obj) (w, h) = scribus.getSize(obj) if y + h > ypos: ypos = y + h + FRAMEGAP if ypos + height > self.pageheight - self.bottommargin: self.newPage() self.flushImages() else: break xpos = self.leftmargin if columns == 1: width = self.pagewidth - self.leftmargin - self.rightmargin self.currentcolumn = 0 else: width = self.columnwidth self.currentcolumn = 1 self.frame = scribus.createText(xpos, ypos, width, height) self.contents = [] self.buffer = [] self.columns = columns self.framelinked = False self.textframes.append(self.frame)
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 __init__(self, *args): """ Optional argument "name" """ if len(args) > 0: self.name = args[0] self.path = sc.getImageFile(self.name) self.width, self.height = sc.getSize(self.name) self.offset_x, self.offset_y = sc.getImageOffset(self.name) self.scale_x, self.scale_y = sc.getImageScale(self.name)
def fit_height(textbox): # come to a state that the text box does not overflow: width, height = scribus.getSize(textbox) to_add = height + 1 while scribus.textOverflows(textbox): scribus.sizeObject(width, height + to_add, textbox) to_add = to_add * 2 # reduce height step = height/2 overflows = False counter = 0 while step > 0.05 or overflows: counter += 1 width, old_height = scribus.getSize(textbox) if scribus.textOverflows(textbox): scribus.sizeObject(width, old_height + step, textbox) else: scribus.sizeObject(width, old_height - step, textbox) step = step * 0.5 overflows = scribus.textOverflows(textbox)
def freeSpace(self, width, height): ypos = self.topmargin for obj in scribus.getAllObjects(): if not obj in self.sidebar.frames: (x,y) = scribus.getPosition(obj) (w,h) = scribus.getSize(obj) if y + h > ypos: ypos = y + h + COLUMNGAP + 1 if ypos + height <= self.pageheight - self.bottommargin and self.gotSpace(self.leftmargin, ypos, width, height): return ypos else: return -1
def fit_height(textbox): # come to a state that the text box does not overflow: width, height = scribus.getSize(textbox) to_add = height + 1 while scribus.textOverflows(textbox): scribus.sizeObject(width, height + to_add, textbox) to_add = to_add * 2 # reduce height step = height / 2 overflows = False counter = 0 while step > 0.05 or overflows: counter += 1 width, old_height = scribus.getSize(textbox) if scribus.textOverflows(textbox): scribus.sizeObject(width, old_height + step, textbox) else: scribus.sizeObject(width, old_height - step, textbox) step = step * 0.5 overflows = scribus.textOverflows(textbox)
def freeSpace(self, width, height): ypos = self.topmargin for obj in scribus.getAllObjects(): if not obj in self.sidebar.frames: (x, y) = scribus.getPosition(obj) (w, h) = scribus.getSize(obj) if y + h > ypos: ypos = y + h + COLUMNGAP + 1 if ypos + height <= self.pageheight - self.bottommargin and self.gotSpace( self.leftmargin, ypos, width, height): return ypos else: return -1
def main(): if sc.selectionCount() == 2: images = ( sc.getSelectedObject(0), sc.getSelectedObject(1) ) for image in images: if sc.getObjectType(image) != "ImageFrame": logging.debug(f"Image type {sc.getObjectType(image)}, but 'ImageFrame' expected") error_msg(f'{image} not an image frame. But type {sc.getObjectType(image)}') image_files = (sc.getImageFile(images[0]), sc.getImageFile(images[1])) # keep Scale and Offset, before reset by image load image_0_offset = sc.getImageOffset(images[0]) image_0_scale = sc.getImageScale(images[0]) image_1_offset = sc.getImageOffset(images[1]) image_1_scale = sc.getImageScale(images[1]) sc.loadImage(image_files[1], images[0]) sc.loadImage(image_files[0], images[1]) if sc.getSize(images[0]) == sc.getSize(images[1]): # Frames have the same size swap scale and offset logging.debug(f"Frames have the same size {sc.getSize(images[0])}, swap offset and scale") logging.debug(f"Image 0: {images[0]}, Image 1: {images[1]}") logging.debug(f"Image properties: offset {sc.getImageOffset(images[0])}, scale {image_0_scale}") sc.setImageOffset(*image_1_offset, images[0]) sc.setImageScale(*image_1_scale, images[0]) sc.setImageOffset(*image_0_offset, images[1]) sc.setImageScale(*image_0_scale, images[1]) else: # scale and center logging.debug("Different size scale and center, both.") for name in images: x, y = sff.scale_to_frame(name) sff.center_image(name, x, y) else: logging.debug(f"{sc.selectionCount()} frames selected.") error_msg(f'{sc.selectionCount()} frames selected')
def alignImage(self): if scribus.haveDoc(): restore_units = scribus.getUnit( ) # since there is an issue with units other than points, scribus.setUnit(0) # we switch to points then restore later. nbrSelected = scribus.selectionCount() objList = [] for i in range(nbrSelected): objList.append(scribus.getSelectedObject(i)) scribus.deselectAll() for i in range(nbrSelected): try: obj = objList[i] scribus.selectObject(obj) frameW, frameH = scribus.getSize(obj) saveScaleX, saveScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(1, 0, obj) fullScaleX, fullScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(0, 0, obj) scribus.setImageScale(saveScaleX, saveScaleY, obj) imageW = frameW * (saveScaleX / fullScaleX) imageH = frameH * (saveScaleY / fullScaleY) imageX = 0.0 imageY = 0.0 if self.alignVar.get()[0] == "T": imageY = 0.0 elif self.alignVar.get()[0] == "M": imageY = (frameH - imageH) / 2.0 elif self.alignVar.get()[0] == "B": imageY = (frameH - imageH) if self.alignVar.get()[1] == "L": imageX = 0.0 elif self.alignVar.get()[1] == "C": imageX = (frameW - imageW) / 2.0 elif self.alignVar.get()[1] == "R": imageX = (frameW - imageW) scribus.setImageOffset(imageX, imageY, obj) scribus.docChanged(1) scribus.setRedraw(True) scribus.deselectAll() except: nothing = "nothing" scribus.setUnit(restore_units) self.master.destroy()
def alignImage(self): if scribus.haveDoc(): restore_units = scribus.getUnit() # since there is an issue with units other than points, scribus.setUnit(0) # we switch to points then restore later. nbrSelected = scribus.selectionCount() objList = [] for i in range(nbrSelected): objList.append(scribus.getSelectedObject(i)) scribus.deselectAll() for i in range(nbrSelected): try: obj = objList[i] scribus.selectObject(obj) frameW, frameH = scribus.getSize(obj) saveScaleX, saveScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(1, 0, obj) fullScaleX, fullScaleY = scribus.getImageScale(obj) scribus.setScaleImageToFrame(0, 0, obj) scribus.setImageScale(saveScaleX, saveScaleY, obj) imageW = frameW * (saveScaleX / fullScaleX) imageH = frameH * (saveScaleY / fullScaleY) imageX = 0.0 imageY = 0.0 if self.alignVar.get()[0] == "T": imageY = 0.0 elif self.alignVar.get()[0] == "M": imageY = (frameH - imageH) / 2.0 elif self.alignVar.get()[0] == "B": imageY = (frameH - imageH) if self.alignVar.get()[1] == "L": imageX = 0.0 elif self.alignVar.get()[1] == "C": imageX = (frameW - imageW) / 2.0 elif self.alignVar.get()[1] == "R": imageX = (frameW - imageW) scribus.setImageOffset(imageX, imageY, obj) scribus.docChanged(1) scribus.setRedraw(True) scribus.deselectAll() except: nothing = "nothing" scribus.setUnit(restore_units) self.master.destroy()
def getPosition(): if scribus.selectionCount() == 1: areaname = scribus.getSelectedObject() position = scribus.getPosition(areaname) vpos = position[1] hpos = position[0] size = scribus.getSize(areaname) width = size[0] height = size[1] scribus.deleteObject(areaname) return vpos, hpos, width, height else: scribus.messageBox( "csv2table", "please select ONE Object to mark the drawing area for the table") sys.exit()
def drawPlaceholders(): page = scribus.getPageSize() margin = scribus.getPageMargins() # add the page margins rectangle = scribus.createRect(margin[1], margin[0], (page[0] - margin[1] - margin[2]), (page[1] - margin[0] - margin[3])) scribus.setFillColor('none', rectangle) scribus.setLineColor('Blue', rectangle) scribus.setLineWidth(0.4, rectangle) # add horizontal and vertical guides for item in scribus.getHGuides(): line = scribus.createLine(0, item, page[0], item) scribus.setLineColor('Black', line) scribus.setLineWidth(0.6, line) scribus.setLineStyle(scribus.LINE_DASHDOT, line) for item in scribus.getVGuides(): line = scribus.createLine(item, 0, item, page[0]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.6, line) scribus.setLineStyle(scribus.LINE_DASHDOT, line) # add a "crossed frame" for missing images for item in scribus.getAllObjects(): if scribus.getObjectType(item) == 'ImageFrame': image = scribus.getImageFile(item) if image == '': pos = scribus.getPosition(item) size = scribus.getSize(item) rectangle = scribus.createRect(pos[0], pos[1], size[0], size[1]) scribus.setFillColor('none', rectangle) scribus.setLineColor('Black', rectangle) scribus.setLineWidth(0.4, rectangle) line = scribus.createLine(pos[0], pos[1], pos[0] + size[0], pos[1] + size[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.4, line) line = scribus.createLine(pos[0], pos[1] + size[1], pos[0] + size[0], pos[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.4, line)
def center_image(name, image_x, image_y): """ name: image naem image_x: original image width image_y: original image higth """ scaleC, _ = sc.getImageScale(name) offX, offY = sc.getImageOffset(name) frame_x, frame_y = sc.getSize(name) ix = image_x * scaleC iy = image_y * scaleC if ix != frame_x: offX = (frame_x - ix) / 2 if iy != frame_y: offY = (frame_y - iy) / 2 sc.setImageOffset(offX, offY, name)
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 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 drawPlaceholders(): page = scribus.getPageSize() margin = scribus.getPageMargins() # add the page margins rectangle = scribus.createRect(margin[1], margin[0], (page[0] - margin[1] - margin[2]), (page[1] - margin[0] - margin[3])) scribus.setFillColor('none', rectangle) scribus.setLineColor('Blue', rectangle) scribus.setLineWidth(0.4, rectangle) # add horizontal and vertical guides for item in scribus.getHGuides(): line = scribus.createLine(0, item , page[0], item) scribus.setLineColor('Black', line) scribus.setLineWidth(0.6, line) scribus.setLineStyle(scribus.LINE_DASHDOT, line) for item in scribus.getVGuides(): line = scribus.createLine(item, 0 , item, page[0]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.6, line) scribus.setLineStyle(scribus.LINE_DASHDOT, line) # add a "crossed frame" for missing images for item in scribus.getAllObjects(): if scribus.getObjectType(item) == 'ImageFrame': image = scribus.getImageFile(item) if image == '': pos = scribus.getPosition(item) size = scribus.getSize(item) rectangle = scribus.createRect(pos[0], pos[1], size[0], size[1]) scribus.setFillColor('none', rectangle) scribus.setLineColor('Black', rectangle) scribus.setLineWidth(0.4, rectangle) line = scribus.createLine(pos[0], pos[1] , pos[0] + size[0], pos[1] + size[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.4, line) line = scribus.createLine(pos[0], pos[1] + size[1], pos[0] + size[0], pos[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.4, line)
def scale_to_frame(obj): """ scales the image so that it fills the frame completely. One dimension of the image (width/height) may overflow the frame, but at least one dimension will fill the frame exactly return scaled image size (X, Y) """ try: sc.setScaleImageToFrame(True, False, obj) scale_x, scale_y = sc.getImageScale(obj) frame_x, frame_y = sc.getSize(obj) sc.setScaleImageToFrame(False, False, obj) if scale_x > scale_y: scale = scale_x elif scale_y > scale_x: scale = scale_y sc.setImageScale(scale, scale, obj) image_x = int(round(frame_x / scale_x)) image_y = int(round(frame_y / scale_y)) return (image_x, image_y) except: logging.info("scaling for image {} failed".format(obj))
PageX,PageY = scribus.getPageSize() leftX, leftY = scribus.getPosition(leftSpineMarker) rightX, rightY = scribus.getPosition(rightSpineMarker) curSpineWidth = rightX - leftX - leftOffset - rightOffset spineWidthDiff = newWidth - curSpineWidth halfWidthDiff = spineWidthDiff / 2 vGuides = [(PageX/2), (PageX/2 + newWidth/2), (PageX/2 - newWidth/2)] hGuides = [] for item in pageItems: if item[0].startswith('spine_background'): X,Y = scribus.getPosition(item[0]) hasSpineBackground = True Xsize,Ysize = scribus.getSize(item[0]) scribus.sizeObject(newWidth, Ysize, item[0]) scribus.moveObjectAbs(PageX/2 - newWidth/2, Y ,item[0]) for item in pageItems: X,Y = scribus.getPosition(item[0]) if item[0].startswith('background'): scribus.moveObject(-halfWidthDiff, 0 , item[0]) Xsize,Ysize = scribus.getSize(item[0]) backgroundSize = Xsize + spineWidthDiff scribus.sizeObject(backgroundSize, Ysize, item[0]) if item[0].startswith('left_'): scribus.moveObject(-halfWidthDiff, 0 , item[0]) if item[0].startswith('left_background'): Xsize,Ysize = scribus.getSize(item[0]) leftBackgroundSize = PageX/2 - X + halfWidthDiff + 0.05
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): 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)
scribus.messageBox('Selection Count', "You must have at least one object selected", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b") captionloc = captionloc[0] location = captionloc.upper() pageunits = scribus.getUnit() scribus.setUnit(scribus.UNIT_POINTS) while count < numselect: frames.append(scribus.getSelectedObject(count)) count += 1 for frame in frames: fwidth, fheight = scribus.getSize(frame) fx, fy = scribus.getPosition(frame) if location == "B": textf = scribus.createText(fx, fy+fheight, fwidth, 24) elif location == "T": textf = scribus.createText(fx, fy-24, fwidth, 24) elif location == "R": textf = scribus.createText(fx + fwidth, fy, 150, 40) elif location == "L": textf = scribus.createText(fx-150, fy + fheight - 40, 150, 40) scribus.setUnit(pageunits) scribus.setRedraw(True)
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)
def main(argv): unit = scribus.getUnit() units = ['pts', 'mm', 'inches', 'picas', 'cm', 'ciceros'] unitlabel = units[unit] # get page size xysize = scribus.getPageSize() # ask for layout style layout_style = scribus.valueDialog("Guides Layout", layout_text, "1") if layout_style == "": sys.exit() # 0 = erase all guides if layout_style == "0": #guides scribus.setVGuides([]) scribus.setHGuides([]) sys.exit() # 1 = guides around page if layout_style == "1": # set guides distance pageguides_str = scribus.valueDialog( "Create Guides around Page", "Set distance to page borders (" + unitlabel + ") :\n\n- positive (e.g. 3) for page margin\n\n- negative (e.g. -3) for page bleed\n", "3") if pageguides_str != "": pageguides = float(pageguides_str) else: sys.exit() #set guides scribus.setVGuides(scribus.getVGuides() + [pageguides, xysize[0] - pageguides]) scribus.setHGuides(scribus.getHGuides() + [pageguides, xysize[1] - pageguides]) # 2 = guides around selected object if layout_style == "2": # set guides distance objectguides_str = scribus.valueDialog( "Create Guides around selected Objects", "Set distance to object borders (" + unitlabel + ") :\n\n- 0 for around the object borders\n\n- positive (e.g. 3) towards inside the object\n\n- negative (e.g. -3) towards outside the object\n", "0") if objectguides_str != "": objectguides = float(objectguides_str) else: sys.exit() if scribus.selectionCount() == 0: scribus.messageBox("Error", "Select an object first !", icon=scribus.ICON_WARNING) sys.exit() #get selected object selection_name = scribus.getSelectedObject(0) objectpos = scribus.getPosition(selection_name) objectsize = scribus.getSize(selection_name) #set guides scribus.setVGuides(scribus.getVGuides() + [ objectpos[0] + objectguides, objectpos[0] + objectsize[0] - objectguides ]) scribus.setHGuides(scribus.getHGuides() + [ objectpos[1] + objectguides, objectpos[1] + objectsize[1] - objectguides ])
import scribus import os import glob pageNum = scribus.pageCount() print(pageNum) result = "" os.chdir(os.path.dirname(scribus.getDocName()) + "/../png") listeImages = sorted(glob.glob("*")) itemNum = 0 for i in range(1, pageNum + 1): scribus.gotoPage(i) for o in scribus.getAllObjects(): if (scribus.getObjectType(o) == "ImageFrame"): if (scribus.getSize(o)[0] >= scribus.getPageSize()[0] * 0.99): #result = result + "item:" + str(itemNum) + " page:" + str(i) + " name: " + o + "\n" + " imageFile:" + scribus.getImageFile(o) scribus.loadImage(listeImages[itemNum], o) itemNum = itemNum + 1 #scribus.messageBox("caption", result) #scribus.messageBox("listeImages", "\n".join(listeImages))
import scribus n = scribus.selectionCount() list = [] for i in range(0, n): list.append(scribus.getSelectedObject(i)) margin = 2 fillColor = "White" lineStyle = "noLine" lineWidth = 0 #deselectAll() for selected in list: x, y = scribus.getPosition(selected) width, height = scribus.getSize(selected) scribus.setFillColor(fillColor, selected) scribus.setLineShade(lineWidth, selected) scribus.setLineWidth(lineWidth, selected) scribus.setLineTransparency(lineWidth, selected) #scribus.setLineStyle(lineStyle, rectangle) #scribus.setStrokeColor(strokeColor, rectangle)
scribus.messageBox( 'Scribus - Script Error', "You have more than one object selected.\nPlease select one text frame and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) textbox = scribus.getSelectedObject() pageitems = scribus.getPageItems() scribus.setRedraw(False) for item in pageitems: if (item[0] == textbox): if (item[1] != 4): scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) lines = scribus.getTextLines(textbox) distances = scribus.getTextDistances(textbox) linespace = scribus.getLineSpacing(textbox) dimensions = scribus.getSize(textbox) # (width, height) if (scribus.textOverflows(textbox, 1) > 0): scribus.messageBox('User Error', "This frame is already overflowing", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) newtopdist = (dimensions[1] - linespace * lines) / 2 scribus.setTextDistances(distances[0], distances[1], newtopdist, distances[3], textbox) scribus.setRedraw(True)
filecontent = filecontent.replace('PTYPE="16"', 'PTYPE="4"') # quick and dirty workaround for setting PRINTABLE attribute to 1 if not already set: filecontent = filecontent.replace('CLIPEDIT="1" PWIDTH=', 'CLIPEDIT="1" PRINTABLE="1" PWIDTH=') filecontent = filecontent.replace('CLIPEDIT="0" PWIDTH=', 'CLIPEDIT="0" PRINTABLE="1" PWIDTH=') filecontent = re.sub(r"(<DefaultStyle[^>].*?>)", "", filecontent) filecontent = re.sub(r"(<TableData[^>].*?>)", "", filecontent) filecontent = re.sub(r"(<Cell [^>].*?>)", "", filecontent) newfile = slafile.replace(".sla", "_1-4.sla") if os.path.isfile(newfile): scribus.messageBox( "Error: The file already exists", "The file '" + newfile + "' already exists.\The script has stopped; Please rename the existing file." ) else: ofile = open(newfile, "w").write(filecontent) scribus.openDoc(newfile) anzahl = scribus.pageCount() for seite in range(1, anzahl + 1): scribus.gotoPage(seite) objects = scribus.getAllObjects() for x in objects: width, height = scribus.getSize(x) scribus.sizeObject(100, 100, x) scribus.sizeObject(width, height, x) scribus.setLineShade(100, x)
# Bachir Soussi Chiadmi - 2015 - outilslibresalternatifs.org - ola#0 import sys sys.path.append('/usr/lib/python3.4/site-packages') import random import string import wikipedia import scribus # help(string) # CONSTANTS # nbr_pages = 4 bpX, bpY = scribus.getPosition('wiki') bW, bH = scribus.getSize('wiki') # block_txt_w = (bW)/2 block_txt_w = 50 nbr_col = bW / block_txt_w # INIT def init(): # k = 0 c = 0 y = bpY x = bpX h = 0 full = 0
def clashes(self, xpos, ypos, width, height, obj): (x,y) = scribus.getPosition(obj) (w,h) = scribus.getSize(obj) return not ((x+w < xpos or x > xpos+width) or (y+h < ypos or y > ypos+height))
if not scribus.haveDoc(): scribus.messagebarText("No .") sys.exit() if scribus.selectionCount() == 0: scribus.messagebarText("No frame selected.") sys.exit() if scribus.selectionCount() > 1: scribus.messagebarText("Please select one single frame.") sys.exit() master_frame = scribus.getSelectedObject() x,y = scribus.getPosition() width, height = scribus.getSize() path = scribus.fileDialog("Pick a directory", scribus.getDocName(), isdir = True) if path == '': scribus.messagebarText("No directory selected.") 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()
def main(argv): unit = scribus.getUnit() units = ['pts','mm','inches','picas','cm','ciceros'] unitlabel = units[unit] # get page size pagesize = scribus.getPageSize() # ask for layout style layout_style = scribus.valueDialog("Select Mirror", layout_text, "v") if layout_style == "": sys.exit() # v = vertical mirror if layout_style == "v": # warn and exit if no selection if scribus.selectionCount() == 0: scribus.messageBox("Error", "Select an object first!", icon=scribus.ICON_WARNING) sys.exit() #create mirror guides scribus.setVGuides(scribus.getHGuides() + [pagesize[0]/2]) #get selected object selection_name = scribus.getSelectedObject(0) objectpos = scribus.getPosition(selection_name) objectsize = scribus.getSize(selection_name) #duplicate object scribus.duplicateObject(selection_name) #move object newobjectpos = (pagesize[0] - (objectpos[0] + objectsize[0]) , objectpos[1]) scribus.moveObjectAbs(newobjectpos[0], objectpos[1], selection_name) #flip object scribus.flipObject(1,0,selection_name) # h = horizontal mirror if layout_style == "h": # warn and exit if no selection if scribus.selectionCount() == 0: scribus.messageBox("Error", "Select an object first!", icon=scribus.ICON_WARNING) sys.exit() #create mirror guides scribus.setHGuides(scribus.getHGuides() + [pagesize[1]/2]) #get selected object selection_name = scribus.getSelectedObject(0) objectpos = scribus.getPosition(selection_name) objectsize = scribus.getSize(selection_name) #duplicate object scribus.duplicateObject(selection_name) #move object newobjectpos = (objectpos[0] , pagesize[1] - (objectpos[1] + objectsize[1])) scribus.moveObjectAbs(objectpos[0], newobjectpos[1], selection_name) #flip object scribus.flipObject(0,1,selection_name)
def load_song(data, offset, settings): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin( page_num) start_point = margin_top + offset new_width = page_width - margin_left - margin_right if not FAST: scribus.placeEPS(os.path.join(FILES, data["filename"]), 0, 0) eps = scribus.getSelectedObject() eps_width, eps_height = scribus.getSize(eps) #scribus.scaleGroup(new_width/eps_width) # slow on scribus 1.4; does something else on scribus 1.5 scribus.sizeObject(eps_width * 0.86, eps_height * 0.86, eps) scribus.moveObjectAbs(margin_left, start_point + SPACING_HEADLINE_SONG, eps) eps_width, eps_height = scribus.getSize(eps) else: eps_height = 0 scribus.deselectAll() textbox = scribus.createText(margin_left, start_point, new_width, 20) style_suffix = get_style_suffix() if data["composer"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["composer"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) if data["poet"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["poet"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) scribus.deselectAll() scribus.insertText(u"{}\n".format(data["name"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("headline_{}".format(style_suffix), textbox) text = data["text"] text = [t.strip() for t in text if t.strip() != ""] # TODO: exit if text == [] textbox = scribus.createText( margin_left, start_point + eps_height + SPACING_HEADLINE_SONG + SPACING_SONG_TEXT, new_width, 50) scribus.setStyle("text", textbox) # let's see how many digits are in there: num_verses = len([l for l in text if l.isdigit()]) num_chars = 0 num_line_total = len(text) num_line_actually = 0 no_new_line = False verse_counter = 0 text_columns_height = 0 # TODO: should be None for num_line, line in enumerate(text): if line.strip == "": continue num_line_actually += 1 if line.isdigit(): print "#", verse_counter, math.ceil( num_verses * 0.5), num_verses, data["filename"] if verse_counter == math.ceil( num_verses * 0.5 ): # this is the first verse that should be in the new column, so let's see what's the height print text_columns_height, num_line_actually text_columns_height = BASELINE_GRID * (num_line_actually - 1) first_char = "\n" if num_line == 0: first_char = "" no_new_line = True line = u"{}{}.\t".format(first_char, line) scribus.insertText(line, -1, textbox) scribus.deselectAll() scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("num", textbox) # no character styles available #scribus.setFontSize(5, textbox) # TODO: testing only # BUG? scribus.setFont("Linux Libertine O Bold", textbox) num_chars += len(line) verse_counter += 1 else: if no_new_line: first_char = "" else: first_char = chr(28) no_new_line = False line = u"{}{}".format(first_char, line) scribus.insertText(line, -1, textbox) #scribus.deselectAll() #scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("text", textbox) num_chars += len(line) scribus.setColumnGap(5, textbox) columns = settings.get("columns", 2) scribus.setColumns(columns, textbox) if columns != 2: fit_height(textbox) else: scribus.sizeObject(new_width, text_columns_height, textbox) l, t = scribus.getPosition(textbox) scribus.moveObjectAbs(l, round(t / BASELINE_GRID) * BASELINE_GRID, textbox) if scribus.textOverflows(textbox): fit_height(textbox) # there are some cases,.. text_width, text_height = scribus.getSize(textbox) text_left, text_top = scribus.getPosition(textbox) return text_top + text_height - start_point + SPACING_SONGS, page_num
def clashes(self, xpos, ypos, width, height, obj): (x, y) = scribus.getPosition(obj) (w, h) = scribus.getSize(obj) return not ((x + w < xpos or x > xpos + width) or (y + h < ypos or y > ypos + height))
def load_song(data, offset, settings): page_num = scribus.pageCount() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(page_num) start_point = margin_top + offset new_width = page_width - margin_left - margin_right if not FAST: scribus.placeEPS(os.path.join(FILES, data["filename"]), 0, 0) eps = scribus.getSelectedObject() eps_width, eps_height = scribus.getSize(eps) #scribus.scaleGroup(new_width/eps_width) # slow on scribus 1.4; does something else on scribus 1.5 scribus.sizeObject(eps_width*0.86, eps_height*0.86, eps) scribus.moveObjectAbs(margin_left, start_point+SPACING_HEADLINE_SONG, eps) eps_width, eps_height = scribus.getSize(eps) else: eps_height = 0 scribus.deselectAll() textbox = scribus.createText(margin_left, start_point, new_width, 20) style_suffix = get_style_suffix() if data["composer"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["composer"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) if data["poet"]: scribus.deselectAll() scribus.insertText(u"{}\n".format(data["poet"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("subline_{}".format(style_suffix), textbox) scribus.deselectAll() scribus.insertText(u"{}\n".format(data["name"]), 0, textbox) scribus.selectText(0, 1, textbox) scribus.setStyle("headline_{}".format(style_suffix), textbox) text = data["text"] text = [t.strip() for t in text if t.strip() != ""] # TODO: exit if text == [] textbox = scribus.createText(margin_left, start_point + eps_height + SPACING_HEADLINE_SONG + SPACING_SONG_TEXT, new_width, 50) scribus.setStyle("text", textbox) # let's see how many digits are in there: num_verses = len([l for l in text if l.isdigit()]) num_chars = 0 num_line_total = len(text) num_line_actually = 0 no_new_line = False verse_counter = 0 text_columns_height = 0 # TODO: should be None for num_line, line in enumerate(text): if line.strip == "": continue num_line_actually += 1 if line.isdigit(): print "#", verse_counter, math.ceil(num_verses * 0.5), num_verses, data["filename"] if verse_counter == math.ceil(num_verses*0.5): # this is the first verse that should be in the new column, so let's see what's the height print text_columns_height, num_line_actually text_columns_height = BASELINE_GRID * (num_line_actually -1) first_char = "\n" if num_line == 0: first_char = "" no_new_line = True line = u"{}{}.\t".format(first_char, line) scribus.insertText(line, -1, textbox) scribus.deselectAll() scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("num", textbox) # no character styles available #scribus.setFontSize(5, textbox) # TODO: testing only # BUG? scribus.setFont("Linux Libertine O Bold", textbox) num_chars += len(line) verse_counter += 1 else: if no_new_line: first_char = "" else: first_char = chr(28) no_new_line = False line = u"{}{}".format(first_char, line) scribus.insertText(line, -1, textbox) #scribus.deselectAll() #scribus.selectText(num_chars, len(line), textbox) #scribus.setStyle("text", textbox) num_chars += len(line) scribus.setColumnGap(5, textbox) columns = settings.get("columns", 2) scribus.setColumns(columns, textbox) if columns != 2: fit_height(textbox) else: scribus.sizeObject(new_width, text_columns_height, textbox) l, t = scribus.getPosition(textbox) scribus.moveObjectAbs(l, round(t/BASELINE_GRID)*BASELINE_GRID, textbox) if scribus.textOverflows(textbox): fit_height(textbox) # there are some cases,.. text_width, text_height = scribus.getSize(textbox) text_left, text_top = scribus.getPosition(textbox) return text_top + text_height - start_point + SPACING_SONGS, page_num
import sys sys.path.append('/usr/lib/python3.4/site-packages') import random import string import wikipedia import scribus # help(string) # CONSTANTS # nbr_pages = 4 bpX, bpY = scribus.getPosition('wiki') bW, bH = scribus.getSize('wiki') # block_txt_w = (bW)/2 block_txt_w = 50 nbr_col = bW / block_txt_w # INIT def init(): # k = 0 c = 0 y = bpY x = bpX h = 0 full = 0
scribus.setLineWidth(0.6, line) scribus.setLineStyle(scribus.LINE_DASHDOT, line) for item in scribus.getVGuides(): line = scribus.createLine(item, 0 , item, page[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.6, line) scribus.setLineStyle(scribus.LINE_DASHDOT, line) # add a "crossed frame" for missing images for item in scribus.getAllObjects(): if scribus.getObjectType(item) == 'ImageFrame': image = scribus.getImageFile(item) if image == '': pos = scribus.getPosition(item) size = scribus.getSize(item) rectangle = scribus.createRect(pos[0], pos[1], size[0], size[1]) scribus.setFillColor('none', rectangle) scribus.setLineColor('Black', rectangle) scribus.setLineWidth(0.4, rectangle) line = scribus.createLine(pos[0], pos[1] , pos[0] + size[0], pos[1] + size[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.4, line) line = scribus.createLine(pos[0], pos[1] + size[1], pos[0] + size[0], pos[1]) scribus.setLineColor('Black', line) scribus.setLineWidth(0.4, line) scribus.setActiveLayer(layer) scribus.setUnit(unit_current)