Exemple #1
0
 def pasteImage(self, src, xpos, ypos, width, height, rotate=False):
    img = scribus.createImage(xpos, ypos, width, height)
    scribus.loadImage(src, img)
    scribus.setScaleImageToFrame(True,True,img)    
    scribus.textFlowMode(img, 1)
    if src[-3:] == "jpg":
       scribus.setLineColor("Black",img)
       scribus.setLineWidth(0.2,img)
    #scribus.setLineShade(50,img)
    if rotate:
       scribus.rotateObject(90,img)
    #scribus.setCornerRadius(ROUNDS,img)
    self.imageframes.append(img)
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
Exemple #3
0
def placerandom(iteration):
	for i in range(iteration):
		imagedir = "./elements/"
		random_x = random.randint(-20,int(document_width))
		random_y = random.randint(-20,int(document_height))
		randomsize_x = random.randint(30,50)

		circles = scribus.createImage(random_x, random_y, randomsize_x,randomsize_x)
		scribus.loadImage(imagedir + "ubuntu_circle.png", circles)
		scribus.setScaleImageToFrame(1,1,circles)

		random_degree = random.randint(0,180)
		scribus.rotateObject(random_degree, circles)

		scribus.sentToLayer("randomcircles", circles)
    def alignImage(self):
        if scribus.haveDoc():
	    restore_units = scribus.getUnit()   # since there is an issue with units other than points,
	    scribus.setUnit(0)			# we switch to points then restore later.
            nbrSelected = scribus.selectionCount()
            objList = []
            for i in range(nbrSelected):
                objList.append(scribus.getSelectedObject(i))
            scribus.deselectAll()
            for i in range(nbrSelected):
                try:
                    obj = objList[i]
                    scribus.selectObject(obj)
                    frameW, frameH = scribus.getSize(obj)
                    saveScaleX, saveScaleY = scribus.getImageScale(obj)
                    scribus.setScaleImageToFrame(1, 0, obj)
                    fullScaleX, fullScaleY = scribus.getImageScale(obj)
                    scribus.setScaleImageToFrame(0, 0, obj)
                    scribus.setImageScale(saveScaleX, saveScaleY, obj)
                    imageW = frameW * (saveScaleX / fullScaleX)
                    imageH = frameH * (saveScaleY / fullScaleY)
                    imageX = 0.0
                    imageY = 0.0
 
                    if self.alignVar.get()[0] == "T":
                        imageY = 0.0
                    elif self.alignVar.get()[0] == "M":
                        imageY = (frameH - imageH) / 2.0
                    elif self.alignVar.get()[0] == "B":
                        imageY = (frameH - imageH)
                    if self.alignVar.get()[1] == "L":
                        imageX = 0.0
                    elif self.alignVar.get()[1] == "C":
                        imageX = (frameW - imageW) / 2.0
                    elif self.alignVar.get()[1] == "R":
                        imageX = (frameW - imageW)
 
                    scribus.setImageOffset(imageX, imageY, obj)
                    scribus.docChanged(1)
                    scribus.setRedraw(True)
                    scribus.deselectAll()
                except:
                    nothing = "nothing"
	    scribus.setUnit(restore_units)
	    
	    self.master.destroy()
Exemple #5
0
def placerandom_bars(iteration):
	for i in range(iteration):
		imagedir = "./elements/"
		random_x = random.randint(0,int(document_width))
		random_y = random.randint(0,int(document_height))
		randomsize_x = random.randint(100,105)
		randomsize_y = random.randint(50,50)
	
		bars = scribus.createImage(random_x, random_y, randomsize_x, randomsize_y)
		scribus.loadImage(imagedir + "ubuntu_bar.png", bars)
		scribus.setScaleImageToFrame(1,1,bars)
	
		i = random.randint(0,2)
		if i == 0:
			random_degree = 0
		elif i == 1:
			random_degree = 120
		elif i == 2:
			random_degree = 240	

		scribus.rotateObject(random_degree, bars)
		scribus.sentToLayer("randombars", bars)
    def slotOkClicked(self):
        global CWD

        text = self.text.text()
        preamble = self.preamble.text()
        scale = self.scale.value()
        CWD = self.cwd.text()

        DPI = 600.0
        os.chdir(CWD)

        try:
            img = scribus.getSelectedObject()
            scribus.getImageFile(img)
        except scribus.NoValidObjectError:
            img = self.get_new_image_name()
            scribus.createImage(0, 0, 10, 10, img)

        img_file = os.path.abspath('%s.png' % img)
        self.generate_latex(text, preamble, scale, img_file, DPI*scale)

        info = open(img_file + '.info', 'w')
        info.write("%s\n" % preamble)
        info.write("%g\n" % scale)
        info.write(text)
        info.close()

        x = Image.open(img_file, 'r')
        w, h = x.size
        del x

        scribus.setUnit(scribus.UNIT_MILLIMETERS)
        scribus.loadImage(img_file, img)
        scribus.setScaleImageToFrame(True, True, img)
        x, y = scribus.getPosition(img)
        scribus.sizeObject(x + w*25.4/DPI, y + h*25.4/DPI, img)
        
        self.accept()
