def main(argv): """Main method - here we check if we have a doc - else we open one. we get all the colors and write them to a csv file.""" if scribus.haveDoc() > 0: #DOC OPEN #get colors, get filename, write stuff cols = getColorsFromDoc() filename = scribus.fileDialog("color2csv: Save csv color file", defaultname="colors.csv", issave=True , haspreview=False) #@TODO: optimize path checking if filename !="": if os.path.exists(filename): #make sure we don't accidentally overwrite existing files answer= scribus.messageBox("color2csv", "File already exists! \n do you want to overwrite it?", icon=scribus.ICON_WARNING, button1=scribus.BUTTON_YES, button2=scribus.BUTTON_ABORT) if answer == scribus.BUTTON_YES: writeColorCsvFile(filename, cols) else: sys.exit() else: writeColorCsvFile(filename, cols) else: sys.exit() else: # NO DOC OPEN - open one! scribusfile = scribus.fileDialog("color2csv: Open scribus file", "Scribus files(*.sla *.SLA *.sla.gz *.SLA.GZ)") if scribusfile !="": try: scribus.openDoc(scribusfile) except: scribus.messageBox("color2csv", "Could not open file!") sys.exit() #get colors, get filename, write stuff cols = getColorsFromDoc() filename = scribus.fileDialog("color2csv: Save csv color file", defaultname="colors.csv", issave=True ) writeColorCsvFile(filename, cols) else: sys.exit()
def main(argv): """Main method""" global filParam if not scribus.haveDoc(): #do we have a doc? scribus.messageBox("importerPros", "Le fichier d'annuaire vierge doit être ouvert pour importer les données") sys.exit() else: filename=scribus.fileDialog("Fichier de données à importer", "Données (*.csv)", "", False) # Images (*.png *.xpm *.jpg) if not filename : sys.exit() filParam=scribus.fileDialog("Fichier de paramètres à utiliser", "Données (*.csv)", filParam, False) if not filParam : sys.exit() else: try: strNum=scribus.getText("txtNumPro") #récupération du dernier numéro de professionnel qui a été écrit dans une zone invisible if scribus.messageBox("Importation des données", "Importation du fichier de données : %s \net des fichiers suivants issus du même répertoire : \n.%s, \n.%s, \n.%s, \n.%s, \n.%s\nNuméro du professionnel à partir duquel le prochain cadre de texte vide sera rempli : %s" % (filename, QRCODE, LOGO, SMALL_LOGO, CATEGORIE, filParam, strNum), scribus.ICON_INFORMATION,scribus.BUTTON_CANCEL, scribus.BUTTON_OK)==scribus.BUTTON_CANCEL: sys.exit() else: nbPro=1 iExec=0 while iExec < NB_TXT: idxPro=nbPro #int(strNum) (nbLogo, nbImg, nbCol, nbChange, nbPro, nbCat)=importData(filename, idxPro) scribus.docChanged(True) #scribus.setText( str(nbPro), "txtNumPro") #scribus.setStyle("styleProTitre", "txtNumPro") if SCRIBUS_BUG and iExec<NB_TXT-1 and scribus.messageBox("importerPros", "%d logos importés \n%d images importées \n%d couleurs importées \n%d bureaux de change \n%d professionnels \n%d catégories\n\nContinuer ?" % (nbLogo, nbImg, nbCol, nbChange, nbPro, nbCat), scribus.ICON_INFORMATION,scribus.BUTTON_CANCEL, scribus.BUTTON_OK)==scribus.BUTTON_CANCEL: sys.exit() else: iExec+=1 except Exception as ex: scribus.messageBox("importerPros", "Erreur : "+str(ex), icon=scribus.ICON_WARNING) sys.exit()
def get_image_dir(start_dir=''): if len(start_dir) == 0: start_dir = os.path.dirname(sc.getDocName()) image_dir = sc.fileDialog('Choose Folder with Images', defaultname=start_dir, isdir=True) return image_dir
def create_content(): dirname = scribus.fileDialog("Select Directory", "", "", False, False, True) files = sorted(glob(os.path.join(dirname, "*"))) if len(files) == 0: return scribus.progressReset() scribus.progressTotal(len(files)) scribus.messagebarText("Creating pages...") progress = 0 for f in files: scribus.progressSet(progress) progress = progress + 1 add_image(f) if len(files) > progress: # add page for next image scribus.newPage(-1) scribus.progressReset() scribus.messagebarText("") scribus.deselectAll() scribus.gotoPage(1)
def main(): docfile = scribus.fileDialog("Find Guidebook Config File", "*.gbk", DOCFILE, haspreview=True, issave=False, isdir=False) if len(docfile) != 0: if not os.path.exists(docfile): scribus.messageBox("Bwaahaha","File does not exist") else: create_guide(fetch.GuidebookParser(docfile))
def main(argv): """Main method - here we check if we have a doc - else we open one. we get all the colors and write them to a csv file.""" if scribus.haveDoc() > 0: #DOC OPEN #get colors, get filename, write stuff cols = getColorsFromDoc() filename = scribus.fileDialog("color2csv: Save csv color file", defaultname="colors.csv", issave=True, haspreview=False) #@TODO: optimize path checking if filename != "": if os.path.exists( filename ): #make sure we don't accidentally overwrite existing files answer = scribus.messageBox( "color2csv", "File already exists! \n do you want to overwrite it?", icon=scribus.ICON_WARNING, button1=scribus.BUTTON_YES, button2=scribus.BUTTON_ABORT) if answer == scribus.BUTTON_YES: writeColorCsvFile(filename, cols) else: sys.exit() else: writeColorCsvFile(filename, cols) else: sys.exit() else: # NO DOC OPEN - open one! scribusfile = scribus.fileDialog( "color2csv: Open scribus file", "Scribus files(*.sla *.SLA *.sla.gz *.SLA.GZ)") if scribusfile != "": try: scribus.openDoc(scribusfile) except: scribus.messageBox("color2csv", "Could not open file!") sys.exit() #get colors, get filename, write stuff cols = getColorsFromDoc() filename = scribus.fileDialog("color2csv: Save csv color file", defaultname="colors.csv", issave=True) writeColorCsvFile(filename, cols) else: sys.exit()
def __init__(self): # scribus.messageBox("Debut",'Init',icon=0,button1=1) # loads the file try: # scribus.messageBox("Debut","try OK : fichier charge dans Books",icon=0,button1=1) self.outputfile = scribus.fileDialog("Choose book file", filter="Book Files (*.sla.bk);;All Files (*)") # self.books = etree.parse("/home/cedric/.scribus/plugins/bookfiles/guideapi.sla.bk") self.books = etree.parse(self.outputfile) except Exception, e: scribus.messageBox("Debut", e, icon=0, button1=1)
def run(self): sourceDir = scribus.fileDialog("Comic Directory", isdir=True) scribus.newDoc( self.pageSize, self.margins, scribus.PORTRAIT, 0, scribus.UNIT_MILLIMETERS, scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT) for resource in os.walk(sourceDir): self.clean_up_and_queue(resource[0], resource[1], resource[2]) scribus.gotoPage(1) test = re.compile("[0-9]{1,}\.(%s)$" % self.formats, re.IGNORECASE) files = filter(test.search, self.images) files.sort() nImages = len(files) if nImages % 4 > 0: print "not" numPages = ( ((nImages / 4) +1 ) * 4 ) else: print ":p" numPages = nImages print numPages for page in range(1, numPages): scribus.newPage(-1) i = 1 for file in files: scribus.gotoPage(i) self.createImagePage(file, "image_%s" % i) i = i + 1 if os.path.isfile("%s/front_cover.jpg" % sourceDir): file = "%s/front_cover.jpg" % sourceDir scribus.newPage(1) scribus.gotoPage(1) self.createImagePage(file, "front_cover") if os.path.isfile("%s/back_cover.jpg" % sourceDir): file = "%s/back_cover.jpg" % sourceDir scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) self.createImagePage(file, "back_cover") if os.path.isfile("%s/logo_cover.svg" % sourceDir): file = "%s/logo_cover.svg" % sourceDir scribus.gotoPage(1) scribus.placeSVG(file, 0, 0) # result = scribus.messageBox('Debug', "%s" % self._comicInfo) scribus.setInfo("Fernando Michelotti", "Comics", "description") scribus.zoomDocument(-100) scribus.saveDoc()
def main(): docfile = scribus.fileDialog("Find Guidebook Config File", "*.gbk", DOCFILE, haspreview=True, issave=False, isdir=False) if len(docfile) != 0: if not os.path.exists(docfile): scribus.messageBox("Bwaahaha", "File does not exist") else: create_guide(fetch.GuidebookParser(docfile))
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 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 getCSVdata(): """opens a csv file, reads it in and returns a 2 dimensional list with the data""" csvfile = scribus.fileDialog("csv2table :: open file", "*.csv") if csvfile != "": try: reader = csv.reader(file(csvfile)) datalist = [] for row in reader: rowlist = [] for col in row: rowlist.append(col) datalist.append(rowlist) return datalist except Exception, e: scribus.messageBox("csv2table", "Could not open file %s" % e)
def getCSVdata(delim, qc): """opens a csv file, reads it in and returns a 2 dimensional list with the data""" csvfile = scribus.fileDialog("csv2table new:: open file", "*.csv") if csvfile != "": try: reader = csv.reader(file(csvfile), delimiter=delim, quotechar=qc) datalist=[] skipfirst=False for row in reader: if skipfirst==True: rowlist=[] for col in row: rowlist.append(col) datalist.append(rowlist) else : skipfirst=True return datalist except Exception, e: scribus.messageBox("csv2table new", "Could not open file %s"%e)
def getColorsFromDocument(): """gets colors from opend document. if there is no document, display dialog to chose a file. returns a list[name,c,m,y,k]""" def getColors(): """gets the colors and returns a list[name,c,m,y,k]""" colorNames = scribus.getColorNames() list = [] scribus.statusMessage("Reading Colors...") stepsTotal = len(colorNames) scribus.progressTotal(stepsTotal) steps = 0 for name in colorNames: color = scribus.getColor(name) listitem = [name, color[0], color[1], color[2], color[3]] list.append(listitem) #update progress bar steps = steps + 1 scribus.progressSet(steps) return list #check if we have a document - otherwise display open file dialog if scribus.haveDoc() > 0: pass list = getColors() return list else: pass #display file open dialog file = scribus.fileDialog( "ColorChart by Sebastian Stetter", 'Scribus files(*.sla *.SLA *.sla.gz *.SLA.GZ)') #open file try: scribus.openDoc(file) except: scribus.messageBox("ColorChart by Sebastian Stetter", "could not open file") sys.exit() list = getColors() return list
def MakeCalendar(argv): """ Main function to create the calendar from within Scribus. Args: command line Returns: None: No error. string: A string containing the error message """ # check for errors in the page template err = TemplateCheck() if err != None: scribus.messageBox("Template Error", err) return err # ask user for working directory path = scribus.fileDialog("Select the working directory", "", "", isdir=True) if path == "" or path == None: scribus.messageBox("tear365off", "aborting...") return None # get file names from template page listFileNames = TemplateGetFileNames() if listFileNames == []: err = "No valid file name tag 't365_' found" scribus.messageBox("Template Error", err) return err # check the contents of the files (roughly) err = FilesCheckContent(path, listFileNames) if err != None: scribus.messageBox("File content mismatch", err) return None
def main(): md_name = scribus.fileDialog("Select a file", 'Markdown (*.md)') if not md_name: return f = NamedTemporaryFile(suffix='.html') markdown.markdownFromFile(md_name, f) f.flush() html_name = f.name i = 0 while True: ob_name = scribus.getSelectedObject(i) if not ob_name: break if scribus.getObjectType(ob_name) == 'TextFrame': scribus.insertHtmlText(html_name, ob_name) i += 1
def main(): if not scribus.haveDoc(): return filename = scribus.fileDialog('Select a document', 'Scribus document (*.sla)') if not filename: return # find the masterpages in use in the source document scribus.openDoc(filename) pages = tuple(range(1, scribus.pageCount() + 1)) masterpages = [scribus.getMasterPage(p) for p in pages] scribus.closeDoc() # the current page before importing page = scribus.currentPage() # import pages by creating them after the current one scribus.importPage(filename, pages, 1, 1) for i, masterpage in enumerate(masterpages): scribus.applyMasterPage(masterpage, page + 1 + i)
def getColorsFromDocument(): """gets colors from opend document. if there is no document, display dialog to chose a file. returns a list[name,c,m,y,k]""" def getColors(): """gets the colors and returns a list[name,c,m,y,k]""" colorNames = scribus.getColorNames() list = [] scribus.statusMessage("Reading Colors...") stepsTotal = len(colorNames) scribus.progressTotal(stepsTotal) steps = 0 for name in colorNames: color = scribus.getColor(name) listitem = [name, color[0], color[1], color[2], color[3]] list.append(listitem) # update progress bar steps = steps + 1 scribus.progressSet(steps) return list # check if we have a document - otherwise display open file dialog if scribus.haveDoc() > 0: pass list = getColors() return list else: pass # display file open dialog file = scribus.fileDialog("ColorChart by Sebastian Stetter", "Scribus files(*.sla *.SLA *.sla.gz *.SLA.GZ)") # open file try: scribus.openDoc(file) except: scribus.messageBox("ColorChart by Sebastian Stetter", "could not open file") sys.exit() list = getColors() return list
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)
Software Foundation; either version 2 of the License, or (at your option) any later version. """ import scribus import os filetype = [] dicttype = {'j': '.jpg', 'p': '.png', 't': '.tif', 'g': '.gif', 'P': '.pdf'} Dicttype = {'j': '.JPG', 'p': '.PNG', 't': '.TIF', 'g': '.GIF', 'P': '.PDF'} nrimages = '0' while (nrimages != '4') and (nrimages != '6'): nrimages = scribus.valueDialog('Pictures', '- US Letter Paper -\n Four or Six Images per Page?\nChange to 6 as desired', '4') imagedir = scribus.fileDialog('Select Image Directory', 'Directories', isdir=True) imagetype = scribus.valueDialog('Image Types', 'Enter the Image Types, where\n j=jpg,p=png,t=tif,g=gif,P=pdf\n "jptgP" selects all', 'jptgP') for t in imagetype[0:]: filetype.append(dicttype[t]) filetype.append(Dicttype[t]) d = os.listdir(imagedir) D = [] for file in d: for format in filetype: if file.endswith(format): D.append(file) D.sort() labelFont = "DejaVu Sans Book"
def main(argv): ########################################### scribus.newDocDialog() if scribus.haveDoc: scribus.setUnit(scribus.UNIT_MILLIMETERS) (w, h) = scribus.getPageSize() ################### # ask for workdir workdir = scribus.fileDialog("Open directory with images", "", haspreview=False, issave=False, isdir=True) #workdir = "/media/sda7/StudioSession3/PDFTools/pics" #workdir = "/media/sda7/ISG/Itex/PhotoVisit/Boilerroom" # file filter filefilter = scribus.valueDialog( "File filter", "File filter examples: \n\n* or *.* = add all files\n*.jpg = add .jpg files only\nIMG_*.* = add all files starting with IMG_\n\nThis filter is case sensitive!", "*.*") # get image paths filelist = sorted(glob.glob(os.path.join(workdir, filefilter))) #scribus.messageBox("Help", str(filelist)) # count files filesinworkdir = len(filelist) #scribus.messageBox("Help", str(filesinworkdir)) #messagebar text scribus.messagebarText("Importing images...") #error if filesinworkdir == 0: scribus.messageBox("Error", "This directory is empty.") sys.exit() # add filename text? addfilenames = scribus.messageBox("Import images", "Files found in workdir : " + str(filesinworkdir) + "\n\nAdd file names to images?", button1=scribus.BUTTON_YES, button2=scribus.BUTTON_NO) #create text layer if addfilenames == 16384: activelayer = scribus.getActiveLayer() scribus.createLayer("Filenames") scribus.setActiveLayer(activelayer) #progressbar max scribus.progressTotal(filesinworkdir) page = 1 #create page, add and load image for i in filelist: scribus.progressSet(page) scribus.gotoPage(page) scribus.createImage(0, 0, w, h, "imagename" + str(page)) scribus.loadImage(filelist[page - 1], "imagename" + str(page)) scribus.setScaleImageToFrame(True, proportional=True, name="imagename" + str(page)) #scribus.setImageOffset(0, 0, "imagename"+str(page)) #scribus.setScaleFrameToImage(name="imagename"+str(page)) # add filename on page? if addfilenames == 16384: scribus.setActiveLayer("Filenames") filename = scribus.createText(2, 2, 50, 10, filelist[page - 1]) scribus.setText(os.path.basename(filelist[page - 1]), filename) scribus.setTextColor("White", filename) scribus.setActiveLayer(activelayer) scribus.newPage(-1) page += 1 #delete last blank page scribus.deletePage(filesinworkdir + 1)
# create a list of items with a brokein link for page_i in range(0, page_n) : scribus.gotoPage(page_i + 1) item_list = scribus.getPageItems() #print(item_list) for item in item_list : if item[1] == 2 : image_filepath = "" image_filepath = scribus.getImageFile(item[0]) print(image_filepath) if image_filepath != "" and not os.path.isfile(image_filepath) : item_missing.append((item[0], image_filepath)) # print(item_missing) # read the link for the first image with a broken link and try to apply the path # to each other image with a broken link if item_missing : if scribus.messageBox("Missing images", "There are missing images. Do you want to look for them?", scribus.ICON_WARNING, scribus.BUTTON_YES, scribus.BUTTON_NO) == scribus.BUTTON_YES: filename_found = scribus.fileDialog("Find "+os.path.basename(item_missing[0][1]), "Image files (*."+os.path.splitext(item_missing[0][1])[1][1:]+")") # print(filename_found) if filename_found: path_found = os.path.dirname(filename_found) # print("path_found "+path_found) for item in item_missing: item_filename = os.path.join(path_found, os.path.basename(item[1])) # print(item_filename) if os.path.isfile(item_filename) : scribus.loadImage(item_filename, item[0])
if (contents in content): contents = 'Duplication, perhaps linked-to frame' T.append(item[0] + ': ' + contents + '\n\n') content.append(contents) elif (item[1] == 2): imgname = scribus.getImageFile(item[0]) T.append(item[0] + ': ' + imgname + '\n') page += 1 T.append('\n') output_file = open(textfile, 'w') output_file.writelines(T) output_file.close() endmessage = textfile + ' was created' scribus.messageBox("Finished", endmessage, scribus.ICON_NONE, scribus.BUTTON_OK) if scribus.haveDoc(): textfile = scribus.fileDialog('Enter name of file to save to', \ filter='Text Files (*.txt);;All Files (*)') try: if textfile == '': raise Exception exportText(textfile) except Exception, e: print e else: scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', \ scribus.ICON_NONE, scribus.BUTTON_OK)
return 50 return 40 if __name__ == "__main__": x = getX(scribus.currentPage()) headerText = scribus.createText(x, 80, 750, 30) headerUnderline = scribus.createLine(x, 110, 160, 110) bodyText = scribus.createText(x, 120, 750, 1030) scribus.setColumns(4, bodyText) scribus.setColumnGap(10, bodyText) if scribus.getObjectType(bodyText) == "TextFrame": fileName = scribus.fileDialog("Open odt file", 'ODT files (*.odt)') text = removeEmptyStrings(parse(fileName)) header = detag(header(text)) body = body(text) scribus.deleteText(bodyText) scribus.insertText(lines(detag(body))[0], -1, bodyText) scribus.setStyle("first_paragraph", bodyText) for p in lines(detag(body))[1:]: scribus.insertText("\n" + p, -1, bodyText) scribus.setStyle("eot", bodyText) for tag in extractModifiers(body): scribus.selectText(tag['start'], tag['length'], bodyText) if tag['tag'] == "bold": scribus.setFont("Mysl Bold Cyrillic", bodyText)
def main(argv): if not scribus.haveDoc(): sys.exit(1) os.chdir(os.path.expanduser("~")) #### #### If you have a different location of your laidout program change it here: #### laidoutexecutable="/usr/bin/laidout" if os.path.exists(laidoutexecutable)==False: laidoutexecutable="/usr/local/bin/laidout" if os.path.exists(laidoutexecutable)==False: print "Could not find Laidout!" print "Please change scribus-call-laidout-to-impose-gui.py to have a correct path!" #scribus.messageBox("Could not find Laidout!", # "Please change line 37 in scribus-call-laidout-to-impose-gui.py to have a correct path!") #laidoutexecutable=scribus.valueDialog("Laidout path","You do not appear to have Laidout installed! Please enter a valid path for running Laidout","/usr/bin/laidout") laidoutexecutable=scribus.fileDialog('Please locate Laidout executable!!', defaultname='/usr/bin/laidout', issave=False) print "New laidout executable path: "+laidoutexecutable #fail if still not found if os.path.exists(laidoutexecutable)==False: scribus.messageBox("Could not find Laidout!", "Please either change line for \'laidoutexecutable=\"/usr/bin/laidout\"\' in scribus-call-laidout-to-impose-gui.py" " to have a correct path, or enter a valid path.") sys.exit(1) thecommand="" infile=os.getcwd()+"/this-is-a-temporary-file.sla" #note this saves to a very random area usually!! reimposed=os.getcwd()+"/this-is-reimposed-from-laidout.sla" # seems like directory of the plugin #infile =tempfile.NamedTemporaryFile() <-- maybe this can be used instead?? how to create, get filename, then let laidout open?? #outfile=tempfile.NamedTemporaryFile() <-- maybe this can be used instead?? size=scribus.getPageSize() units=scribus.getUnit() width=0 height=0 print "size "+str(size[0])+","+str(size[1]) print "units "+str(units) if (units==scribus.UNIT_MILLIMETERS): width=size[0]/10/2.54 height=size[1]/10/2.54 elif (units==scribus.UNIT_PICAS): width=size[0]/6 height=size[1]/6 elif (units==scribus.UNIT_POINTS): width=size[0]/72 height=size[1]/72 elif (units==scribus.UNIT_INCHES): width=size[0] height=size[1] else: print "unknown units!!!" scribus.messageBox("Unknown units!","For some reason, scribus.getUnit() did not return units known to this script!" "This is probably a bug with the script.") #thecommand="/bin/ls" thecommand=laidoutexecutable+" --impose-only " \ +"'in=\""+infile+"\" " \ +" out=\""+reimposed+"\" " \ +" prefer=\"booklet\"" \ +" width=\""+str(width)+"\"" \ +" height=\""+str(height)+"\"" \ +"'" #print "command:\n", thecommand try: print "Creating temporary file ",infile,"..." scribus.saveDocAs(infile) except: print "Could not save as ",infile sys.exit(1) try: print "Trying: "+thecommand os.system(thecommand) except: print "An error occured trying to run the system command:\n",thecommand sys.exit(1) if os.path.exists(reimposed)==False: print "Reimposed file was not generated!" sys.exit(1) #scribus.closeDoc() #closes the "original" document, which has been rename to infile upon saveDocAs() scribus.openDoc(reimposed) #open the brand spanking new reimposed document #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- might cause problems, but keep around for research print "Removing temporary file ",infile,"..." os.remove(infile) print "All done!"
def main(argv): ########################################### info_text = ''' Welcome to Auto-Photobook! 1. Select the process mode: 9f = creates a 9x9 layout on each page and fill them with images. 4f = creates a 4x4 layout on each page and fill them with images. 9e = creates an empty 9x9 layout on each page. 4e = creates an empty 4x4 layout on each page. 9f+4f = creates a filled 9x9 layout on odd pages and a filled 4x4 layout on even pages. 9e+4e = creates an empty 9x9 layout on odd pages and an empty 4x4 layout on even pages. 9f+4e = creates a filled 9x9 layout on odd pages and an empty 4x4 layout on even pages (default). 9e+4f = creates an empty 9x9 layout on odd pages and a filled 4x4 layout on even pages. 2. Select a document layout, the margins (they need to be equal) and the bleed (if needed). Ignore the number of pages. 3. Define the space between the images (default: 6mm). 4a. If "9f" or "4f" is in your mode, you can choose an image folder and an image filter will be prompted. 4b. Otherwise, set the amount of pages you want to create (default: 10 pages). 5. Wait until it is done... 6. Adjust you layouts and move your images as you need. Process mode:''' # start dialog, choose mode #scribus.messageBox("Auto-Photobook", info_text) todo = scribus.valueDialog("Auto-Photobook", info_text, "9f+4e") todo = list(todo.split("+")) # wrong process mode if "9f" not in todo and "9e" not in todo and "4f" not in todo and "9e" not in todo: scribus.messageBox( "Error", "Wrong process mode. Auto-Photobook was cancelled.") sys.exit() # show new document dialog newdoc = scribus.newDocDialog() # exit if cancelled if newdoc == False: scribus.messageBox("Exit", "Auto-Photobook was cancelled.") sys.exit() if scribus.haveDoc: scribus.setUnit(scribus.UNIT_MILLIMETERS) (w, h) = scribus.getPageSize() ################### # delete all pages except the first: pageamount = scribus.pageCount() while pageamount > 1: scribus.deletePage(pageamount) pageamount = scribus.pageCount() # set image border and bleed border = int( scribus.valueDialog("Space between images", "Define the space between the images (mm).", "6")) #border = 6 # reset image border for easier calculations border = border * 0.75 if "9f" in todo or "4f" in todo: # ask for workdir workdir = scribus.fileDialog("Open directory with images", "", haspreview=False, issave=False, isdir=True) #workdir = "/media/sda7/Programming/Python/scribus_auto_photobook/pics" # file filter filefilter = scribus.valueDialog( "File filter", "File filter examples: \n\n* or *.* = add all files\n*.jpg = add .jpg files only\nIMG_*.* = add all files starting with IMG_\n\nThis filter is case sensitive!", "*.*") # get image paths filelist = sorted(glob.glob(os.path.join(workdir, filefilter))) #filelist = sorted(glob.glob(os.path.join(workdir, "*"))) # count files filesinworkdir = len(filelist) scribus.messageBox( "Files in directory", "Images matched in folder: " + str(filesinworkdir)) #error if filesinworkdir == 0: scribus.messageBox("Error", "This directory is empty.") sys.exit() #messagebar text scribus.messagebarText("Importing images...") #progressbar max scribus.progressTotal(filesinworkdir) # set maxpages (not needed here but needs to be assigned) maxpages = len(filelist) else: # ask for page amount maxpages = int( scribus.valueDialog("Set page amount", "How many pages you want to create?", "10")) #progressbar max scribus.progressTotal(maxpages) # get page size (without bleed) size = scribus.getPageSize() # get margins margins = scribus.getPageMargins()[0] # set page final size final_size = (size[0] - margins, size[1] - margins) # simplify calc for 9x9 layout guide_layout_x = final_size[0] / 3 - margins / 3 guide_layout_y = final_size[1] / 3 - margins / 3 # set indexes page = 1 pic = 0 #create pages, add and load images x = True while x == True: scribus.progressSet(page) scribus.gotoPage(page) # create 9x9 layout if "9f" in todo or "9e" in todo: #guides scribus.setVGuides([ margins + guide_layout_x - border, margins + guide_layout_x + border / 2, margins + guide_layout_x * 2 - border / 2, margins + guide_layout_x * 2 + border ]) scribus.setHGuides([ margins + guide_layout_y - border, margins + guide_layout_y + border / 2, margins + guide_layout_y * 2 - border / 2, margins + guide_layout_y * 2 + border ]) # create images scribus.createImage(margins, margins, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image1") scribus.createImage(margins + guide_layout_x + border / 2, margins, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image2") scribus.createImage(margins + guide_layout_x * 2 + border, margins, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image3") scribus.createImage(margins, margins + guide_layout_y + border / 2, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image4") scribus.createImage(margins + guide_layout_x + border / 2, margins + guide_layout_y + border / 2, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image5") scribus.createImage(margins + guide_layout_x * 2 + border, margins + guide_layout_y + border / 2, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image6") scribus.createImage(margins, margins + guide_layout_y * 2 + border, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image7") scribus.createImage(margins + guide_layout_x + border / 2, margins + guide_layout_y * 2 + border, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image8") scribus.createImage(margins + guide_layout_x * 2 + border, margins + guide_layout_y * 2 + border, guide_layout_x + border - border * 2, guide_layout_y - border, "page" + str(page) + "image9") #load and scale images if "9f" in todo: try: scribus.loadImage(filelist[pic], "page" + str(page) + "image1") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image1") scribus.loadImage(filelist[pic + 1], "page" + str(page) + "image2") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image2") scribus.loadImage(filelist[pic + 2], "page" + str(page) + "image3") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image3") scribus.loadImage(filelist[pic + 3], "page" + str(page) + "image4") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image4") scribus.loadImage(filelist[pic + 4], "page" + str(page) + "image5") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image5") scribus.loadImage(filelist[pic + 5], "page" + str(page) + "image6") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image6") scribus.loadImage(filelist[pic + 6], "page" + str(page) + "image7") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image7") scribus.loadImage(filelist[pic + 7], "page" + str(page) + "image8") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image8") scribus.loadImage(filelist[pic + 8], "page" + str(page) + "image9") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image9") except: x = False # increase picture index pic += 9 # add page scribus.newPage(-1) page += 1 # create 4x4 layout if "4f" in todo or "4e" in todo: #guides scribus.setVGuides( [size[0] / 2 - border * 0.75, size[0] / 2 + border * 0.75]) scribus.setHGuides( [size[1] / 2 - border * 0.75, size[1] / 2 + border * 0.75]) # create images scribus.createImage(margins, margins, size[0] / 2 - border * 0.75 - margins, size[1] / 2 - border * 0.75 - margins, "page" + str(page) + "image1") scribus.createImage(size[0] / 2 + border * 0.75, margins, size[0] / 2 - border * 0.75 - margins, size[1] / 2 - border * 0.75 - margins, "page" + str(page) + "image2") scribus.createImage(margins, size[1] / 2 + border * 0.75, size[0] / 2 - border * 0.75 - margins, size[1] / 2 - border * 0.75 - margins, "page" + str(page) + "image3") scribus.createImage(size[0] / 2 + border * 0.75, size[1] / 2 + border * 0.75, size[0] / 2 - border * 0.75 - margins, size[1] / 2 - border * 0.75 - margins, "page" + str(page) + "image4") #load and scale images if "4f" in todo: try: scribus.loadImage(filelist[pic], "page" + str(page) + "image1") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image1") scribus.loadImage(filelist[pic + 1], "page" + str(page) + "image2") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image2") scribus.loadImage(filelist[pic + 2], "page" + str(page) + "image3") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image3") scribus.loadImage(filelist[pic + 3], "page" + str(page) + "image4") scribus.setScaleImageToFrame(True, proportional=True, name="page" + str(page) + "image4") except: x = False # increase picture index pic += 4 # add page scribus.newPage(-1) page += 1 #scribus.setImageOffset(0, 0, "imagename"+str(page)) #scribus.setScaleFrameToImage(name="imagename"+str(page)) # stop if maxpages reached if page > maxpages: x = False #delete last blank page scribus.deletePage(page)
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() # sorted(filenames) filenames.sort()
coord = pr.get_pos(t['time']) tobj = t t['lat'] = coord['lat'] * scale t['lon'] = coord['lon'] * scale objects.append(tobj) objects.sort(key=lambda k: k['lat']) comp = PDFComposerCairo(objects) #count = 1 #h.points.sort(key=lambda k: k['time']) #for p in h.points: #print('%d: %s %s %s'%(count,p['lat'], p['lon'], p['time'])) #count += 1 #count = 1 #for p in ip.images: #print('%d: %s %s [%s]'%(count,p['lat'], p['lon'],p['path'])) #count += 1 try: import scribus idir = scribus.fileDialog('Images directory', isdir=True) ip = ImagesGPSParser(idir) PDFComposerScribus(ip.images, 3000) except ImportError: if __name__ == '__main__': main()
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 # ######################### script = "Aufschlussdoku.py" version = "20140107" csvfile = scribus.fileDialog("csv2table :: open file", "*.csv") fname_ext = csvfile[csvfile.rfind("/") + 1:] fname_noext = fname_ext[:fname_ext.rfind(".")] reader = csv.reader(open(csvfile, "rb"), delimiter=";") boxes = [["strat_d", 2.25], ["strat_n", 2.25], ["strat_b", 6.5], ["strat_p", 2.3], ["strat_a", 3.9]] start_x = float(1.9075) start_y = float(10.5) strats = [] strat_ct = int(0) strat_ok = float(0.0) print getpass.getuser() for line in reader: if line[0].find("Tiefe bis [m]") <> 0: start_x_0 = start_x strat_ct = strat_ct + 1 strat_d = line[0].replace(",", "."); strat_uk = float(strat_d) + float(strat_ok) strat_draw = float(strat_d) * 2.0 strat_uk_draw = start_y + strat_draw if strat_uk_draw > 26.4: nPage = scribus.currentPage() + 1 pageendtext = "Fortsetzung nächste Seite" #print nPage scribus.createText(start_x_0 + 0.1, start_y + 0.1, 17, 0.5, "box_txt_pageend") scribus.sentToLayer("profil_txt", "box_txt_pageend") scribus.setText(pageendtext, "box_txt_pageend") scribus.setStyle("Buchner_sehrklein", "box_txt_pageend") scribus.newPage(-1,"Buchner_Standard") scribus.gotoPage(nPage) start_y = float(5.5) strat_uk_draw = start_y + strat_draw box_nr = int(0) #print strat_uk #print "aktuelle Seite:", scribus.currentPage() #print strat_uk strat_uk_txt = str(strat_uk).replace(".", ","); #print strat_uk_txt strat_h = line[0] strat_n = line[1] strat_b = line[2] strat_p = line[3] strat_a = line[4] strat = [strat_d, strat_uk, strat_h, strat_n, strat_b, strat_p, strat_a] #print strat strats.append(strat) for box in boxes: box_n = box[0] + str(strat_ct) box_txt = strat[box_nr + 2] box_txt_n = box_n + "txt" #print box_nr #print box_txt #print box_n, box_txt_n, dimensions[1], position scribus.createRect(start_x_0, start_y, float(box[1]), strat_draw, box_n) scribus.setLineWidth(0.567, box_n) scribus.sentToLayer("profil_rahmen", box_n) if box_nr == 0: scribus.createText(start_x_0 + 0.1, start_y + (strat_draw) - 0.4, float(box[1]) - 0.2, 0.4, box_txt_n) #print strat_uk_txt scribus.setText(strat_uk_txt, box_txt_n) else: scribus.createText(start_x_0 + 0.1, start_y + 0.1, float(box[1]) - 0.2, (strat_draw) - 0.1, box_txt_n) scribus.setText(box_txt, box_txt_n) scribus.setStyle("Buchner_Standard schmal", box_txt_n) scribus.sentToLayer("profil_txt", box_txt_n) start_x_0 = start_x_0 + float(box[1]) box_nr = box_nr + 1 #print "end: strat count:", strat_ct start_y = strat_uk_draw start_x_0 = start_x strat_ok = strat_ok + float(strat_d) print "end: all" scribus.createText(start_x_0 + 0.1, start_y + 0.1, 17, 0.5, "box_txt_end") scribus.sentToLayer("profil_txt", "box_txt_end") endtext = "Erstellt von " + getpass.getuser() + " mit " + fname_ext + ", " + script + " (V" + version + ")" scribus.setText(endtext, "box_txt_end") scribus.setStyle("Buchner_sehrklein", "box_txt_end") scribus.saveDocAs(fname_noext + ".sla")
if (item[1] == 4): # the item is a text textfile = folder+"/p"+str(page)+"/"+item[0]+".txt" output_file = open(textfile,'w') output_file.writelines(scribus.getAllText(item[0])) output_file.close() page += 1 endmessage = "Text files successfully saved in "+root_folder scribus.messageBox("Finished", endmessage,icon=0,button1=1) if scribus.haveDoc(): folder = scribus.fileDialog(\ 'Select the folder', \ filter='All Files (*)', \ isdir=True) try: if folder == '': raise Exception exportText(folder) except Exception, e: print e else: scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', \ icon=0, button1=1)
class MyHTMLParser(HTMLParser): def handle_data(self, data): global caption_text #print "Data:", data caption_text = caption_text + data # Read the JSON file into a PYTHON dictionary, which is easier to handle class JSONObject: def __init__(self, d): self.__dict__ = d jsonfile = scribus.fileDialog("Select Your JSON File", "*.JSON") imagedir = scribus.fileDialog("Select Your Persistent - Reserved Directory", "Directories", isdir=True) + "/" #jsonfile = "~users~/AppData/Roaming/PhotoGenie X/{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}/Persistent/Files/projects/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.json" #imagedir = "~users~/AppData/Roaming/PhotoGenie X/{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}/Persistent/Reserved/" # if the folder is copied somewhere else, as in temp, and want to run just one album file, for example: #jsonfile = "C:/tmp/Fotoalbum/Persistent/Files/projects/891d2847-fd35-4bb9-a4c8-xxxxxxxxxxxx.json" #imagedir = "C:/tmp/Fotoalbum/Persistent/Reserved/" with open(jsonfile, 'r') as f: albumdata = json.load(f, object_hook=JSONObject) # instantiate the parser and fed it some HTML parser = MyHTMLParser()
# -*- coding: utf-8 -*- # cc-by-sa 4.0 julius # https://wiki.scribus-user.de/ressourcen:scripte#scribus_15-dokumente_in_14x_oeffnen import scribus import os import re slafile = scribus.fileDialog("Please, choose a Scribus document.", "Scribus Documents (*.sla)") filecontent = open(slafile, "r").read() filecontent = filecontent.replace('<SCRIBUSUTF8NEW Version="1.5.', '<SCRIBUSUTF8NEW Version="1.4.') filecontent = filecontent.replace('<DefaultStyle/>', '') filecontent = filecontent.replace('</StoryText>', '') filecontent = filecontent.replace('<StoryText>', '') filecontent = filecontent.replace('</Cell>', ' ') filecontent = filecontent.replace('</TableData>', '') filecontent = filecontent.replace('PTYPE="12"', 'PTYPE="7"') 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")
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): if not scribus.haveDoc(): sys.exit(1) os.chdir(os.path.expanduser("~")) #### #### If you have a different location of your laidout program change it here: #### laidoutexecutable = "/usr/bin/laidout" if os.path.exists(laidoutexecutable) == False: laidoutexecutable = "/usr/local/bin/laidout" if os.path.exists(laidoutexecutable) == False: print "Could not find Laidout!" print "Please change scribus-call-laidout-to-impose-gui.py to have a correct path!" #scribus.messageBox("Could not find Laidout!", # "Please change line 37 in scribus-call-laidout-to-impose-gui.py to have a correct path!") #laidoutexecutable=scribus.valueDialog("Laidout path","You do not appear to have Laidout installed! Please enter a valid path for running Laidout","/usr/bin/laidout") laidoutexecutable = scribus.fileDialog( 'Please locate Laidout executable!!', defaultname='/usr/bin/laidout', issave=False) print "New laidout executable path: " + laidoutexecutable #fail if still not found if os.path.exists(laidoutexecutable) == False: scribus.messageBox( "Could not find Laidout!", "Please either change line for \'laidoutexecutable=\"/usr/bin/laidout\"\' in scribus-call-laidout-to-impose-gui.py" " to have a correct path, or enter a valid path.") sys.exit(1) thecommand = "" infile = os.getcwd( ) + "/this-is-a-temporary-file.sla" #note this saves to a very random area usually!! reimposed = os.getcwd( ) + "/this-is-reimposed-from-laidout.sla" # seems like directory of the plugin #infile =tempfile.NamedTemporaryFile() <-- maybe this can be used instead?? how to create, get filename, then let laidout open?? #outfile=tempfile.NamedTemporaryFile() <-- maybe this can be used instead?? size = scribus.getPageSize() units = scribus.getUnit() width = 0 height = 0 print "size " + str(size[0]) + "," + str(size[1]) print "units " + str(units) if (units == scribus.UNIT_MILLIMETERS): width = size[0] / 10 / 2.54 height = size[1] / 10 / 2.54 elif (units == scribus.UNIT_PICAS): width = size[0] / 6 height = size[1] / 6 elif (units == scribus.UNIT_POINTS): width = size[0] / 72 height = size[1] / 72 elif (units == scribus.UNIT_INCHES): width = size[0] height = size[1] else: print "unknown units!!!" scribus.messageBox( "Unknown units!", "For some reason, scribus.getUnit() did not return units known to this script!" "This is probably a bug with the script.") #thecommand="/bin/ls" thecommand=laidoutexecutable+" --impose-only " \ +"'in=\""+infile+"\" " \ +" out=\""+reimposed+"\" " \ +" prefer=\"booklet\"" \ +" width=\""+str(width)+"\"" \ +" height=\""+str(height)+"\"" \ +"'" #print "command:\n", thecommand try: print "Creating temporary file ", infile, "..." scribus.saveDocAs(infile) except: print "Could not save as ", infile sys.exit(1) try: print "Trying: " + thecommand os.system(thecommand) except: print "An error occured trying to run the system command:\n", thecommand sys.exit(1) if os.path.exists(reimposed) == False: print "Reimposed file was not generated!" sys.exit(1) #scribus.closeDoc() #closes the "original" document, which has been rename to infile upon saveDocAs() scribus.openDoc(reimposed) #open the brand spanking new reimposed document #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- might cause problems, but keep around for research print "Removing temporary file ", infile, "..." os.remove(infile) print "All done!"
filetype = [] dicttype = {'j':'.jpg','p':'.png','t':'.tif','g':'.gif','P':'.pdf'} Dicttype = {'j':'.JPG','p':'.PNG','t':'.TIF','g':'.GIF','P':'.PDF'} nrimages = '0' # Ask which document size docWidth = float(scribus.valueDialog(docWidthStr1,docWidthStr2,defaultDocWidth)) docHeight = float(scribus.valueDialog(docHeightStr1,docHeightStr2,defaultDocHeight)) # Generate grids numColumns = int(scribus.valueDialog(numColStr1, numColStr2, defaultNumColumns)) numRows = int(scribus.valueDialog(numLinStr1, numLinStr2, defaultNumRows)) gap = float(scribus.valueDialog(gapStr1, gapStr2, defaultGap)) nbrimages = numColumns*numRows imagedir = scribus.fileDialog('Select your pictures folder','Folders',isdir=True) imagetype = scribus.valueDialog('Pictures types','Enter pictures types: j=jpg,p=png,t=tif,g=gif,P=pdf\n "jptgP" selects all','jptgP') for t in imagetype[0:]: filetype.append(dicttype[t]) filetype.append(Dicttype[t]) d = os.listdir(imagedir) D = [] for file in d: for format in filetype: if file.endswith(format): D.append(file) D.sort() imagecount = 0 #framecount = 0
def getFile(caption, filter, defaultname, issave): file = scribus.fileDialog(caption, filter, defaultname, issave) if len(file) == 0: raise UserCanceled("canceled") else: return file
nrimages = '0' # Ask which document size docWidth = float( scribus.valueDialog(docWidthStr1, docWidthStr2, defaultDocWidth)) docHeight = float( scribus.valueDialog(docHeightStr1, docHeightStr2, defaultDocHeight)) # Generate grids numColumns = int(scribus.valueDialog(numColStr1, numColStr2, defaultNumColumns)) numRows = int(scribus.valueDialog(numLinStr1, numLinStr2, defaultNumRows)) gap = float(scribus.valueDialog(gapStr1, gapStr2, defaultGap)) nbrimages = numColumns * numRows imagedir = scribus.fileDialog('Selectionnez un dossier d\'images', 'Dossiers', isdir=True) imagetype = scribus.valueDialog( 'Types d\'images', 'Entrez les types d\'images:\n j=jpg,p=png,t=tif,g=gif,P=pdf\n "jptgP" selects all', 'jptgP') for t in imagetype[0:]: filetype.append(dicttype[t]) filetype.append(Dicttype[t]) d = os.listdir(imagedir) D = [] for file in d: for format in filetype: if file.endswith(format): D.append(file) D.sort()
if item[1] == 2: image_filepath = "" image_filepath = scribus.getImageFile(item[0]) print(image_filepath) if image_filepath != "" and not os.path.isfile(image_filepath): item_missing.append((item[0], image_filepath)) # print(item_missing) # read the link for the first image with a broken link and try to apply the path # to each other image with a broken link if item_missing: if scribus.messageBox( "Missing images", "There are missing images. Do you want to look for them?", scribus.ICON_WARNING, scribus.BUTTON_YES, scribus.BUTTON_NO) == scribus.BUTTON_YES: filename_found = scribus.fileDialog( "Find " + os.path.basename(item_missing[0][1]), "Image files (*." + os.path.splitext(item_missing[0][1])[1][1:] + ")") # print(filename_found) if filename_found: path_found = os.path.dirname(filename_found) # print("path_found "+path_found) for item in item_missing: item_filename = os.path.join(path_found, os.path.basename(item[1])) # print(item_filename) if os.path.isfile(item_filename): scribus.loadImage(item_filename, item[0])
contents = scribus.getAllText(item[0]) if (contents in content): contents = 'Duplication, perhaps linked-to frame' T.append(item[0]+': '+ contents + '\n\n') content.append(contents) elif (item[1] == 2): imgname = scribus.getImageFile(item[0]) T.append(item[0]+': ' + imgname + '\n') page += 1 T.append('\n') output_file = open(textfile,'w') output_file.writelines(T) output_file.close() endmessage = textfile + ' was created' scribus.messageBox("Finished", endmessage,icon=0,button1=1) if scribus.haveDoc(): textfile = scribus.fileDialog('Enter name of file to save to', \ filter='Text Files (*.txt);;All Files (*)') try: if textfile == '': raise Exception exportText(textfile) except Exception, e: print e else: scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', \ icon=0, button1=1)
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() # sorted(filenames) filenames.sort()