コード例 #1
0
def main():
    text_frames, image_frames = get_placeholders()

    sla_template_filename = scribus.getDocName()
    sla_template_path = Path(sla_template_filename)

    if 'file' in CONFIGURATION['data'] and CONFIGURATION['data']['file']:
        data_path = str(
            sla_template_path.parent.joinpath(CONFIGURATION['data']['file']))
    elif CONFIGURATION['data']['format'] == 'json':
        data_path = sla_template_path.with_suffix('.json')
    else:
        data_path = sla_template_path.with_suffix('.csv')

    if not os.path.isfile(data_path):
        sys.exit()

    if CONFIGURATION['data']['format'] == 'json':
        pass
    else:
        data_file = open(data_path, 'rt')
        reader = csv.DictReader(data_file)

    pdf_base_filename = sla_template_path.stem
    pdf_path = Path(sla_template_path.parent)

    if CONFIGURATION['output']['pdf']:
        pdf = scribus.PDFfile()
        pdf.quality = 0
        pdf.fontEmbedding = 0
        pdf.version = 14

        scribus.setRedraw(False)
        for row in reader:
            for frame, placeholders in text_frames:
                fill_text_placeholders(frame, placeholders, row)
            for frame, placeholders in image_frames:
                fill_image_placeholders(frame, placeholders, row)

            pdf.file = str(
                pdf_path.joinpath(pdf_base_filename + '-' +
                                  next(iter(row.items()))[1].lower() + '.pdf'))
            pdf.save()

            scribus.docChanged(True)
            scribus.revertDoc()
        scribus.setRedraw(True)
    elif CONFIGURATION['output']['single-sla']:
        original_pages = list(range(1, scribus.pageCount() + 1))
        for row in reader:
            new_frames = duplicate_content(
                original_pages, [i[0] for i in text_frames + image_frames])

            for frame, placeholders in text_frames:
                fill_text_placeholders(new_frames[frame], placeholders, row)
            for frame, placeholders in image_frames:
                fill_image_placeholders(new_frames[frame], placeholders, row)
        for page in original_pages:
            scribus.deletePage(page)
