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 add_image(f): global page_size, page_margins_right, max_width, max_width_px, max_height, max_height_px try: im = Image.open(f) except: return False scribus.messagebarText("Adding " + f) ## # determine best frame width ## w, h = im.size print "image: %s x %s px" % (w, h) # find the scale coeff coeff = 1 # FIXME: cas où image aussi large que haute mais page en portrait if w > h: # scale on width if w >= max_width_px: coeff = max_width_px / w else: # scale on height if h >= max_height_px: coeff = max_height_px / h print "coeff:", coeff # scaling and conversion to mm frameW = int(((coeff * w) / min_ppi) * 25.4) frameH = int(((coeff * h) / min_ppi) * 25.4) print "frame: %s x %s mm" % (frameW, frameH) # center frame frameX = get_page_margins()[1] + (max_width - frameW) / 2 frameY = get_page_margins()[0] + (max_height - frameH) / 2 frame = scribus.createImage(frameX, frameY, frameW, frameH) scribus.loadImage(f, frame) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=frame) return True
def add_image(f): global page_size, page_margins_right, max_width, max_width_px, max_height, max_height_px try: im = Image.open(f) except: return False scribus.messagebarText("Adding " + f) ## # determine best frame width ## w, h = im.size print 'image: %s x %s px' % (w, h) # find the scale coeff coeff = 1 # FIXME: cas où image aussi large que haute mais page en portrait if w > h: # scale on width if w >= max_width_px: coeff = max_width_px / w else: # scale on height if h >= max_height_px: coeff = max_height_px / h print 'coeff:', coeff # scaling and conversion to mm frameW = int(((coeff * w) / min_ppi) * 25.4) frameH = int(((coeff * h) / min_ppi) * 25.4) print 'frame: %s x %s mm' % (frameW, frameH) # center frame frameX = get_page_margins()[1] + (max_width - frameW) / 2 frameY = get_page_margins()[0] + (max_height - frameH) / 2 frame = scribus.createImage(frameX, frameY, frameW, frameH) scribus.loadImage(f, frame) scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=frame) return True
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)
] button = scribus.messageBox( 'Confirmation', 'You should only scramble a copy of your document', scribus.ICON_WARNING, scribus.BUTTON_OK, scribus.BUTTON_CANCEL) print button if button == scribus.BUTTON_CANCEL: sys.exit(2) selectedFrame = [] textFrame = [] imageFrame = [] if scribus.selectionCount() == 0: for page in range(scribus.pageCount()): scribus.gotoPage(page + 1) scribus.messagebarText("Processing Page " + str(page)) scribus.redrawAll() for item in scribus.getPageItems(): if (item[1] == 4): textFrame.append(item[0]) elif (item[1] == 2): imageFrame.append(item[0]) else: for i in range(scribus.selectionCount()): item = scribus.getSelectedObject(i) selectedFrame.append(item) if scribus.getObjectType(item) == "TextFrame": textFrame.append(item) if scribus.getObjectType(item) == "ImageFrame": imageFrame.append(item[0])
# - get the directory with all images # - on the first page where you want the image create an image frame of the right size # - select the empty image frame # - run the script # - the script copies the frame, then loads the first image in the exiting frame # - then on other following pages paste the emtpy frame and load the next image # - if there are not enough pages, create them to put all the images in the directory import os import sys import scribus if not scribus.haveDoc(): scribus.messagebarText("No .") sys.exit() if scribus.selectionCount() == 0: scribus.messagebarText("No frame selected.") sys.exit() if scribus.selectionCount() > 1: scribus.messagebarText("Please select one single frame.") sys.exit() master_frame = scribus.getSelectedObject() x,y = scribus.getPosition() width, height = scribus.getSize() path = scribus.fileDialog("Pick a directory", scribus.getDocName(), isdir = True) if path == '':
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)
if not os.path.exists(baseDirName): os.makedirs(baseDirName) else: for the_file in os.listdir(baseDirName): file_path = os.path.join(baseDirName, the_file) try: if os.path.isfile(file_path): os.unlink(file_path) except Exception, e: print e #Make Document Temporary scribus.saveDoc() scribus.saveDocAs(tmpFileName) scribus.messagebarText("Dokument in Bearbeitung, bitte warten") scribus.closeDoc() scribus.messagebarText("Dokument in Bearbeitung, bitte warten") scribus.openDoc(tmpFileName) scribus.selectText(0, 1, idtextstring) idfont = scribus.getFont(idtextstring) idfonSize = scribus.getFontSize(idtextstring) idtextcolor = scribus.getTextColor(idtextstring) idtextshade = scribus.getTextShade(idtextstring) scribus.selectText(0, 1, gertextstring) gerfont = scribus.getFont(gertextstring) gerfonSize = scribus.getFontSize(gertextstring) gertextcolor = scribus.getTextColor(gertextstring)
def main(): colstotal = get_multipl(WIDTH, CARDWIDTH, MARGINS[0], MARGINS[1]) rowstotal = get_multipl(HEIGHT, CARDHEIGHT, MARGINS[2], MARGINS[3]) # create a new document t = scribus.newDocument( (WIDTH, HEIGHT), MARGINS, scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT, 1, ) cr = 1 cc = 1 nol = 0 # ask for CSV infos tstr = scribus.valueDialog( 'Cvs Delimiter, Quote and Column to process', 'Type 1 delimiter, 1 quote character ' 'and the column number (Clear for default ,"0):', ';"0', ) if len(tstr) > 0: delim = tstr[0] else: delim = ',' if len(tstr) > 1: qc = tstr[1] else: qc = '"' if len(tstr) > 2: numcol = int(tstr[2]) else: numcol = 0 # select black or white cards color = scribus.valueDialog( 'Color of the cards :', 'black (b) or white (w)', 'w', ) if len(color) > 0 and 'b' == color[0]: is_black = True else: is_black = False # open CSV file data = getCSVdata(delim=delim, qc=qc) # Process data scribus.messagebarText("Processing " + str(nol) + " elements") scribus.progressTotal(len(data)) for row in data: scribus.messagebarText("Processing " + str(nol) + " elements") celltext = row[numcol].strip() if len(celltext) != 0: createCell( celltext, cr, cc, CARDWIDTH, CARDHEIGHT, MARGINS[0], MARGINS[2], is_black, ) nol = nol + 1 if cr == colstotal and cc == rowstotal: #create new page scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) cr = 1 cc = 1 else: if cr == colstotal: cr = 1 cc = cc + 1 else: cr = cr + 1 scribus.progressSet(nol) scribus.messagebarText("Processed " + str(nol) + " items. ") # open CSV file data = getCSVdata(delim=delim, qc=qc) # Process data scribus.messagebarText("Processing " + str(nol) + " elements") scribus.progressReset() scribus.progressTotal(len(data)) nol = 0 cr = 1 cc = cc + 2 for row in data: scribus.messagebarText("Processing " + str(nol) + " elements") celltext = row[numcol].strip() if len(celltext) != 0: createCell( celltext, cr, cc, CARDWIDTH, CARDHEIGHT, MARGINS[0], MARGINS[2], is_black=True, ) nol = nol + 1 if cr == colstotal and cc == rowstotal: #create new page scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) cr = 1 cc = 1 else: if cr == colstotal: cr = 1 cc = cc + 1 else: cr = cr + 1 scribus.progressSet(nol) scribus.messagebarText("Processed " + str(nol) + " items. ") scribus.progressReset()
# - in a document add empty image frames # - all empty image frames will be filled with the images collected import os import sys import scribus if not scribus.haveDoc(): scribus.messagebarText("No .") sys.exit() def get_all_images(path): extensions = ['jpg', 'jpeg', 'JPG', 'png', 'PNG', 'tif', 'TIF'] filenames = [ f for f in os.listdir(path) if any( f.endswith(ext) for ext in extensions) ] filenames.sort() return filenames def get_all_empty_images_frames(): image_frames = [] for page in range(1, scribus.pageCount() + 1): page_image_frames = [] scribus.gotoPage(page) # get all empty image frames on the page for item in scribus.getPageItems(): if item[1] == 2: if scribus.getImageFile(item[0]) == "": x, y = scribus.getPosition(item[0])
You must have a document open. WARNING: this script irreversibly scrambles your text on all pages. You would be wise to work on a copy of the original to avoid accidentally saving this scrambled version only to lose the original. """ import scribus import random if scribus.haveDoc(): c = 0 else: scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1) sys.exit(2) scribus.messagebarText("Getting ready to process Page 1") # a bit kludgey maybe, but gives an initial message about Page 1 scribus.redrawAll() warnresult = scribus.valueDialog('Warning!', 'This script is going to irreversibly alter the text in your document.\nChange this default value to abort', 'Ok!') if (warnresult != 'Ok!'): sys.exit(2) page = 1 pagenum = scribus.pageCount() while (page <= pagenum): scribus.gotoPage(page) scribus.messagebarText("Processing Page "+str(page)) # New Feature! - sends a message to message bar scribus.redrawAll() # this allows the message to show pageitems = scribus.getPageItems()
""" import scribus import random if scribus.haveDoc(): c = 0 else: scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1) sys.exit(2) scribus.messagebarText( "Getting ready to process Page 1" ) # a bit kludgey maybe, but gives an initial message about Page 1 scribus.redrawAll() warnresult = scribus.valueDialog( 'Warning!', 'This script is going to irreversibly alter the text in your document.\nChange this default value to abort', 'Ok!') if (warnresult != 'Ok!'): sys.exit(2) page = 1 pagenum = scribus.pageCount() while (page <= pagenum): scribus.gotoPage(page)
sys.exit(2) charsIgnore = ["-", "–", "", " ", ".", ":", ";", ";", "?", "!", "\n", "'", "‘", "’", "," "\"", "“", "”", "\r"] button = scribus.messageBox('Confirmation', 'You should only scramble a copy of your document', scribus.ICON_WARNING, scribus.BUTTON_OK, scribus.BUTTON_CANCEL) print button if button == scribus.BUTTON_CANCEL : sys.exit(2) selectedFrame = [] textFrame = [] imageFrame = [] if scribus.selectionCount() == 0: for page in range(scribus.pageCount()) : scribus.gotoPage(page + 1) scribus.messagebarText("Processing Page "+str(page)) scribus.redrawAll() for item in scribus.getPageItems() : if (item[1] == 4): textFrame.append(item[0]) elif (item[1] == 2) : imageFrame.append(item[0]) else : for i in range(scribus.selectionCount()) : item = scribus.getSelectedObject(i) selectedFrame.append(item) if scribus.getObjectType(item) == "TextFrame" : textFrame.append(item) if scribus.getObjectType(item) == "ImageFrame" : imageFrame.append(item[0])
if len(tstr) > 1: qc=tstr[1] else: qc='"' if len(tstr) > 2: numcol=int(tstr[2]) else: numcol=0 # select black or white cards color=scribus.valueDialog('Color of the cards :','black (b) or white (w)','w') if len(color) > 0 and 'b'==color[0]: isBlack=True else: isBlack=False # open CSV file data = getCSVdata(delim=delim, qc=qc) # Process data scribus.messagebarText("Processing "+str(nol)+" elements") scribus.progressTotal(len(data)) for row in data: scribus.messagebarText("Processing "+str(nol)+" elements") celltext = row[numcol].strip() if len(celltext)!=0: createCell(celltext, cr, cc, CARDWIDTH, CARDHEIGHT, MARGINS[0], MARGINS[2], isBlack) nol=nol+1 if cr==colstotal and cc==rowstotal: #create new page scribus.newPage(-1) scribus.gotoPage(scribus.pageCount()) cr=1 cc=1 else: if cr==colstotal:
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)
# - get the directory with all images # - on the first page where you want the image create an image frame of the right size # - select the empty image frame # - run the script # - the script copies the frame, then loads the first image in the exiting frame # - then on other following pages paste the emtpy frame and load the next image # - if there are not enough pages, create them to put all the images in the directory # # 1.5 only, since it uses copy/paste of objects # it's untested. import os import sys import scribus if not scribus.haveDoc(): scribus.messagebarText("No .") sys.exit() path = "/tmp/t/lot_forum" 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() page = 1 n_pages = scribus.pageCount() scribus.copyObject()
# - get the directory with all images # - on the first page where you want the image create an image frame of the right size # - select the empty image frame # - run the script # - the script copies the frame, then loads the first image in the exiting frame # - then on other following pages paste the emtpy frame and load the next image # - if there are not enough pages, create them to put all the images in the directory import os import sys import scribus if not scribus.haveDoc(): scribus.messagebarText("No .") sys.exit() if scribus.selectionCount() == 0: scribus.messagebarText("No frame selected.") sys.exit() if scribus.selectionCount() > 1: scribus.messagebarText("Please select one single frame.") sys.exit() master_frame = scribus.getSelectedObject() x, y = scribus.getPosition() width, height = scribus.getSize() path = scribus.fileDialog("Pick a directory", scribus.getDocName(), isdir=True) if path == '': scribus.messagebarText("No directory selected.")
def main(argv): scribus.setUnit(scribus.UNIT_MILLIMETERS) # get page size and page count pagesize = scribus.getPageSize() pagenum = scribus.pageCount() #create on page selectedpage = scribus.valueDialog( "Select page", "Create arrows and annotation links on page (1-" + str(pagenum) + ") :", "1") # get active layer, create new layer for exit buttons, set it as active #activelayer = scribus.getActiveLayer() scribus.createLayer("Arrowlinks") scribus.setActiveLayer("Arrowlinks") #progressbar max scribus.progressTotal(pagenum) arrowinitxpos = 10 arrowinitypos = 30 scribus.gotoPage(int(selectedpage)) page = 1 ########################################### for i in range(pagenum): # create rectangle #exitrect = scribus.createRect(arrowinitxpos, 50, 30, 30, "exitrect") #messagebar text scribus.messagebarText( "Creating arrows and annotation links on page " + selectedpage + "...") #progress bar scribus.progressSet(page) #create and distribute arrow arrowpoly = [ 10, 30, 30, 10, 50, 30, 40, 30, 40, 50, 20, 50, 20, 30, 10, 30 ] arrowup = scribus.createPolygon(arrowpoly) scribus.sizeObject(10, 10, arrowup) scribus.moveObjectAbs(arrowinitxpos, arrowinitypos, arrowup) scribus.setFillColor("White", arrowup) #create and distribute links arrowlink = scribus.createText(arrowinitxpos, arrowinitypos + 11, 10, 10, "link_to_page_" + str(page)) #setLinkAnnotation(page,x,y,["name"]) scribus.setLinkAnnotation(int(page), 0, 0, arrowlink) arrowinitxpos += 11 if arrowinitxpos > 250: arrowinitypos += 24 arrowinitxpos = 10 # add page number to iteration page += 1