Exemple #7
0
 def placeGuide(self, rock, sun, walk, graph, iconpath):
    """Build the header section of a guide"""
    if self.frame != None:
       (w,h) = scribus.getSize(self.frame)
       scribus.sizeObject(w, h + HEADERSIZE, self.frame)
          
       if os.path.exists(graph):
          img = scribus.createImage(self.leftmargin + 5, self.topmargin + 10, GRAPHSIZE, GRAPHSIZE)
          scribus.loadImage(graph, img)
          scribus.setScaleImageToFrame(True,True,img)    
                   
       offset = 13
       iconleft = self.leftmargin + 10 + GRAPHSIZE + 3
       txtleft = iconleft + ICONSIZE + 3
       framewidth = self.pagewidth - self.leftmargin - self.rightmargin
       if sun != "":
          img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE)
          scribus.loadImage(iconpath + os.sep + "sun1.png", img)
          scribus.setScaleImageToFrame(True,True,img)
          #scribus.setCornerRadius(ROUNDS,img)
          icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE)
          self.styleText(sun, "IconText", icontxtframe)
          offset = offset + ICONSIZE + 3
             
       if walk != "":
          img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE)
          scribus.loadImage(iconpath + os.sep + "walk1.png", img)
          scribus.setScaleImageToFrame(True,True,img)    
          #scribus.setCornerRadius(ROUNDS,img)
          icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE)
          self.styleText(walk, "IconText", icontxtframe)
          offset = offset + ICONSIZE + 3
                
       if rock != "":
          img = scribus.createImage(iconleft, self.topmargin + offset, ICONSIZE, ICONSIZE)
          scribus.loadImage(iconpath + os.sep + "rock1.png", img)
          scribus.setScaleImageToFrame(True,True,img)    
          #scribus.setCornerRadius(ROUNDS,img)
          icontxtframe = scribus.createText(txtleft, self.topmargin + offset + 2, framewidth - txtleft, ICONSIZE)
          self.styleText(rock, "IconText", icontxtframe)
          offset = offset + ICONSIZE + 3
    self.endFrame()
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)
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()

scribus.loadImage(filenames[0])
filenames = filenames[1:]

page = scribus.currentPage() + 1
n_pages = scribus.pageCount()

for filename in filenames:
    print(filename)
    if page <= n_pages:
        scribus.gotoPage(page)
    else:
        # TODO: currently this does not work if the names of the default master pages
        # are not in the language of the GUI.
        # if it's the case you need to create all pages before loading the images.
        scribus.newPage(-1)
        scribus.gotoPage(scribus.pageCount())
    new_image = scribus.createImage(x, y, width, height)
    scribus.setScaleImageToFrame(True, True, new_image)
    scribus.loadImage(filename, new_image)
    page += 1
