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 drawHeaderFooter(pagetitle): """draw some info on the pages""" # get page size pageSize=scribus.getPageSize() pageWidth=pageSize[0] pageHeight=pageSize[1] #pageMargins pageMargins=scribus.getPageMargins() topMargin=pageMargins[0] leftMargin=pageMargins[1] rightMargin=pageMargins[2] bottomMargin=pageMargins[3] #create textbox and insert text for header textbox=scribus.createText(leftMargin, topMargin, pageWidth-leftMargin-rightMargin, HEADERSIZE) #set proper font size and alignment scribus.setFontSize(18, textbox) scribus.setTextAlignment(scribus.ALIGN_CENTERED, textbox) #load the string into the textbox headerstring=pagetitle scribus.insertText(headerstring, 0, textbox) scribus.setTextColor("Black", textbox) #create textbox and insert text for footer textbox=scribus.createText(leftMargin, pageHeight-bottomMargin-FOOTERSIZE, pageWidth-leftMargin-rightMargin, FOOTERSIZE) #set proper font size and alignment scribus.setFontSize(9, textbox) scribus.setTextAlignment(scribus.ALIGN_LEFT, textbox) #load the string into the textbox footerstring="Created using ColorChart.py V %s script for Scribus by Sebastian Stetter - http://www.sebastianstetter.de" % str(__version__) scribus.insertText(footerstring, 0, textbox) scribus.setTextColor("Black", textbox)
def 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 setPageNumber (self, crds, pageSide, row, pageNumber) : '''Place the page number on the page if called for.''' if self.pageNumbers : # Make the page number box pNumBox = scribus.createText(crds[row]['pageNumXPos' + pageSide], crds[row]['pageNumYPos'], crds[row]['pageNumWidth'], crds[row]['pageNumHeight']) # Put the page number in it and format according to the page we are on scribus.setText(`pageNumber`, pNumBox) if pageSide == 'Odd' : scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNumBox) else: scribus.setTextAlignment(scribus.ALIGN_LEFT, pNumBox) scribus.setFont(self.fonts['pageNum']['bold'], pNumBox) scribus.setFontSize(self.fonts['pageNum']['size'], pNumBox)
def drawColor(colorname, h, v, width, height): # h horizontal position, v vertical position """draws a color chart field with its caption for the given colorname at the h and v position """ # get cmyk values and convert them to 0 - 255 values color = scribus.getColor(colorname) c = int(round(color[0] / 2.55)) m = int(round(color[1] / 2.55)) y = int(round(color[2] / 2.55)) k = int(round(color[3] / 2.55)) # get rgb color rgbcolor = scribus.getColorAsRGB(colorname) r = rgbcolor[0] g = rgbcolor[1] b = rgbcolor[2] # get webcolor webcolor = rgbhex(r, g, b) # but String for Textbox together colorDisplay = colorname if scribus.isSpotColor(colorname): colorDisplay += " (Spot Color)" colorstring = "%s\nC %i, M %i, Y %i, K %i, \nR %i, G %i, B %i \nRGB: %s" % ( colorDisplay, c, m, y, k, r, g, b, webcolor, ) # draw rectangle and set colors rect = scribus.createRect(h, v, width, height) scribus.setFillColor(colorname, rect) # if total amount of color is < 20 draw outline in Black for rectangle, else in same color if c + m + y + k < 20: scribus.setLineColor("Black", rect) else: scribus.setLineColor(colorname, rect) # create textbox and insert text textbox = scribus.createText(h + width + 5, v, 50, height) # set proper font size scribus.setFontSize(11, textbox) scribus.setTextAlignment(scribus.ALIGN_LEFT, textbox) # load the string into the textbox scribus.insertText(colorstring, 0, textbox)
def setPageNumber(self, crds, pageSide, row, pageNumber): '''Place the page number on the page if called for.''' if self.pageNumbers: # Make the page number box pNumBox = scribus.createText(crds[row]['pageNumXPos' + pageSide], crds[row]['pageNumYPos'], crds[row]['pageNumWidth'], crds[row]['pageNumHeight']) # Put the page number in it and format according to the page we are on scribus.setText( ` pageNumber `, pNumBox) if pageSide == 'Odd': scribus.setTextAlignment(scribus.ALIGN_RIGHT, pNumBox) else: scribus.setTextAlignment(scribus.ALIGN_LEFT, pNumBox) scribus.setFont(self.fonts['pageNum']['bold'], pNumBox) scribus.setFontSize(self.fonts['pageNum']['size'], pNumBox)
def drawColor(colorname, h, v, width, height): #h horizontal position, v vertical position """draws a color chart field with its caption for the given colorname at the h and v position """ #get cmyk values and convert them to 0 - 255 values color = scribus.getColor(colorname) c = int(round(color[0] / 2.55)) m = int(round(color[1] / 2.55)) y = int(round(color[2] / 2.55)) k = int(round(color[3] / 2.55)) #get rgb color rgbcolor = scribus.getColorAsRGB(colorname) r = rgbcolor[0] g = rgbcolor[1] b = rgbcolor[2] #get webcolor webcolor = rgbhex(r, g, b) #but String for Textbox together colorDisplay = colorname if scribus.isSpotColor(colorname): colorDisplay += " (Spot Color)" colorstring = "%s\nC %i, M %i, Y %i, K %i, \nR %i, G %i, B %i \nRGB: %s" % ( colorDisplay, c, m, y, k, r, g, b, webcolor) #draw rectangle and set colors rect = scribus.createRect(h, v, width, height) scribus.setFillColor(colorname, rect) #if total amount of color is < 20 draw outline in Black for rectangle, else in same color if c + m + y + k < 20: scribus.setLineColor("Black", rect) else: scribus.setLineColor(colorname, rect) #create textbox and insert text textbox = scribus.createText(h + width + 5, v, 50, height) #set proper font size scribus.setFontSize(11, textbox) scribus.setTextAlignment(scribus.ALIGN_LEFT, textbox) #load the string into the textbox scribus.insertText(colorstring, 0, textbox) scribus.setTextColor("Black", textbox)
def main(argv): scribus.setUnit(scribus.UNIT_MILLIMETERS) # get page size pagesize = scribus.getPageSize() ########################################### # size and position of the exit buttons linksize = pagesize[0] / 30 linkpos = pagesize[0] - linksize - 2 # set up exit to page pagenum = scribus.pageCount() exittopage = scribus.valueDialog( "Exit to page", "Exit buttons should go to page (1-" + str(pagenum) + ") :", "1") #error #if exittopage > pagenum: # scribus.messageBox("Error", "This page doesn't exist.") # sys.exit() # get active layer, create new layer for exit buttons, set it as active activelayer = scribus.getActiveLayer() scribus.createLayer("Exitbuttons") scribus.setActiveLayer("Exitbuttons") #progressbar max scribus.progressTotal(pagenum) # iterate through all the pages page = 1 while (page <= pagenum): #messagebar text scribus.messagebarText("Create exit buttons...") scribus.progressSet(page) scribus.gotoPage(page) # create rectangle exitrect = scribus.createRect(linkpos, 2, linksize, linksize, "exitrect" + str(page)) scribus.setFillColor("White", exitrect) # create text in rectangle exittext = scribus.createText(linkpos, 4, linksize, linksize, "exittext" + str(page)) scribus.setText("X", exittext) scribus.setFontSize(20, exittext) scribus.setTextAlignment(1, exittext) # create link annotation exitlink = scribus.createText(linkpos, 2, linksize, linksize, "exitlink" + str(page)) #setLinkAnnotation(page,x,y,["name"]) scribus.setLinkAnnotation(int(exittopage), 0, 0, exitlink) # add page number to iteration page += 1 # go back to active layer scribus.setActiveLayer(activelayer)
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)
distros.keys().sort() for distro in sorted(distros.iterkeys()): # 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)
def funzioneprincipale(csvData): for line in csvData: i = 0 listacompleta=[] while i < len(line): listacompleta.append(line[i]) #scribus.messageBox('Scribus - Messaggio di test', str(line[i]), scribus.ICON_WARNING, scribus.BUTTON_OK) i = i + 1 if scribus.haveDoc(): #scribus.messageBox('Scribus - Messaggio di test', str(listacompleta), scribus.ICON_WARNING, scribus.BUTTON_OK) #scribus.newDoc(scribus.PAPER_LETTER, (20,20,20,20),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT) #variabili pos_footer_x = 43 pos_y = 521 width1 = 330 width2 = 90 height = 26 max_height = 710 max_width = 520 interlinea = 12.5 margin_sx = 3.5 margin_dx = 3.5 margin_up = 3.5 margin_down = 2 font_size = 8 # primo numero da inserire dopo %VAR_F n = 6 num_col = 3 width3 = width1 + width2 #ciclo tutte le righe del csv for i in range(1, len(csvData)): #scribus.messageBox('Scribus - Messaggio di test', str(len(csvData[i])), scribus.ICON_WARNING, scribus.BUTTON_OK) pos_x = 43 #colonne for j in range(3, len(csvData[i])): #creo la variabile pos_footer, che contiene la nuova posizione della y #che verrà assegnata alla cornice di testo chiamata 'footer' while (pos_x <= max_width): #creazione di 3 colonne con dimensioni diverse # la prima ha larghezza pari a variabile width1 # la seconda e la terza hanno la larghezza pari a width2 if (pos_x <= width1): nometxtbox = "Cella: I=%d, Pos_x=%d, Pos_y=%d" % (i, pos_x, pos_y) cell_label = csvData[i][j] scribus.createText(pos_x, pos_y, width1, height, nometxtbox) scribus.createRect(pos_x, pos_y, width1, height) scribus.setText(cell_label, nometxtbox) #scribus.setText("Testo di pcsvDataa","Testo1") #comando per creare una cornice di testo #modifico la dimensione del testo scribus.setFontSize(font_size, nometxtbox) #modifico i margini (sx, dx, alto, basso) scribus.setTextDistances(margin_sx, margin_dx, margin_up, margin_down, nometxtbox) #modifico l’interlinea scribus.setLineSpacing(interlinea,nometxtbox) j = j + 1 pos_x = pos_x + width1 #n = n + 1 elif (pos_x <= width3): nometxtbox = "Cella: I=%d, Pos_x=%d, Pos_y=%d" % (i, pos_x, pos_y) cell_label = csvData[i][j] scribus.createText(pos_x, pos_y, width2, height, nometxtbox) scribus.createRect(pos_x, pos_y, width2, height) scribus.setText(cell_label, nometxtbox) #Allineo il testo al centro scribus.setTextAlignment(scribus.ALIGN_CENTERED, nometxtbox) scribus.setFontSize(font_size, nometxtbox) scribus.setTextDistances(margin_sx, margin_dx, margin_up, margin_down, nometxtbox) scribus.setLineSpacing(interlinea,nometxtbox) j = j + 1 pos_x = pos_x + width2 #n = n + 1 else: nometxtbox = "Cella: I=%d, Pos_x=%d, Pos_y=%d" % (i, pos_x, pos_y) cell_label = csvData[i][j] scribus.createText(pos_x, pos_y, width2, height, nometxtbox) scribus.createRect(pos_x, pos_y, width2, height) scribus.setText(cell_label, nometxtbox) #Allineo il testo al centro scribus.setTextAlignment(scribus.ALIGN_CENTERED, nometxtbox) scribus.setFontSize(font_size, nometxtbox) scribus.setTextDistances(margin_sx, margin_dx, margin_up, margin_down, nometxtbox) scribus.setLineSpacing(interlinea,nometxtbox) j = j + 1 pos_x = pos_x + width2 #n = n + 1 if pos_y >= max_height: #crea una nuova pagina se la variabile pos_y raggiunge la dimensione #massima prestabilita scribus.newPage(-1) pos_y = height + 20 else: pos_y = pos_y + height #Salvo il documento attivo altrimenti #lo script ScribusGenerator non inserisce la tabella appena creata pos_footer_y = pos_y + height + 5 scribus.moveObjectAbs(pos_footer_x, pos_footer_y,"footer") scribus.saveDoc() else: scribus.messageBox('Alert di errore', "Devi avere una pagina Scribus aperta!!!", scribus.ICON_WARNING, scribus.BUTTON_OK) scribus.newDoc(scribus.PAPER_LETTER, (20,20,20,20),scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, scribus.FIRSTPAGERIGHT) #per importare uno script copiarlo nella cartella: C:\Python27\Lib\site-packages #Ottenere testo da textbox #a=scribus.getText(nometextbox) #mostrare msgbox #scribus.messageBox('Scribus - Messaggio di test', a, scribus.ICON_WARNING, scribus.BUTTON_OK)
scribus.newDocument((pageX, pageY), (0.0, 0.0, 0.0, 0.0), scribus.LANDSCAPE, 1, scribus.UNIT_INCHES, scribus.PAGE_1, 0, 1) #0,13 for final for x in range(0,13): #1,12,6 for final for y in range(1,12,6): rx = x ry = y for zx in range(0,2): for zy in range(0,3): a = scribus.createText(2.25+((zx+0)*(pageX/1.55)), 0.75+(zy*(pageY/3.84)), 1.25, 0.25) scribus.setFont('Arial Regular',a) scribus.setFontSize(12, a) scribus.setTextColor("gray", a) scribus.setTextAlignment(scribus.ALIGN_CENTERED, a) scribus.rotateObject(180, a); rxy = rx-ry scribus.insertText('%(rx)d - %(ry)d = %(rxy)d' % locals(), 0, a) q = scribus.createText(1.0+((zx+0)*(pageX/1.55)), 1.125+(zy*(pageY/3.84)), 4, 1) scribus.setFont('Arial Regular',q) scribus.setFontSize(55, q) scribus.setTextAlignment(scribus.ALIGN_CENTERED, q) scribus.insertText('%(rx)d + %(ry)d =' % locals(), 0, q) ry = ry + 1 l = scribus.createLine(0.0,2.833333,11,2.833333) scribus.setLineColor("gray", l) l = scribus.createLine(0.0,5.666666,11,5.666666) scribus.setLineColor("gray", l)
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)