def importData(filename, idxPro): (nbLogo, nbImg, nbChange, nbPro, nbCol, nbCat) =(0,0,0,0,0,0) global filParam strDir = os.path.dirname(filename) if os.path.isfile(filParam): nbCol=importParametres(filParam, idxPro) if idxPro==1: if os.path.isfile(strDir+LOGO) and scribus.objectExists("imgLogo"): #Logo de la première page lorsque le document est entièrement plié en huit scribus.loadImage(strDir+LOGO, "imgLogo") nbLogo+=1 if os.path.isfile(strDir+LOGO) and scribus.objectExists("imgSmallLogo"): #Petit logo de la dernière page lorsque le document est entièrement plié en huit scribus.loadImage(strDir+SMALL_LOGO, "imgSmallLogo") nbLogo+=1 if os.path.isfile(strDir+QRCODE) and scribus.objectExists("imgQrcode"): #QR code de la dernière page scribus.loadImage(strDir+QRCODE, "imgQrcode") nbImg=1 for img in range(1,5): if os.path.isfile(strDir+("/image%d.png"%img)): #images facultatives scribus.loadImage(strDir+("/image%d.png"%img), "img%d"%img) nbImg+=1 datJ=datetime.date.today() # Date de l'importation comme date de l'annuaire scribus.setText(datJ.strftime("%B %Y"), "txtDate") scribus.setStyle("styleDate","txtDate") if os.path.isfile(filename): #Sociétés de l'annuaire et les noms des catégories (nbChange, nbPro, nbCat)=importSocietes(filename, strDir+CATEGORIE, idxPro) return (nbLogo, nbImg, nbCol, nbChange, nbPro, nbCat)
def createDefaultVal(): scribus.gotoPage(1) if scribus.objectExists("myframe") == False: scribus.createText(-70, 10, 40, 10, "myframelabel") scribus.setText("Default Frame:", "myframelabel") scribus.setProperty("myframelabel", "m_PrintEnabled", False) scribus.createText(-30, 10, 10, 10, "myframe") scribus.setText("3", "myframe") scribus.setProperty("myframe", "m_PrintEnabled", False) if scribus.objectExists("myborder") == False: scribus.createText(-70, 30, 40, 10, "myborderlabel") scribus.setText("Default Border:", "myborderlabel") scribus.setProperty("myborderlabel", "m_PrintEnabled", False) scribus.createText(-30, 30, 10, 10, "myborder") scribus.setText("3", "myborder") scribus.setProperty("myborder", "m_PrintEnabled", False) if scribus.objectExists("mylayout") == False: scribus.createText(-70, 50, 40, 10, "mylayoutlabel") scribus.setText("Default Layout:", "mylayoutlabel") scribus.setProperty("mylayoutlabel", "m_PrintEnabled", False) scribus.createText(-30, 50, 10, 10, "mylayout") scribus.setText("h", "mylayout") scribus.setProperty("mylayout", "m_PrintEnabled", False)
def getColorsFromCsv(filename, idxPro): csvreader=csv.reader(file(filename)) csvcolors=[] for row in csvreader: if len(row)>1 and idxPro==1: name=row[0].strip() if len(row)>4 and name[0:7]=='couleur': c=int(row[1] )* 2.55 c=int(c) m=int(row[2] )* 2.55 m=int(m) y=int(row[3] )* 2.55 y=int(y) k=int(row[4] )* 2.55 k=int(k) if checkValue(c, m, y, k) ==False: scribus.messageBox("importerPros", "At least one CMYK value in your csv file is not correct \n(must be between 0 and 100)\nAborting script - nothing imported.", icon=scribus.ICON_WARNING) sys.exit() color=(name, c, m, y, k) csvcolors.append(color) elif name[0:3]=='txt': if scribus.objectExists(name): scribus.setText(row[1].replace("\\n","\n"), name) nbContent=scribus.getTextLength(name) scribus.selectText(0, nbContent, name) scribus.setStyle("style"+name[3:], name) else: scribus.messageBox("Objet non trouvé","Aucun objet correspondant au paramètre %s n'a été trouvé dans le document vierge"%name) readGlobalParameter(row) return csvcolors
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 create_toc(data): if not scribus.objectExists("TOC"): new_page() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin(1) toc = scribus.createText(margin_left, margin_top, page_width-margin_right-margin_left, page_height-margin_top-margin_bottom) scribus.setNewName("TOC", toc) scribus.insertText("provide a textframe with name 'TOC' in front_matter.sla and i will not create the toc at the end of the document", 0, "TOC") text = "\n".join(("{}\t{}".format(title, pagenum) for (title, pagenum) in data)) scribus.insertText(text, -1, "TOC")
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 # ######################### #copyPlayer("__player__","PLAYER 1") #copyPlayer("__player__","PLAYER 2") #copyPlayer("__player__","PLAYER 3") csv = scribus.fileDialog('Open input', 'CSV files (*.csv)') stuff = { 'NAME': 'Mike Hingley', 'ADDRESS': '22 Trinity Street, Cradley Heath, West Midlands', 'PHOTO': '128.jpg' } print(os.path.dirname(os.path.realpath(sys.argv[0]))) print os.getcwd() print(sys.path[0]) print(os.path.abspath('')) sourceName = "__player__" if scribus.objectExists(sourceName): scribus.selectObject(sourceName) scribus.unGroupObject() childObjectCount = scribus.selectionCount() for x in range(0, childObjectCount): element = scribus.getSelectedObject(x) if scribus.getObjectType(str(element)) == 'TextFrame': current = scribus.getAllText(element) if current in stuff: fontsize = scribus.getFontSize(element) font = scribus.getFont(element) scribus.setText(stuff[current], element) scribus.setFont(font) scribus.setFontSize(fontsize) if scribus.getObjectType(str(element)) == 'ImageFrame': current = scribus.getImageFile(element) currentName = os.path.basename(os.path.normpath(current)) print current print currentName if currentName in stuff: ExistingFolder = os.path.split(current) print ExistingFolder[0] newFile = os.path.join(ExistingFolder[0], stuff[currentName]) print newFile scribus.loadImage(newFile, element) print scribus.getObjectType(str(element)) print str(scribus.getSelectedObject(x)) scribus.groupObjects() print "name = " + scribus.getSelectedObject() scribus.setNewName("__player__", scribus.getSelectedObject())
def create_toc(data): if not scribus.objectExists("TOC"): new_page() page_width, page_height, margin_top, margin_left, margin_right, margin_bottom = page_size_margin( 1) toc = scribus.createText(margin_left, margin_top, page_width - margin_right - margin_left, page_height - margin_top - margin_bottom) scribus.setNewName("TOC", toc) scribus.insertText( "provide a textframe with name 'TOC' in front_matter.sla and i will not create the toc at the end of the document", 0, "TOC") text = "\n".join( ("{}\t{}".format(title, pagenum) for (title, pagenum) in data)) scribus.insertText(text, -1, "TOC")
def importSocietes(filename, fileCat, iPro): arrLines=[]#liste de lignes du fichier csv, chaque ligne est une liste de champs mapCol={}#table de correspondance entre les champs à importer et les numéros de colonne du fichier csv mapCat={}#table de correspondance entre numéro de catégorie et nom de catégorie nbCat=readSocietes(filename, fileCat, mapCat, arrLines, mapCol) (nbChg, nbPro)=(0,0) numPro=1 while scribus.getTextLength("txtPros%d" % numPro)>0 and numPro<=NB_TXT: numPro+=1 if iPro==1 and scribus.objectExists("txtBureauxChange"): scribus.deleteText("txtBureauxChange") scribus.progressTotal(len(arrLines)) strPro="txtPros%d"%numPro scribus.statusMessage("Remplissage du cadre de texte %s..."%strPro) bFirstPro=True strCat="#" for record in arrLines:#Pour chaque pro # log("nbPro=%d\n"%nbPro) if strCat != record[mapCol["cat"]]:#nouvelle categorie strCat=record[mapCol["cat"]] bNewCat=True else: bNewCat=False nbPro+=1 if nbPro<iPro:#déjà importé à l'exécution précédente continue try: scribus.progressSet(nbPro) if record[mapCol["chg"]]=="True" and scribus.objectExists("txtBureauxChange"): try: nbCarBureau=scribus.getTextLength("txtBureauxChange") appendText(u"● "+toUnicode(record[mapCol["nom"]])+"\n","styleChangeTitre","txtBureauxChange") appendText(toUnicode(record[mapCol["adr"]].replace("\\n"," - "))+"\n","styleChangeAdresse","txtBureauxChange") appendText(record[mapCol["post"]]+" "+toUnicode(record[mapCol["ville"]].upper()+"\n"),"styleChangeAdresse","txtBureauxChange") nbChg+=1 except Exception as ex: scribus.messageBox( "Erreur","Une erreur est survenue sur ce bureau de change: \n%s\n\n%s" %(record, str(ex))) sys.exit() else : nbCarBureau=0 nbCar=scribus.getTextLength(strPro) if bNewCat or bFirstPro: if bFirstPro and not bNewCat: appendText(toUnicode(strCat+" (suite)")+"\n","styleProCatSuite",strPro) else: appendText(toUnicode(strCat)+"\n","styleProCat",strPro) bFirstPro=False appendText(u"● "+toUnicode(record[mapCol["nom"]])+"\n","styleProTitre",strPro) if record[mapCol["chg"]]=="True" : appendText(u"\n","styleProBureau",strPro) #icone du bureau de change en police FontAwesome appendText(processDesc(toUnicode(record[mapCol["desc"]]))+"\n","styleProDesc",strPro) if bLivret: strAdr=toUnicode(record[mapCol["adr"]].replace("\\n"," - "))+" - " + toUnicode(record[mapCol["post"]])+" " strAdr+=processDesc(toUnicode(record[mapCol["ville"]].upper())) if record[mapCol["tel"]].strip(): strAdr+=" ("+toUnicode(record[mapCol["tel"]].strip().replace(" ","\xC2\xA0"))+")\n" #numéro de téléphone insécable else: strAdr+="\n" appendText(strAdr, "styleProAdresse", strPro) else: appendText(toUnicode(record[mapCol["adr"]].replace("\\n"," - "))+"\n","styleProAdresse",strPro) appendText(toUnicode(record[mapCol["post"]])+" "+processDesc(toUnicode(record[mapCol["ville"]]).upper())+"\n","styleProAdresse",strPro) if record[mapCol["tel"]].strip(): appendText(processTelephone(record[mapCol["tel"]])+"\n","styleProAdresse",strPro) if scribus.textOverflows(strPro, nolinks=1): #effacement du paragraphe de pro tronqué et du bureau de change en double scribus.selectText(nbCar, scribus.getTextLength(strPro)-nbCar, strPro) scribus.deleteText(strPro) if nbCarBureau: scribus.selectText(nbCarBureau, scribus.getTextLength("txtBureauxChange")-nbCarBureau, "txtBureauxChange") scribus.deleteText("txtBureauxChange") #log("Cadre rempli : le cadre de texte %s est plein à la ligne %d\n" % (strPro, nbPro)) break except Exception as exc: scribus.messageBox( "Erreur","Une erreur est survenue sur ce professionnel: \n%s\n\n%s" %(record, str(exc))) sys.exit() return (nbChg, nbPro, nbCat)
2 = 2 vertical images 22 = 2 horizontal images 3 = 1 image left, 2 images right 33 = 2 images left, 1 image right 333 = 1 image on top, 2 images on bottom 3333 = 2 images on top, 1 image on bottom 4 = 4 images 6 = 6 images, 3x2 66 = 6 images, 2x3 9 = 9 images h = help v = create default variable fields """ if scribus.objectExists("myframe") == True: myframe = scribus.getText("myframe") else: myframe = "3" if scribus.objectExists("myborder") == True: myborder = scribus.getText("myborder") else: myborder = "3" if scribus.objectExists("mylayout") == True: mylayout = scribus.getText("mylayout") else: mylayout = "h" #scribus.messageBox("Values", myframe + "\n" + myborder)