Exemple #10
0
    def main(self):

        # Load up all the file and record information.
        # Use CSV reader to build list of record dicts
        records = self.loadCSVData(self.dataFile)
        totalRecs = len(records)

        # Reality check first to see if we have anything to process
        if totalRecs <= 0:
            scribus.messageBox('Not Found', 'No records found to process!')
            sys.exit()

        pageNumber = 1
        recCount = 0
        row = 0
        pageSide = 'Odd'
        scribus.progressTotal(totalRecs)
        paIndex = {}
        lastName = ''
        firstName = ''
        photoFirstName = ''
        verseRef = ''
        verseText = ''

        # Get the page layout coordinates for this publication
        crds = self.getCoordinates(self.dimensions)

        # Make a new document to put our records on
        if scribus.newDocument(
                getattr(scribus, self.dimensions['page']['scribusPageCode']),
            (self.dimensions['margins']['left'],
             self.dimensions['margins']['right'],
             self.dimensions['margins']['top'],
             self.dimensions['margins']['bottom']), scribus.PORTRAIT, 1,
                scribus.UNIT_POINTS, scribus.NOFACINGPAGES,
                scribus.FIRSTPAGERIGHT, 1):

            self.setPageNumber(crds, pageSide, row, pageNumber)

            while recCount < totalRecs:

                # Output a new page on the first row after we have done the first page
                if row == 0 and recCount != 0:
                    scribus.newPage(-1)
                    if pageSide == 'Odd':
                        pageSide = 'Even'
                    else:
                        pageSide = 'Odd'

                    self.setPageNumber(crds, pageSide, row, pageNumber)

                ########### Now set the current record in the current row ##########

                # Set the last name
                lastName = records[recCount]['NameLast']

                # Adjust the NameFirst field to include the spouse if there is one
                if records[recCount]['Spouse'] != '':
                    firstName = records[recCount][
                        'NameFirst'] + ' & ' + records[recCount]['Spouse']
                else:
                    firstName = records[recCount]['NameFirst']

                # Make the photo file name
                photoFirstName = firstName.replace('&', '-').replace(
                    '.', '').replace(' ', '')

                # Set our record count for progress display and send a status message
                scribus.progressSet(recCount)
                scribus.statusMessage('Placing record ' + ` recCount ` +
                                      ' of ' + ` totalRecs `)

                # Add a watermark if a string is specified
                if self.outputWatermark:
                    self.addWatermark()

                # Put the last name element in this row
                nameLastBox = scribus.createText(crds[row]['nameLastXPos'],
                                                 crds[row]['nameLastYPos'],
                                                 crds[row]['nameLastWidth'],
                                                 crds[row]['nameLastHeight'])
                scribus.setText(lastName, nameLastBox)
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, nameLastBox)
                scribus.setTextDistances(0, 0, 0, 0, nameLastBox)
                scribus.setFont(self.fonts['nameLast']['bold'], nameLastBox)
                scribus.setFontSize(self.fonts['nameLast']['size'],
                                    nameLastBox)
                scribus.setTextShade(80, nameLastBox)
                scribus.rotateObject(90, nameLastBox)

                # Place the first name element in this row
                nameFirstBox = scribus.createText(crds[row]['nameFirstXPos'],
                                                  crds[row]['nameFirstYPos'],
                                                  crds[row]['nameFirstWidth'],
                                                  crds[row]['nameFirstHeight'])
                scribus.setText(records[recCount]['Caption'], nameFirstBox)
                scribus.setTextAlignment(scribus.ALIGN_LEFT, nameFirstBox)
                scribus.setFont(self.fonts['nameFirst']['boldItalic'],
                                nameFirstBox)
                scribus.setFontSize(self.fonts['nameFirst']['size'],
                                    nameFirstBox)

                # Place the image element in this row
                # We will need to do some processing on the first pass
                # The default output format is JPG
                orgImgFileName = records[recCount]['Photo']
                orgImgFile = os.path.join(self.orgImgDir, orgImgFileName)
                baseImgFileName = lastName + '_' + photoFirstName
                if self.willBePngImg:
                    ext = 'png'
                else:
                    ext = 'jpg'
                if not self.rgbColor:
                    imgFile = os.path.join(
                        getattr(self, ext + 'ImgDir'),
                        baseImgFileName + '-gray' + '.' + ext)
                else:
                    imgFile = os.path.join(getattr(self, ext + 'ImgDir'),
                                           baseImgFileName + '.' + ext)

                # Process the image now if there is none
                if not os.path.exists(imgFile):
                    self.img_process.sizePic(orgImgFile, imgFile,
                                             self.maxHeight)
                    #                    self.img_process.outlinePic(imgFile, imgFile)
                    self.img_process.scalePic(imgFile, imgFile,
                                              self.imgDensity)
                    self.img_process.addPoloroidBorder(imgFile, imgFile)
                    # Color RGB is the default
                    if not self.rgbColor:
                        self.img_process.makeGray(imgFile, imgFile)

                # Double check the output and substitute with placeholder pic
                if not os.path.exists(imgFile):
                    imgFile = self.placeholderPic
                # Create the imageBox and load the picture
                imageBox = scribus.createImage(crds[row]['imageXPos'],
                                               crds[row]['imageYPos'],
                                               crds[row]['imageWidth'],
                                               crds[row]['imageHeight'])
                if os.path.isfile(imgFile):
                    scribus.loadImage(imgFile, imageBox)
                scribus.setScaleImageToFrame(scaletoframe=1,
                                             proportional=1,
                                             name=imageBox)

                # Place the country element in this row (add second one if present)
                countryBox = scribus.createText(crds[row]['countryXPos'],
                                                crds[row]['countryYPos'],
                                                crds[row]['countryWidth'],
                                                crds[row]['countryHeight'])
                countryLine = records[recCount]['Country1']
                try:
                    if records[recCount]['Country2'] != '':
                        countryLine = countryLine + ' & ' + records[recCount][
                            'Country2']
                except:
                    pass
                scribus.setText(countryLine, countryBox)
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, countryBox)
                scribus.setFont(self.fonts['text']['boldItalic'], countryBox)
                scribus.setFontSize(self.fonts['text']['size'], countryBox)

                # Place the assignment element in this row
                assignBox = scribus.createText(crds[row]['assignXPos'],
                                               crds[row]['assignYPos'],
                                               crds[row]['assignWidth'],
                                               crds[row]['assignHeight'])
                scribus.setText(self.fixText(records[recCount]['Assignment']),
                                assignBox)
                # Assign style to box
                #                scribus.createParagraphStyle(name='assignStyle', alignment=0, leftmargin=10, firstindent=-10)
                #                scribus.setStyle('assignStyle', assignBox)
                # Hard formated box
                scribus.setTextAlignment(scribus.ALIGN_LEFT, assignBox)
                scribus.setFont(self.fonts['text']['italic'], assignBox)
                scribus.setFontSize(self.fonts['text']['size'], assignBox)
                scribus.setLineSpacing(self.fonts['text']['size'] + 1,
                                       assignBox)
                scribus.setTextDistances(4, 0, 0, 0, assignBox)
                # Resize the frame height and determine the difference for
                # placing the next frame below it
                assignHeightNew = self.resizeFrame(assignBox)
                assignHeightDiff = crds[row]['assignHeight'] - assignHeightNew

                # Place the verse element in this row
                verseYPosNew = crds[row]['verseYPos'] - assignHeightDiff
                verseBox = scribus.createText(crds[row]['verseXPos'],
                                              verseYPosNew,
                                              crds[row]['verseWidth'],
                                              crds[row]['verseHeight'])
                # The verse element may be either a Scripture verse or a prayer request
                # If it is Scripture, and it has a verse ref, we want to set that
                # seperatly so we need to do a little preprocess on the text to find
                # out if it has a ref. This script will only recognize references
                # at the end of the string that are enclosed in brackets. See the
                # findVerseRef() function for more details
                verseRef = self.findVerseRef(records[recCount]['Prayer'])
                if verseRef:
                    verseText = self.removeVerseRef(
                        self.fixText(records[recCount]['Prayer']))
                    scribus.setText(verseText, verseBox)
                else:
                    scribus.setText(self.fixText(records[recCount]['Prayer']),
                                    verseBox)
                # Can't find a way to set alignment to justified using setTextAlignment()