コード例 #2
0
def main(argv):
    """This is a documentation string. Write a description of what your code
    does here. You should generally put documentation strings ("docstrings")
    on all your Python functions."""
    #########################
    #  YOUR CODE GOES HERE  #
    #########################
    scribus.statusMessage(str(scribus.PAPER_A4))
    scribus.newDocument(
        scribus.PAPER_A4,  #paper
        (MARGIN, MARGIN, MARGIN, MARGIN),  #margins
        scribus.LANDSCAPE,  #orientation
        0,  #firstPageNumber
        scribus.UNIT_MILLIMETERS,  #unit
        scribus.PAGE_1,  #pagesType
        0,  #firstPageOrder
        0,  #numPages
    )
    scribus.createCharStyle('date1', 'Athelas Bold', 45)
    scribus.createCharStyle('month1', 'Athelas Bold', 16)
    scribus.createCharStyle('name1', 'Athelas Regular', 16)
    scribus.createParagraphStyle('dateL',
                                 alignment=scribus.ALIGN_LEFT,
                                 charstyle='date1')
    scribus.createParagraphStyle('monthL',
                                 alignment=scribus.ALIGN_LEFT,
                                 charstyle='month1')
    scribus.createParagraphStyle('nameL',
                                 alignment=scribus.ALIGN_LEFT,
                                 charstyle='name1')
    scribus.createParagraphStyle('dateR',
                                 alignment=scribus.ALIGN_RIGHT,
                                 charstyle='date1')
    scribus.createParagraphStyle('monthR',
                                 alignment=scribus.ALIGN_RIGHT,
                                 charstyle='month1')
    scribus.createParagraphStyle('nameR',
                                 alignment=scribus.ALIGN_RIGHT,
                                 charstyle='name1')
    masterPage()

    d = data.loadData()
    """
    We want to make pamphlet (signature) of 5 x A4 papers printed from both sides with 2 weeks on each side
    2sided 4imposition refer imposition.py
    """
    def pageFn(left, right):
        page = scribus.newPage(-1, 'planner')
        i = 0
        sizeDate = (20, 15)
        sizeMonth = (20, 7)
        sizeName = (290, 7)
        for xend, y in iterDayLines():
            try:
                tLeftDate = left[i]
                posLeftDate = (xstart, y - sizeDate[1])
                posLeftMonth = (xstart + sizeDate[0], y - sizeDate[1])
                posLeftName = (xstart + sizeDate[0], y - sizeName[1])
                tLeftName = ', '.join(d[tLeftDate.month][tLeftDate.day])
                objLeftDate = scribus.createText(*posLeftDate + sizeDate)
                objLeftMonth = scribus.createText(*posLeftMonth + sizeMonth)
                objLeftName = scribus.createText(*posLeftName + sizeName)
                scribus.setText(tLeftDate.strftime('%d'), objLeftDate)
                scribus.setText(mm(tLeftDate), objLeftMonth)
                scribus.setText(tLeftName, objLeftName)
                scribus.setStyle('dateL', objLeftDate)
                scribus.setStyle('monthL', objLeftMonth)
                scribus.setStyle('nameL', objLeftName)
            except IndexError:
                pass

            try:
                posRightDate = (xend - sizeDate[0], y - sizeDate[1])
                posRightMonth = (xend - sizeDate[0] - sizeMonth[0],
                                 y - sizeDate[1])
                posRightName = (xend - sizeDate[0] - sizeName[0],
                                y - sizeName[1])
                tRightDate = right[i]
                tRightName = ', '.join(d[tRightDate.month][tRightDate.day])
                objRightDate = scribus.createText(*posRightDate + sizeDate)
                objRightMonth = scribus.createText(*posRightMonth + sizeMonth)
                objRightName = scribus.createText(*posRightName + sizeName)
                scribus.setText(tRightDate.strftime('%d'), objRightDate)
                scribus.setText(mm(tRightDate), objRightMonth)
                scribus.setText(tRightName, objRightName)
                scribus.setStyle('dateR', objRightDate)
                scribus.setStyle('monthR', objRightMonth)
                scribus.setStyle('nameR', objRightName)
            except IndexError:
                pass
            i += 1

    dates.forEachWeek(pageFn)
    scribus.deletePage(1)
# print(projects)
# sys.exit(1)

# add the projects to a scribus doc, one project per A6 page. for each section there is a specific master page with a logo.

if (not scribus.haveDoc()) :
    # TODO: how to open a file in the script's directory?
    # scribus.openDoc(os.path.dirname(os.path.realpath(__file__)) + '/cards.sla')
    # scribus.openDoc(os.path.dirname(os.path.realpath(sys.argv[0])) + '/cards.sla')
    scribus.messageBox("Error", "You should first open the cards.sla file", ICON_WARNING, BUTTON_OK)
    sys.exit(1)

# for page in range(2, scribus.pageCount()) :
# scribus.messageBox("Error", str(scribus.pageCount()), ICON_WARNING, BUTTON_OK)
for page in range(scribus.pageCount(), 1, -1) :
    scribus.deletePage(page)

for project in projects :
    scribus.newPage(-1, project['section'])

    # title: x=10 y=10 w=85mm h=20
    # description: x=10 y=40 w=85mm h=80
    titleFrame = scribus.createText(10, 10, 85, 20)
    scribus.setText(project['title'], titleFrame)
    scribus.setStyle('title', titleFrame)
    descriptionFrame = scribus.createText(10, 40, 85, 80)
    scribus.setText(project['description'], descriptionFrame)
    scribus.setStyle('description', descriptionFrame)

    # shrink the title and text size if it does not fit in the frame
    while scribus.textOverflows(titleFrame) != 0 :
コード例 #4
0
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)
コード例 #5
0
import scribus
import argparse

parser = argparse.ArgumentParser(
    description="Deletes page from an `.sla` file")

parser.add_argument(
    "file",
    default=None,
    help="SLA file to be processed",
)

parser.add_argument(
    "--page",
    type=int,
    help="Number of pages being deleted",
)

if __name__ == "__main__":
    args = parser.parse_args()

    # Open document
    scribus.openDoc(os.path.abspath(args.file))

    # Delete page
    scribus.deletePage(args.page)

    # Save & close document
    scribus.saveDoc()
    scribus.closeDoc()
コード例 #6
0
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)