def run(self): selCount = scribus.selectionCount() if selCount == 0: scribus.messageBox('Scribus Data Merger- Usage Error', "There is no objects selected.\nPlease try again.", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(2) csvData = self.loadCsvData() # Create a list with the names of the selected objects: selectedObjects = [] # Loop through the selected objects and put their names into the list selectedObjects o = 0 while (o < selCount): selectedObjects.append(scribus.getSelectedObject(o)) o = o + 1 startingPage = scribus.currentPage() lastRow = len(csvData) if(self.__dataObject.getNumberOfLinesToMerge() != 'All'): lastRow = int(self.__dataObject.getNumberOfLinesToMerge()) lastRow = min(lastRow, len(csvData)) # This will prevent the script from trying to merge data from non-existing rows in the data file currentPage = scribus.currentPage() rowNumber = 0 insertPageBeforeThis = -1 while (rowNumber < lastRow): if(scribus.pageCount() > currentPage): insertPageBeforeThis = currentPage + 1 scribus.newPage(insertPageBeforeThis) # Inserts a page before the page given as an argument currentPage = currentPage + 1 for selectedObject in selectedObjects: # Loop through the names of all the selected objects scribus.gotoPage(startingPage) # Set the working page to the one we want to copy objects from scribus.copyObject(selectedObject) scribus.gotoPage(currentPage) scribus.pasteObject() # Paste the copied object on the new page scribus.docChanged(1) scribus.gotoPage(currentPage) # Make sure ware are on the current page before we call getAllObjects() newPageObejcts = scribus.getAllObjects() for pastedObject in newPageObejcts: # Loop through all the items on the current page objType = scribus.getObjectType(pastedObject) text = CONST.EMPTY if(objType == 'TextFrame'): text = scribus.getAllText(pastedObject) # This should have used getText but getText does not return the text values of just pasted objects text = self.replaceText(csvData[rowNumber], text) scribus.setText(text, pastedObject) if(objType == 'ImageFrame'): text = scribus.getImageFile(pastedObject) # self.info("Image text", text) # Todo: Find out if it is possible to replace text in the ImageFile property rowNumber = rowNumber + 1 scribus.setRedraw(1) scribus.docChanged(1) scribus.messageBox("Merge Completed", "Merge Completed", icon=scribus.ICON_INFORMATION, button1=scribus.BUTTON_OK)
def main(argv): """This is a documentation string. Write a description of what your code does here. You should generally put documentation strings ("docstrings") on all your Python functions.""" ######################### # YOUR CODE GOES HERE # ######################### userdim = scribus.getUnit() # get unit and change it to mm scribus.setUnit(scribus.UNIT_MILLIMETERS) cellwidthleft = 0 cellwidthright = 0 cellHeight = 0 pos = getPosition() while cellwidthleft <= 0: cellwidthL = scribus.valueDialog("Left Cell Width", "How wide (mm) do you wish left cells to be?", "30.0") cellwidthleft = float(cellwidthL) while cellwidthright <= 0: cellwidthR = scribus.valueDialog("Right Cell Width", "How wide (mm) do you wish right cells to be?", "30.0") cellwidthright = float(cellwidthR) while cellHeight <= 0: cellheight = scribus.valueDialog("Cell Height", "How tall (mm) do you wish cells to be?", "10.0") cellHeight = float(cellheight) data = getCSVdata() di = getDataInformation(data) hposition = pos[1] vposition = pos[0] objectlist = [] # here we keep a record of all the created textboxes so we can group them later i = 0 scribus.progressTotal(len(data)) scribus.setRedraw(False) for row in data: c = 0 for cell in row: cell = cell.strip() cellsize = cellwidthleft if c == 1: cellsize = cellwidthright textbox = scribus.createText(hposition, vposition, cellsize, cellHeight) # create a textbox objectlist.append(textbox) scribus.insertText(cell, 0, textbox) # insert the text into the textbox hposition = hposition + cellwidthleft # move the position for the next cell c = 1 vposition = vposition + cellHeight # set vertical position for next row hposition = pos[1] # reset vertical position for next row i = i + 1 scribus.progressSet(i) scribus.groupObjects(objectlist) scribus.progressReset() scribus.setUnit(userdim) # reset unit to previous value scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)
def main(argv): rectColor = "Black" topMargin, leftMargin, rightMargin, bottomMargin = scribus.getPageMargins() pageWidth, pageHeight = scribus.getPageSize() printAreaWidth = pageWidth - leftMargin - rightMargin printAreaHeight = pageHeight - topMargin - bottomMargin vertRectW = random.randrange(2,4) vertRectH = random.randrange(48,50) horRectW = random.randrange(47,49) horRectH = random.randrange(2,5) startx = leftMargin endx = pageWidth - leftMargin - horRectW starty = topMargin endy = pageHeight - topMargin - vertRectH numberRectVert = random.randrange(400,600) numberRectHor = random.randrange(400,600) opacity = 0 scribus.progressTotal(numberRectVert+numberRectHor) scribus.setRedraw(False) for i in range(1, numberRectVert): opacity = opacity + 0.002 xpos = random.randrange(int(startx),int(endx)) ypos = random.randrange(int(starty),int(endy)) rect = scribus.createRect(xpos, ypos, vertRectW, vertRectH) scribus.setFillColor(rectColor, rect) scribus.setLineColor("None", rect) if opacity < 1: scribus.setFillTransparency(opacity, rect) scribus.progressSet(i*2) for i in range(1, numberRectVert): opacity = opacity + 0.002 xpos = random.randrange(int(startx),int(endx)) ypos = random.randrange(int(starty),int(endy)) recthor = scribus.createRect(xpos, ypos, horRectW, horRectH) scribus.setFillColor(rectColor, recthor) scribus.setLineColor("None", recthor) if opacity < 1: scribus.setFillTransparency(opacity, recthor) scribus.progressReset() scribus.docChanged(True) scribus.statusMessage("Done") scribus.setRedraw(True)
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 main(argv): """Main method for importing colors.""" if not scribus.haveDoc() > 0: #do we have a doc? scribus.messageBox("csv2color", "No document to import colors \n Please open one, first.") sys.exit() else: filename=scribus.fileDialog("csv2color", "CSV files(*.csv *.CSV *.txt *.TXT)") while os.path.isdir(filename): filename=scribus.fileDialog("csv2color", "CSV files(*.csv *.CSV *.txt *.TXT)") #proper filename? else: try: colorlist=getColorsFromCsv(filename) messagestring = "You are going to import %i colors \n This may take a while" % len(colorlist) answer = scribus.messageBox("csv2color", messagestring, button1=scribus.BUTTON_OK, button2=scribus.BUTTON_CANCEL) if answer != scribus.BUTTON_OK: sys.exit() else: importColors(colorlist) scribus.docChanged(True) scribus.messageBox("csv2color", "Colors imported! \n Thank you for using csv2color and Scribus!") except: scribus.messageBox("csv2color", "Could not import file!", icon=scribus.ICON_WARNING) sys.exit()
def main_wrapper(): """The main_wrapper() function disables redrawing, sets a sensible generic status bar message, and optionally sets up the progress bar. It then runs the main() function. Once everything finishes it cleans up after the main() function, making sure everything is sane before the script terminates.""" scribus.messageBox("Version",SCRIPT_VERSION) if not scribus.haveDoc(): scribus.messageBox("Bwaaaahaha","Need a base document open") else: scribus.setRedraw(False) try: scribus.statusMessage("Running script...") scribus.progressReset() main() finally: # Exit neatly even if the script terminated with an exception, # so we leave the progress bar and status bar blank and make sure # drawing is enabled. if scribus.haveDoc(): scribus.setRedraw(True) scribus.docChanged(True) scribus.statusMessage("") scribus.progressReset()
else: scribus.deleteText(textbox) scribus.insertText(follow_double, c, textbox) if ((ord(char) == 39) and (c == 0)): scribus.deleteText(textbox) scribus.insertText(lead_single, c, textbox) elif (ord(char) == 39): if ((prevchar == '.') or (prevchar == ',') or (prevchar == '?') or (prevchar == '!')): scribus.deleteText(textbox) scribus.insertText(follow_single, c, textbox) elif ((ord(prevchar) == 34) and ((nextchar != ' ') and (nextchar != ',') and (nextchar != '.'))): scribus.deleteText(textbox) scribus.insertText(lead_single, c, textbox) elif ((prevchar != ' ') and (ord(prevchar) != 34) and (nextchar != ' ')): scribus.deleteText(textbox) scribus.insertText(follow_single, c, textbox) elif ((prevchar == ' ') or ((nextchar != ' ') and (ord(nextchar) != 34))): scribus.deleteText(textbox) scribus.insertText(lead_single, c, textbox) else: scribus.deleteText(textbox) scribus.insertText(follow_single, c, textbox) c += 1 prevchar = char scribus.setRedraw(1) scribus.docChanged(1) endmessage = 'Successfully ran script\n Last character read was '+str(char) # Change this message to your liking scribus.messageBox("Finished", endmessage,icon=0,button1=1)
if not scribus.haveDoc(): scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK) sys.exit(1) scribus.setRedraw(False) selectionCount = scribus.selectionCount() # str('Selected: ' + str(selectionCount)) selected = [] # remember all selected objects for index in range(0, selectionCount): # str(index) selectedObject = scribus.getSelectedObject(index) # str(selectedObject) selected.append(selectedObject) scribus.deselectAll() # change style for each selected object for obj in selected: # str(obj) scribus.selectObject(obj) scribus.selectText(0, scribus.getTextLength(obj), obj) scribus.setStyle(style, obj) scribus.deselectAll() scribus.setRedraw(True) scribus.docChanged(True)