#                scribus.setTextAlignment(scribus.ALIGN_LEFT, verseBox)
# Because of this, we make a style which seems to work
                scribus.createParagraphStyle(name='vBoxStyle', alignment=3)
                scribus.setStyle('vBoxStyle', verseBox)
                scribus.setFont(self.fonts['verse']['regular'], verseBox)
                scribus.setFontSize(self.fonts['verse']['size'], verseBox)
                scribus.setLineSpacing(self.fonts['verse']['size'] + 1,
                                       verseBox)
                scribus.setTextDistances(4, 0, 4, 0, verseBox)
                if self.hyphenate:
                    scribus.hyphenateText(verseBox)
                # Get the height difference in case we need to set ref box
                verseHeightNew = self.resizeFrame(verseBox)
                verseHeightDiff = crds[row]['verseHeight'] - verseHeightNew
                if verseRef:
                    # Set coordinates for this box
                    vRefBoxX = crds[row]['verseXPos']
                    vRefBoxY = (verseYPosNew + verseHeightNew)
                    vRefBoxH = crds[row]['nameFirstHeight'] / 2
                    vRefBoxW = crds[row]['verseWidth']
                    verseRefBox = scribus.createText(vRefBoxX, vRefBoxY,
                                                     vRefBoxW, vRefBoxH)
                    scribus.setText(verseRef, verseRefBox)
                    scribus.setTextAlignment(scribus.ALIGN_RIGHT, verseRefBox)
                    scribus.setFont(self.fonts['verse']['italic'], verseRefBox)
                    scribus.setFontSize(self.fonts['verse']['size'] - 2,
                                        verseRefBox)
                    scribus.setLineSpacing(self.fonts['verse']['size'],
                                           verseRefBox)
                    scribus.setTextDistances(2, 0, 0, 0, verseRefBox)

                # Up our counts
                if row >= self.dimensions['rows']['count'] - 1:
                    row = 0
                    pageNumber += 1
                else:
                    row += 1

                recCount += 1

            # Create the index page here
            # Output a new page for the index
            if row == 0 and recCount != 0:
                scribus.newPage(-1)
                if pageSide == 'Odd':
                    pageSide = 'Even'
                else:
                    pageSide = 'Odd'

                self.setPageNumber(crds, pageSide, 0, pageNumber)

        # Outut the index entries at this point
#        for key in paIndex.keys() :

# Report we are done now before we loose focus
        scribus.statusMessage('Process Complete!')

        ###############################################################################
        ############################## Output Results #################################
        ###############################################################################

        # Now we will output the results to PDF if that is desired
        if self.makePdf:
            pdfExport = scribus.PDFfile()
            pdfExport.info = self.pdfFile
            pdfExport.file = self.pdfFile
            pdfExport.save()

        # View the output if set
        if self.makePdf and self.viewPdf:
            cmd = ['evince', self.pdfFile]
            try:
                subprocess.Popen(cmd)
            except Exception as e:
                result = scribus.messageBox(
                    'View PDF command failed with: ' + str(e),
                    scribus.BUTTON_OK)
Exemple #11
0
	scribus.loadImage(img_path, img_id)
	scribus.sentToLayer(layer, img_id)

# create new document (smallsquare) 
if scribus.newDocument((document_width,document_height), (0,6.35,3.175,3.175), scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.PAGE_2, 1, 0):

	i = 0
	scribus.createLayer("images")
	scribus.createLayer("text")

	textframes("titel", 42.5, 50, 129.7, 17.99, "White","Black", 39, "FreeSans Bold", 0, "DIE SCHWÄRZUNG","text", 0, 0)
	scribus.createLine(20.2,67.5,190.2,67.5)
	scribus.createImage(55, 72.7, 99.5, 20.2, "logo")
	scribus.loadImage("handydandy_logo.eps", "logo")
	scribus.sentToLayer("images", "logo")
	scribus.setScaleImageToFrame(1,1,"logo")
	textframes("jahr", 81.7, 216.7, 46.1, 18.5, "White","Black", 22, "FreeSans Medium", 0, "2006 - 2012","text", 0, 0)
	
	scribus.newPage(-1)

	slike = glob.glob("pics/*.jpg")
	slike.sort()

	for slika in slike:
		img_id = "img_id" + str(i)
		loadimages(img_id,0,0,209.55,273.1,slika,"images",0)		
		i += 1
		if (i > 796): break
		scribus.newPage(-1)

	scribus.newPage(-1)
        ycount = topMargin
        
				# Calculate position of images
        for i in range(1, numRows+1):
        	xcount = leftMargin
	        for i in range(1, numColumns+1):
	            xpos.append(xcount)
	            ypos.append(ycount)
	            xcount = xcount + columnWidth + gap

        	ycount = ycount + rowHeight + gap

        while imagecount < len(D):
            if imagecount > 0:
                scribus.newPage(-1)
                framecount = 0
# Here is where we're loading images into the page, four at a time, then go back up for a newPage
            for x,y in zip(xpos,ypos):
                if imagecount < len(D):
                    f = scribus.createImage(x, y, imageWidth, imageHeight)
                    scribus.loadImage(imagedir + '/' + D[imagecount], f)
                    scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=f)
                    lenfilename = len(D[imagecount])
                    Lpiclen = int(5.3 * lenfilename)
                    imagecount += 1
    scribus.setRedraw(1)
    scribus.redrawAll()

else:
    result = scribus.messageBox ('Not Found','No Images found with\n this search selection',scribus.BUTTON_OK)
Exemple #13
0
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)
Exemple #14
0
    while page <= len(D):
        scribus.gotoPage(page)
        # if imagecount > 0:
        #     scribus.newPage(-1)
        #     framecount = 0
        # L is the frame at the top of each page showing the directory name
        # L = scribus.createText(15, 20, 200, 20)
        # scribus.setText("Dir: " + imagedir, L)
        # scribus.setTextAlignment(scribus.ALIGN_LEFT, L)
        # scribus.setFont(labelFont, L)
        # scribus.setFontSize(10, L)
        # Here is where we're loading images into the page, four at a time, then go back up for a newPage
        if imagecount < len(D):
            f = scribus.createImage(-3.175, -3.175, pwidth, pheight)
            scribus.loadImage(imagedir + '/' + D[imagecount], f)
            scribus.setScaleImageToFrame(scaletoframe=1, proportional=0, name=f)
            #lenfilename = len(D[imagecount])
            #Lpiclen = int(5.3 * lenfilename)
            # Lpic is the label for each picture, with position and length adjusted
            # according to the text length, so if you change the font or its size,
            # you may need to adjust this only approximate calculation.
            # Lpic = scribus.createText(x, y + 193, Lpiclen, 15)
            # scribus.setText(D[imagecount], Lpic)
            # scribus.setTextAlignment(scribus.ALIGN_RIGHT, Lpic)
            # scribus.setFont(labelFont, Lpic)
            # scribus.setFontSize(8, Lpic)
            # scribus.setFillColor("White", Lpic)
            imagecount += 1
            page += 1

    scribus.setRedraw(1)
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.

import scribus as sc

if sc.haveDoc():
    nbrSelected = sc.selectionCount()

objList = []

for i in range(nbrSelected):
    objList.append(sc.getSelectedObject(i))

for i in range(nbrSelected):
    try:
        obj = objList[i]
        sc.setScaleImageToFrame(True, False, obj)
        scaleX, scaleY = sc.getImageScale(obj)
        sc.setScaleImageToFrame(False, False, obj)
        if scaleX > scaleY:
            scale = scaleX
            sc.setImageScale(scale, scale, obj)
        elif scaleY > scaleX:
            scale = scaleY
            sc.setImageScale(scale, scale, obj)
        sc.docChanged(1)
        sc.setRedraw(True)
    except Exception:
        pass
Exemple #16
0
    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()

scribus.loadImage(filenames[0])
filenames = filenames[1:]

page = scribus.currentPage() + 1
n_pages = scribus.pageCount()

for filename in filenames:
    print(filename)
    if page <= n_pages:
        scribus.gotoPage(page)
    else:
        # TODO: currently this does not work if the names of the default master pages
        # are not in the language of the GUI.
        # if it's the case you need to create all pages before loading the images.
        scribus.newPage(-1)
        scribus.gotoPage(scribus.pageCount())
    new_image = scribus.createImage(x, y, width, height)
    scribus.setScaleImageToFrame(True, True, new_image)
    scribus.loadImage(filename, new_image)
    page += 1
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)
Exemple #18
0
# HACK! I'm sorry :(
files_with_long_text = [
    "{}{}.sla".format(directory, i) for i in indices_with_long_text
]
if not filenames:
    print("No documents with expected name found in " + directory)
for infile in filenames:
    print("Opening " + infile)
    scribus.openDoc(infile)
    # Auto-scale the picture
    try:
        # Find which image object we must change
        images = [s for s in scribus.getPageItems() if s[1] == IMG_TYPE]
        frame = sorted(images, key=lambda s: s[2])[-1][0]
        # frame should be "Image9" if all elements are rendered
        scribus.setScaleImageToFrame(True, name=frame)
        scribus.saveDoc()
    except NoValidObjectError, err:
        print("Image not found in " + infile)
    # Change the text size if necessary
    print(infile)
    if infile in files_with_long_text:
        print("Found " + infile + "!!!")
        try:
            frame = "Text7"
            scribus.setFontSize(11, frame)
            scribus.saveDoc()
        except NoValidObjectError, err:
            print("Text not found in " + infile)
    # Generate the PDF
    pdf = scribus.PDFfile()
if not scribus.haveDoc():
    scribus.messageBox('Usage Error',
                       'You need a Document open',
                       icon=0,
                       button1=1)
    sys.exit(2)

# TODO: ask for the range of pages (current page if empty)

unit = scribus.getUnit()
scribus.setUnit(unit)
scribus.setUnit(scribus.UNIT_MILLIMETERS)

item = scribus.getSelectedObject()

path = scribus.getImageFile(item)
if path == '':
    scribus.messageBox('Usage Error',
                       'You need to first load an image',
                       icon=0,
                       button1=1)
    sys.exit(2)

scribus.setScaleImageToFrame(True, False, item)
scribus.setScaleImageToFrame(False, False, item)
scale = scribus.getImageScale(item)
max_scale = max(scale)
scribus.setImageScale(max_scale, max_scale, item)

scribus.setUnit(unit)
Exemple #20
0
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)
Exemple #21
0
	filesizeiso = distros[distro][1]
	md5sum = distros[distro][2]
	modified = distros[distro][3]

	# create page title/header
	B = scribus.createText(left_page_x, 10, 100, 10)
	scribus.setText(distro, B)
	scribus.setFont("Gentium Plus Compact Regular", B)
	scribus.setTextAlignment(scribus.ALIGN_LEFT, B)
	scribus.setFontSize(18, B)
	
	# load small-logo into page
	imagedir = "./logos/"
	f = scribus.createImage(left_page_x, 23, 65, 65)
	scribus.loadImage(imagedir + distro + ".png", f)
	scribus.setScaleImageToFrame(1,1,f)
	scribus.sentToLayer("textlayer", f)

	# get description text for each distro
	scribus.createText(left_page_x, 92, 120, 80,distro)
	scribus.setText(description, distro)
	scribus.setLineSpacing(12,distro)
	linespacing = scribus.getLineSpacing(distro)
	scribus.setFont("Gentium Plus Compact Regular", distro)
	scribus.setTextAlignment(scribus.ALIGN_LEFT, distro)
	scribus.setFontSize(10, distro)
	scribus.sentToLayer("textlayer", distro)

	# place some background stuff
	placerandom(2)
	placerandom_bars(3)
	def createImagePage(self, file, name):
		scribus.createImage(0, 0, 210, 297, name)
		scribus.loadImage( file, name)
		scribus.setScaleImageToFrame(True, True, name)
Exemple #23
0
    def main (self) :

        # Load up all the file and record information.
        # Use CSV reader to build list of record dicts
        records         = self.loadCSVData(self.dataFile)
        totalRecs       = len(records)

        # Reality check first to see if we have anything to process
        if totalRecs <= 0 :
            scribus.messageBox('Not Found', 'No records found to process!')
            sys.exit()

        pageNumber      = 1
        recCount        = 0
        row             = 0
        pageSide        = 'Odd'
        scribus.progressTotal(totalRecs)
        paIndex         = {}
        lastName        = ''
        firstName       = ''
        photoFirstName  = ''
        verseRef        = ''
        verseText       = ''

        # Get the page layout coordinates for this publication
        crds = self.getCoordinates(self.dimensions)

        # Make a new document to put our records on
        if scribus.newDocument(getattr(scribus, self.dimensions['page']['scribusPageCode']), 
                    (self.dimensions['margins']['left'], self.dimensions['margins']['right'], self.dimensions['margins']['top'], self.dimensions['margins']['bottom']),
                        scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.NOFACINGPAGES, 
                            scribus.FIRSTPAGERIGHT, 1) :

            self.setPageNumber(crds, pageSide, row, pageNumber)

            while recCount < totalRecs :

                # Output a new page on the first row after we have done the first page
                if row == 0 and recCount != 0:
                    scribus.newPage(-1)
                    if pageSide == 'Odd' :
                        pageSide = 'Even'
                    else :
                        pageSide = 'Odd'

                    self.setPageNumber(crds, pageSide, row, pageNumber)

                ########### Now set the current record in the current row ##########

                # Set the last name
                lastName = records[recCount]['NameLast']

                # Adjust the NameFirst field to include the spouse if there is one
                if records[recCount]['Spouse'] != '' :
                    firstName = records[recCount]['NameFirst'] + ' & ' + records[recCount]['Spouse']
                else :
                    firstName = records[recCount]['NameFirst']
                    
                # Make the photo file name
                photoFirstName = firstName.replace('&', '-').replace('.', '').replace(' ', '')

                # Set our record count for progress display and send a status message
                scribus.progressSet(recCount)
                scribus.statusMessage('Placing record ' + `recCount` + ' of ' + `totalRecs`)

                # Add a watermark if a string is specified
                if self.outputWatermark :
                    self.addWatermark()

                # Put the last name element in this row
                nameLastBox = scribus.createText(crds[row]['nameLastXPos'], crds[row]['nameLastYPos'], crds[row]['nameLastWidth'], crds[row]['nameLastHeight'])
                scribus.setText(lastName, nameLastBox)
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, nameLastBox)
                scribus.setTextDistances(0, 0, 0, 0, nameLastBox)
                scribus.setFont(self.fonts['nameLast']['bold'], nameLastBox)
                scribus.setFontSize(self.fonts['nameLast']['size'], nameLastBox)
                scribus.setTextShade(80, nameLastBox)
                scribus.rotateObject(90, nameLastBox)

                # Place the first name element in this row
                nameFirstBox = scribus.createText(crds[row]['nameFirstXPos'], crds[row]['nameFirstYPos'], crds[row]['nameFirstWidth'], crds[row]['nameFirstHeight'])
                scribus.setText(records[recCount]['Caption'], nameFirstBox)
                scribus.setTextAlignment(scribus.ALIGN_LEFT, nameFirstBox)
                scribus.setFont(self.fonts['nameFirst']['boldItalic'], nameFirstBox)
                scribus.setFontSize(self.fonts['nameFirst']['size'], nameFirstBox)

                # Place the image element in this row
                # We will need to do some processing on the first pass
                # The default output format is JPG
                orgImgFileName = records[recCount]['Photo']
                orgImgFile = os.path.join(self.orgImgDir, orgImgFileName)
                baseImgFileName = lastName + '_' + photoFirstName
                if self.willBePngImg :
                    ext = 'png'
                else :
                    ext = 'jpg'
                if not self.rgbColor :
                    imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '-gray' + '.' + ext)
                else :
                    imgFile = os.path.join(getattr(self, ext + 'ImgDir'), baseImgFileName + '.' + ext)

                # Process the image now if there is none
                if not os.path.exists(imgFile) :
                    self.img_process.sizePic(orgImgFile, imgFile, self.maxHeight)
#                    self.img_process.outlinePic(imgFile, imgFile)
                    self.img_process.scalePic(imgFile, imgFile, self.imgDensity)
                    self.img_process.addPoloroidBorder(imgFile, imgFile)
                    # Color RGB is the default
                    if not self.rgbColor :
                        self.img_process.makeGray(imgFile, imgFile)

                # Double check the output and substitute with placeholder pic
                if not os.path.exists(imgFile) :
                    imgFile = self.placeholderPic
                # Create the imageBox and load the picture
                imageBox = scribus.createImage(crds[row]['imageXPos'], crds[row]['imageYPos'], crds[row]['imageWidth'], crds[row]['imageHeight'])
                if os.path.isfile(imgFile) :
                    scribus.loadImage(imgFile, imageBox)
                scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=imageBox)

                # Place the country element in this row (add second one if present)
                countryBox = scribus.createText(crds[row]['countryXPos'], crds[row]['countryYPos'], crds[row]['countryWidth'], crds[row]['countryHeight'])
                countryLine = records[recCount]['Country1']
                try :
                    if records[recCount]['Country2'] != '' :
                        countryLine = countryLine + ' & ' + records[recCount]['Country2']
                except :
                    pass
                scribus.setText(countryLine, countryBox)
                scribus.setTextAlignment(scribus.ALIGN_RIGHT, countryBox)
                scribus.setFont(self.fonts['text']['boldItalic'], countryBox)
                scribus.setFontSize(self.fonts['text']['size'], countryBox)

                # Place the assignment element in this row
                assignBox = scribus.createText(crds[row]['assignXPos'], crds[row]['assignYPos'], crds[row]['assignWidth'], crds[row]['assignHeight'])
                scribus.setText(self.fixText(records[recCount]['Assignment']), assignBox)
                # Assign style to box
#                scribus.createParagraphStyle(name='assignStyle', alignment=0, leftmargin=10, firstindent=-10)
#                scribus.setStyle('assignStyle', assignBox)
                # Hard formated box
                scribus.setTextAlignment(scribus.ALIGN_LEFT, assignBox)
                scribus.setFont(self.fonts['text']['italic'], assignBox)
                scribus.setFontSize(self.fonts['text']['size'], assignBox)
                scribus.setLineSpacing(self.fonts['text']['size'] + 1, assignBox)
                scribus.setTextDistances(4, 0, 0, 0, assignBox)
                # Resize the frame height and determine the difference for
                # placing the next frame below it
                assignHeightNew = self.resizeFrame(assignBox)
                assignHeightDiff = crds[row]['assignHeight'] - assignHeightNew

                # Place the verse element in this row
                verseYPosNew = crds[row]['verseYPos'] - assignHeightDiff
                verseBox = scribus.createText(crds[row]['verseXPos'], verseYPosNew, crds[row]['verseWidth'], crds[row]['verseHeight'])
                # The verse element may be either a Scripture verse or a prayer request
                # If it is Scripture, and it has a verse ref, we want to set that
                # seperatly so we need to do a little preprocess on the text to find
                # out if it has a ref. This script will only recognize references
                # at the end of the string that are enclosed in brackets. See the
                # findVerseRef() function for more details
                verseRef = self.findVerseRef(records[recCount]['Prayer'])
                if verseRef :
                    verseText = self.removeVerseRef(self.fixText(records[recCount]['Prayer']))
                    scribus.setText(verseText, verseBox)
                else :
                    scribus.setText(self.fixText(records[recCount]['Prayer']), verseBox)
                # Can't find a way to set alignment to justified using setTextAlignment()
#                scribus.setTextAlignment(scribus.ALIGN_LEFT, verseBox)
                # Because of this, we make a style which seems to work
                scribus.createParagraphStyle(name='vBoxStyle', alignment=3)
                scribus.setStyle('vBoxStyle', verseBox)
                scribus.setFont(self.fonts['verse']['regular'], verseBox)
                scribus.setFontSize(self.fonts['verse']['size'], verseBox)
                scribus.setLineSpacing(self.fonts['verse']['size'] + 1, verseBox)
                scribus.setTextDistances(4, 0, 4, 0, verseBox)
                if self.hyphenate :
                    scribus.hyphenateText(verseBox)
                # Get the height difference in case we need to set ref box
                verseHeightNew = self.resizeFrame(verseBox)
                verseHeightDiff = crds[row]['verseHeight'] - verseHeightNew
                if verseRef :
                    # Set coordinates for this box
                    vRefBoxX = crds[row]['verseXPos']
                    vRefBoxY = (verseYPosNew + verseHeightNew)
                    vRefBoxH = crds[row]['nameFirstHeight'] / 2
                    vRefBoxW = crds[row]['verseWidth']
                    verseRefBox = scribus.createText(vRefBoxX, vRefBoxY, vRefBoxW, vRefBoxH)
                    scribus.setText(verseRef, verseRefBox)
                    scribus.setTextAlignment(scribus.ALIGN_RIGHT, verseRefBox)
                    scribus.setFont(self.fonts['verse']['italic'], verseRefBox)
                    scribus.setFontSize(self.fonts['verse']['size'] - 2, verseRefBox)
                    scribus.setLineSpacing(self.fonts['verse']['size'], verseRefBox)
                    scribus.setTextDistances(2, 0, 0, 0, verseRefBox)

                # Up our counts
                if row >= self.dimensions['rows']['count'] - 1 :
                    row = 0
                    pageNumber +=1
                else :
                    row +=1
                    
                recCount +=1

            # Create the index page here
            # Output a new page for the index
            if row == 0 and recCount != 0:
                scribus.newPage(-1)
                if pageSide == 'Odd' :
                    pageSide = 'Even'
                else :
                    pageSide = 'Odd'

                self.setPageNumber(crds, pageSide, 0, pageNumber)

        # Outut the index entries at this point
#        for key in paIndex.keys() :

        # Report we are done now before we loose focus
        scribus.statusMessage('Process Complete!')

###############################################################################
############################## Output Results #################################
###############################################################################

        # Now we will output the results to PDF if that is desired
        if self.makePdf :
            pdfExport =  scribus.PDFfile()
            pdfExport.info = self.pdfFile
            pdfExport.file = self.pdfFile
            pdfExport.save()

        # View the output if set
        if self.makePdf and self.viewPdf :
            cmd = ['evince', self.pdfFile]
            try :
                subprocess.Popen(cmd)
            except Exception as e :
                result = scribus.messageBox ('View PDF command failed with: ' + str(e), scribus.BUTTON_OK)