Example #1
0
    def addWatermark (self) :
        '''Create a Draft watermark layer. This was taken from:
            http://wiki.scribus.net/canvas/Adding_%27DRAFT%27_to_a_document'''

        L = len(self.watermark)                         # The length of the word 
                                                        # will determine the font size
        scribus.defineColor("gray", 11, 11, 11, 11)     # Set your own color here

        u  = scribus.getUnit()                          # Get the units of the document
        al = scribus.getActiveLayer()                   # Identify the working layer
        scribus.setUnit(scribus.UNIT_MILLIMETERS)       # Set the document units to mm,
        (w,h) = scribus.getPageSize()                   # needed to set the text box size

        scribus.createLayer("c")
        scribus.setActiveLayer("c")

        T = scribus.createText(w/6, 6*h/10 , h, w/2)    # Create the text box
        scribus.setText(self.watermark, T)              # Insert the text
        scribus.setTextColor("gray", T)                 # Set the color of the text
        scribus.setFontSize((w/210)*(180 - 10*L), T)    # Set the font size according to length and width

        scribus.rotateObject(45, T)                     # Turn it round antclockwise 45 degrees
        scribus.setUnit(u)                              # return to original document units
# FIXME: It would be nice if we could move the watermark box down to the lowest layer so 
# that it is under all the page text. Have not found a method to do this. For now we just
# plop the watermark on top of everything else.
        scribus.setActiveLayer(al)                      # return to the original active layer
def main(argv):
    """A simple scripts to set baseline grid and matching guides."""

    CurrentUnit = scribus.getUnit()

    scribus.setUnit(0)
    H_Guides = []

    GuideHeight = float(
        scribus.valueDialog('Set BaseLine Grid & Guides',
                            'Enter value for Grid and Guide Height (pt).',
                            '14.40'))
    GuideOffset = float(
        scribus.valueDialog('Set Grid & Guide Offsets',
                            'Enter value for Grid and Guide Offset (pt).',
                            '0.0'))

    PageWidth, PageHeight = scribus.getPageSize()

    NumLoops = math.floor(1 + (PageHeight - GuideOffset) / GuideHeight)

    for i in range(int(NumLoops)):
        if i > 0:
            H_Guides.append(GuideOffset + i * GuideHeight)

    scribus.setBaseLine(GuideHeight, GuideOffset)
    scribus.setHGuides(scribus.getHGuides() + H_Guides)

    scribus.setUnit(CurrentUnit)

    scribus.messageBox(
        'Script',
        '<h3>Script by ugajin</h3><p>Thanks a bunch for using setBaselineGuides and Scribus!</p><p>[email protected]</p>',
        scribus.ICON_INFORMATION, scribus.BUTTON_OK, scribus.BUTTON_CANCEL)
Example #3
0
    def addWatermark(self):
        '''Create a Draft watermark layer. This was taken from:
			http://wiki.scribus.net/canvas/Adding_%27DRAFT%27_to_a_document'''

        L = len(self.watermark)  # The length of the word
        # will determine the font size
        scribus.defineColor("gray", 11, 11, 11, 11)  # Set your own color here

        u = scribus.getUnit()  # Get the units of the document
        al = scribus.getActiveLayer()  # Identify the working layer
        scribus.setUnit(
            scribus.UNIT_MILLIMETERS)  # Set the document units to mm,
        (w, h) = scribus.getPageSize()  # needed to set the text box size

        scribus.createLayer("c")
        scribus.setActiveLayer("c")

        T = scribus.createText(w / 6, 6 * h / 10, h,
                               w / 2)  # Create the text box
        scribus.setText(self.watermark, T)  # Insert the text
        scribus.setTextColor("gray", T)  # Set the color of the text
        scribus.setFontSize(
            (w / 210) * (180 - 10 * L),
            T)  # Set the font size according to length and width

        scribus.rotateObject(45, T)  # Turn it round antclockwise 45 degrees
        scribus.setUnit(u)  # return to original document units
        # FIXME: It would be nice if we could move the watermark box down to the lowest layer so
        # that it is under all the page text. Have not found a method to do this. For now we just
        # plop the watermark on top of everything else.
        scribus.setActiveLayer(al)  # return to the original active layer
def main(argv):
    """A simple scripts to set baseline grid and matching guides."""

    CurrentUnit = scribus.getUnit() 
    
    scribus.setUnit(0) 
    H_Guides = [] 
    
    GuideHeight = float(scribus.valueDialog('Set BaseLine Grid & Guides', 'Enter value for Grid and Guide Height (pt).', '14.40') )
    GuideOffset = float(scribus.valueDialog('Set Grid & Guide Offsets', 'Enter value for Grid and Guide Offset (pt).', '0.0') )
    
    PageWidth, PageHeight = scribus.getPageSize() 
    
    NumLoops = math.floor(1 + (PageHeight - GuideOffset) / GuideHeight)
    
    for i in range(int(NumLoops)):
    	if i > 0:
    		H_Guides.append(GuideOffset + i * GuideHeight)
    
    scribus.setBaseLine(GuideHeight, GuideOffset)
    scribus.setHGuides(scribus.getHGuides() + H_Guides)
    
    scribus.setUnit(CurrentUnit)
    
    scribus.messageBox('Script', '<h3>Script by ugajin</h3><p>Thanks a bunch for using setBaselineGuides and Scribus!</p><p>[email protected]</p>', scribus.ICON_INFORMATION, scribus.BUTTON_OK, scribus.BUTTON_CANCEL)
Example #5
0
def prepareDocument():
    """creates the new document, sets up colors """
    colorList = getColorsFromDocument()
    spotDict = getSpotColors()
    scribus.statusMessage("Preparing new document...")
    scribus.newDocument(scribus.PAPER_A4,  (15,15,  20, 20),  scribus.PORTRAIT, 1, scribus.UNIT_POINTS,  scribus.PAGE_1, 0, 1) 
    scribus.setUnit(scribus.UNIT_MILLIMETERS)
    #delete existing colors
    cols = scribus.getColorNames()
    for col in cols:
        scribus.deleteColor(col, "None")

    #create our new colors
    for color in colorList:
        cname=color[0]
        c = int(color[1])
        m = int(color[2])
        y = int(color[3])
        k = int(color[4])
        scribus.defineColorCMYK(cname,  c, m, y, k )
        if spotDict.has_key(cname):
            scribus.setSpotColor(cname, spotDict[cname])

    #get the pageTitle form user and store it in PageTitle
    global pageTitle
    pageTitle=scribus.valueDialog("ColorChart by Sebastian Stetter", "Please enter document title", "Scribus COLOR CHART")
    drawHeaderFooter(pageTitle)
Example #6
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  #
    #########################
    userdim = scribus.getUnit()  # get unit and change it to mm
    scribus.setUnit(scribus.UNIT_MILLIMETERS)
    cellwidthleft = 0
    cellwidthright = 0
    cellHeight = 0
    pos = getPosition()
    while cellwidthleft <= 0:
        cellwidthL = scribus.valueDialog("Left Cell Width", "How wide (mm) do you wish left cells to be?", "30.0")
        cellwidthleft = float(cellwidthL)
    while cellwidthright <= 0:
        cellwidthR = scribus.valueDialog("Right Cell Width", "How wide (mm) do you wish right cells to be?", "30.0")
        cellwidthright = float(cellwidthR)
    while cellHeight <= 0:
        cellheight = scribus.valueDialog("Cell Height", "How tall (mm) do you wish cells to be?", "10.0")
        cellHeight = float(cellheight)
    data = getCSVdata()
    di = getDataInformation(data)
    hposition = pos[1]
    vposition = pos[0]

    objectlist = []  # here we keep a record of all the created textboxes so we can group them later
    i = 0
    scribus.progressTotal(len(data))
    scribus.setRedraw(False)
    for row in data:
        c = 0
        for cell in row:
            cell = cell.strip()
            cellsize = cellwidthleft
            if c == 1:
                cellsize = cellwidthright
            textbox = scribus.createText(hposition, vposition, cellsize, cellHeight)  # create a textbox
            objectlist.append(textbox)
            scribus.insertText(cell, 0, textbox)  # insert the text into the textbox
            hposition = hposition + cellwidthleft  # move the position for the next cell
            c = 1
        vposition = vposition + cellHeight  # set vertical position for next row
        hposition = pos[1]  # reset vertical position for next row
        i = i + 1
        scribus.progressSet(i)

    scribus.groupObjects(objectlist)
    scribus.progressReset()
    scribus.setUnit(userdim)  # reset unit to previous value
    scribus.docChanged(True)
    scribus.statusMessage("Done")
    scribus.setRedraw(True)
def get_settings_from_document(ignore_margins=True):
    scribus.setUnit(scribus.UNIT_MILLIMETERS)

    global page_size, page_margins_right, page_margins_left

    page_size = scribus.getPageSize()

    if ignore_margins:
        page_margins_right = (0, 0, 0, 0)
    else:
        page_margins_right = scribus.getPageMargins()

    page_margins_left = (page_margins_right[0], page_margins_right[2], page_margins_right[1], page_margins_right[3])

    calc_max()
def get_settings_from_document(ignore_margins=True):
    scribus.setUnit(scribus.UNIT_MILLIMETERS)

    global page_size, page_margins_right, page_margins_left

    page_size = scribus.getPageSize()

    if ignore_margins:
        page_margins_right = (0, 0, 0, 0)
    else:
        page_margins_right = scribus.getPageMargins()

    page_margins_left = (page_margins_right[0], page_margins_right[2],
                         page_margins_right[1], page_margins_right[3])

    calc_max()
    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()
    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()
Example #11
0
    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()
def create(argv):
    """
        - create a page using the "badge" master page.
        - add the text field with the name
        - add the text with the role in the project
    """
    #########################
    #  YOUR CODE GOES HERE  #
    #########################
    userdim=scribus.getUnit() #get unit and change it to mm
    scribus.setUnit(scribus.UNIT_POINTS)
 
    data = getCSVdata()
 
    scribus.progressTotal(len(data)+1)
    scribus.setRedraw(False)

    i = 0;
    
    #Select Output Directory and define some Vars based on it.
    #baseDirName = scribus.fileDialog("Rosenlehrpfad - Wahl des Ausgabeverzeichnisses", "*","./" ,False, False, True)
    baseDirName = os.path.abspath("./output")
    tmpFileName = os.path.join(baseDirName, "tmp.sla")
    idtextstring = "Rosenid"
    gertextstring = "RosentextDeutsch"
    lattextstring = "RosentextLatein"
    
    if not os.path.exists(baseDirName):
      os.makedirs(baseDirName)
    else:
      for the_file in os.listdir(baseDirName):
	file_path = os.path.join(baseDirName, the_file)
	try:
	  if os.path.isfile(file_path):
	    os.unlink(file_path)
	except Exception, e:
	  print e
Example #13
0
    if False:
        print label + ' ' + str(value)


debug("############")

# this script makes no sense without a document open
if not scribus.haveDoc():
    scribus.messageBox('Scribus - Script Error', "No document open",
                       scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(1)

# environment initialization

unit_current = scribus.getUnit()  #get unit and change it to mm
scribus.setUnit(scribus.UNIT_MILLIMETERS)

# some ratios for calculations

pt_to_mm_ratio = 3.528 / 10.0
cell_ratio = 2.0 / 3  # or 3/2

# input values
column_count = scribus.valueDialog(
    'Number of columns',
    'Please set the number of columns\n(sane values are 6, 9, 12, 24)', '6')
column_count = get_int_from_dialog_value(column_count)

font_size_main_text = scribus.valueDialog(
    'Text size',
    'Please set the font size for the main text\n(this value will be used)',
def init():
    scribus.openDoc(pwd("init.sla"))
    scribus.saveDocAs("/tmp/{}.sla".format(time.time()))
    scribus.setUnit(scribus.UNIT_MM)
Example #15
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  #
    #########################
    userdim = scribus.getUnit()  #get unit and change it to mm
    scribus.setUnit(scribus.UNIT_MILLIMETERS)
    cellwidthleft = 0
    cellwidthright = 0
    cellHeight = 0
    pos = getPosition()
    while cellwidthleft <= 0:
        cellwidthL = scribus.valueDialog(
            'Left Cell Width', 'How wide (mm) do you wish left cells to be?',
            '30.0')
        cellwidthleft = float(cellwidthL)
    while cellwidthright <= 0:
        cellwidthR = scribus.valueDialog(
            'Right Cell Width', 'How wide (mm) do you wish right cells to be?',
            '30.0')
        cellwidthright = float(cellwidthR)
    while cellHeight <= 0:
        cellheight = scribus.valueDialog(
            'Cell Height', 'How tall (mm) do you wish cells to be?', '10.0')
        cellHeight = float(cellheight)
    data = getCSVdata()
    di = getDataInformation(data)
    hposition = pos[1]
    vposition = pos[0]

    objectlist = [
    ]  # here we keep a record of all the created textboxes so we can group them later
    i = 0
    scribus.progressTotal(len(data))
    scribus.setRedraw(False)
    for row in data:
        c = 0
        for cell in row:
            cell = cell.strip()
            cellsize = cellwidthleft
            if c == 1: cellsize = cellwidthright
            textbox = scribus.createText(hposition, vposition, cellsize,
                                         cellHeight)  #create a textbox
            objectlist.append(textbox)
            scribus.insertText(cell, 0,
                               textbox)  #insert the text into the textbox
            hposition = hposition + cellwidthleft  #move the position for the next cell
            c = 1
        vposition = vposition + cellHeight  #set vertical position for next row
        hposition = pos[1]  #reset vertical position for next row
        i = i + 1
        scribus.progressSet(i)

    scribus.groupObjects(objectlist)
    scribus.progressReset()
    scribus.setUnit(userdim)  # reset unit to previous value
    scribus.docChanged(True)
    scribus.statusMessage("Done")
    scribus.setRedraw(True)
#/usr/bin/env python
# -*- coding: utf-8 -*-

import scribus
from scribus import *
import math  


scribus.setUnit(2)


startMsg1 = "This script automates some simple setup taskss."

startMsg = startMsg1

#sets colors (no need to import color palette any longer)


defineColor("Nimble Maroon", 0, 100, 100, 55)
defineColor("Nimble Napoleonic Green", 73, 0, 78, 73) 
defineColor("Nimble Blue", 100, 67, 0, 62) 
defineColor("Nimble Feldgrau", 60, 40, 51, 43) 
defineColor("Nimble Metallic Gold", 44, 47, 78, 20) 
defineColor("Nimble Reference Red", 0, 100, 100, 0)

createLayer("Cover")

createLayer("ISBN_Box")


createLayer("ISBN")
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)
#/usr/bin/env python
# -*- coding: utf-8 -*-

import scribus
from scribus import *
import math

scribus.setUnit(2)

startMsg1 = "This script automates some simple setup taskss."

startMsg = startMsg1

#sets colors (no need to import color palette any longer)

defineColor("Nimble Maroon", 0, 100, 100, 55)
defineColor("Nimble Napoleonic Green", 73, 0, 78, 73)
defineColor("Nimble Blue", 100, 67, 0, 62)
defineColor("Nimble Feldgrau", 60, 40, 51, 43)
defineColor("Nimble Metallic Gold", 44, 47, 78, 20)
defineColor("Nimble Reference Red", 0, 100, 100, 0)

createLayer("Cover")

createLayer("ISBN_Box")

createLayer("ISBN")
def main(argv):
    userdim = scribus.getUnit()  # get unit and change it to mm
    scribus.setUnit(scribus.UNIT_MILLIMETERS)
    cellwidthleft = 0
    cellwidthright = 0
    # Set starting position
    hposition = 28
    vposition = 20
    data = getCSVdata()
    di = getDataInformation(data)
    ncol = len(data[0])
    nrow = len(data)
    scribus.messageBox("Table", "   " + str(ncol) + " columns,    " +
                       str(nrow) + " rows   ")  #jpg
    ColWidthList = []
    TableWidth = 0
    RowHeightList = []
    TableHeight = 0
    i = 0
    for row in data:
        if i == 0:
            c = 0
            for cell in row:
                ColWidth = 40
                ColWidthList.append(ColWidth)
        TableWidth = TableWidth + ColWidth
        c = c + 1
        RowHeight = 15
        RowHeightList.append(RowHeight)
        TableHeight = TableHeight + RowHeight
        i = i + 1
    objectlist = [
    ]  # here we keep a record of all the created textboxes so we can group them later
    i = 0
    scribus.progressTotal(len(data))
    scribus.setRedraw(False)
    rowindex = 0
    new_row_indication = 1
    new_page_indication = 1
    firstorigin_indicator = 1
    while rowindex < len(data):
        c = 0
        origin_cd = data[rowindex][0].strip()
        origin = data[rowindex][1].strip()
        origin_complete = origin + ' (' + origin_cd + ")"
        headerorigin = origin_complete
        origin_added = 0
        destination_cd = data[rowindex][2].strip()
        destination = data[rowindex][3].strip()
        destination_complete = destination + ' (' + destination_cd + ")"
        fareplan = data[rowindex][4].strip()
        fareplan_type = data[rowindex][5].strip()
        fareplan_complete = fareplan + ' ' + fareplan_type[:1]
        fare = data[rowindex][6].strip()
        fare = float(fare)
        fare = "{0:.2f}".format(fare)
        fare_onboard = data[rowindex][7].strip()
        fare_onboard = float(fare_onboard)
        fare_onboard = "{0:.2f}".format(fare_onboard)
        cellheight_market = 5
        cellheight_market_dos = 5

        try:
            last_origin = data[rowindex - 1][1].strip()
        except:
            last_origin = origin

        try:
            last_destination = data[rowindex - 1][3].strip()
        except:
            last_destination = destination

        cellsize = ColWidthList[c]
        cellHeight = RowHeightList[i]

        # Check to see if near bottom of the page, if so wrap it over
        if (vposition > 227):
            hposition = hposition + cellsize
            vposition = 20
            new_row_indication = 1
        # If at end, reset and create new page
        if (hposition > 174):
            scribus.newPage(-1)
            hposition = 28
            vposition = 20
            new_page_indication = 1
            firstorigin_indicator = 0

        if new_row_indication == 1:
            textbox = scribus.createText(hposition, 16, cellsize / 2,
                                         4)  # create a textbox.
            objectlist.append(textbox)
            scribus.setStyle('FareplanHeader', textbox)
            scribus.insertText('Fareplan', 0, textbox)
            c = c + 1

            textbox = scribus.createText(hposition + (cellsize / 2), 16,
                                         cellsize / 2, 4)  # create a textbox.
            objectlist.append(textbox)
            scribus.setStyle('FareplanHeader', textbox)
            scribus.insertText('Amount', 0, textbox)
            c = c + 1


#			if (firstorigin_indicator == 1):
#				headerorigin = origin_complete
#				textbox = scribus.createText(20, 10, cellsize*4, 4) # create a textbox.
#				objectlist.append(textbox)
#				scribus.setStyle('HeaderOrigin', textbox)
#				scribus.insertText(headerorigin, 0, textbox)
#				c = c + 1

# Origin textbox
        if (rowindex < len(data)):
            if ((origin != last_origin) or (rowindex == 0)):
                # Add 'btwn' text
                textbox = scribus.createText(hposition, vposition, cellsize,
                                             4)  # create a textbox.
                objectlist.append(textbox)
                scribus.setStyle(
                    'Headings', textbox
                )  # set it in the style 'Headings' as defined in Scribus.
                scribus.insertText(
                    'btwn', 0, textbox)  # insert the origin into the textbox.
                # scribus.setDistances(1,1,1,1) # set the distances.
                vposition = vposition + 4  # Shift position of cell down.
                c = c + 1

                textbox = scribus.createText(
                    hposition, vposition, cellsize,
                    cellheight_market_dos)  # create a textbox.
                objectlist.append(textbox)
                scribus.setStyle(
                    'Headings', textbox
                )  # set it in the style 'Headings' as defined in Scribus.
                scribus.insertText(
                    origin_complete, 0,
                    textbox)  # insert the origin into the textbox.
                while (scribus.textOverflows(textbox) > 0):
                    cellheight_market_dos += 1
                    scribus.sizeObject(cellsize, cellheight_market_dos,
                                       textbox)
                vposition = vposition + cellheight_market_dos  # Shift position of cell down.
                c = c + 1

                # Add 'and' text
                textbox = scribus.createText(hposition, vposition, cellsize,
                                             4)  # create a textbox.
                objectlist.append(textbox)
                scribus.setStyle(
                    'andStyle', textbox
                )  # set it in the style 'andStyle' as defined in Scribus.
                scribus.insertText(
                    'and', 0, textbox)  # insert the origin into the textbox.
                vposition = vposition + 4  # Shift position of cell down.
                c = c + 1

                origin_added = 1
                firstorigin_indicator = firstorigin_indicator + 1

                # Insert the origin at the top margin
                if (firstorigin_indicator == 1 or rowindex == 0):
                    headerorigin = origin_complete
                    textbox = scribus.createText(28, 10, cellsize * 4,
                                                 4)  # create a textbox.
                    objectlist.append(textbox)
                    scribus.setStyle('HeaderOrigin', textbox)
                    scribus.insertText(headerorigin, 0, textbox)
                    c = c + 1

        # Destination textbox
        if ((destination != last_destination) or (rowindex == 0)
                or (origin_added == 1)):
            textbox = scribus.createText(
                hposition, vposition, cellsize,
                cellheight_market)  # create a textbox.
            objectlist.append(textbox)
            scribus.setStyle(
                'Headings', textbox
            )  # set it in the style 'Headings' as defined in Scribus.
            scribus.insertText(
                destination_complete, 0,
                textbox)  # insert the destination into the textbox.
            while (scribus.textOverflows(textbox) > 0):
                cellheight_market += 1
                scribus.sizeObject(cellsize, cellheight_market, textbox)

            vposition = vposition + cellheight_market  # Shift position of cell down.
            c = c + 1
        rowindex = rowindex + 1

        # Fareplan textbox
        fareplan_box_height = 5
        if fare_onboard != '0.00':
            fareplan_box_height = 10
        textbox = scribus.createText(hposition, vposition, cellsize / 2,
                                     fareplan_box_height)  # create a textbox.
        objectlist.append(textbox)
        scribus.insertText(fareplan_complete, 0,
                           textbox)  # insert the fareplan into the textbox.
        hposition = hposition + (cellsize / 2)  # Shift position of cell right.
        c = c + 1

        # Fare textbox
        textbox = scribus.createText(hposition, vposition, cellsize / 2,
                                     5)  # create a textbox.
        objectlist.append(textbox)
        scribus.insertText(fare, 0,
                           textbox)  # insert the fare into the textbox.
        c = c + 1

        if fare_onboard != '0.00':
            vposition = vposition + 5  # Shift position of cell down.
            textbox = scribus.createText(hposition, vposition, cellsize / 2,
                                         5)  # create a textbox.
            objectlist.append(textbox)
            scribus.setStyle('OnBoard', textbox)
            scribus.insertText(fare_onboard, 0,
                               textbox)  # insert the fare into the textbox.
            hposition = hposition - (cellsize / 2
                                     )  # Shift position of cell back.
            vposition = vposition + 5  # Shift position of cell down.
            c = c + 1
        else:
            hposition = hposition - (cellsize / 2
                                     )  # Shift position of cell back.
            vposition = vposition + 5  # Shift position of cell down.
        i = i + 1
        new_row_indication = 0
        new_page_indication = 0

    scribus.deselectAll()
    scribus.groupObjects(objectlist)
    scribus.progressReset()
    scribus.setUnit(userdim)  # reset unit to previous value
    scribus.docChanged(True)
    scribus.statusMessage("Done")
    scribus.setRedraw(True)
Example #20
0
def main(argv):

    scribus.setUnit(scribus.UNIT_MILLIMETERS)

    # get page size
    pagesize = scribus.getPageSize()

    ###########################################

    # size and position of the exit buttons
    linksize = pagesize[0] / 30
    linkpos = pagesize[0] - linksize - 2

    # set up exit to page
    pagenum = scribus.pageCount()
    exittopage = scribus.valueDialog(
        "Exit to page",
        "Exit buttons should go to page (1-" + str(pagenum) + ") :", "1")

    #error
    #if exittopage > pagenum:
    #    scribus.messageBox("Error", "This page doesn't exist.")
    #    sys.exit()

    # get active layer, create new layer for exit buttons, set it as active
    activelayer = scribus.getActiveLayer()
    scribus.createLayer("Exitbuttons")
    scribus.setActiveLayer("Exitbuttons")

    #progressbar max
    scribus.progressTotal(pagenum)

    # iterate through all the pages
    page = 1
    while (page <= pagenum):

        #messagebar text
        scribus.messagebarText("Create exit buttons...")

        scribus.progressSet(page)
        scribus.gotoPage(page)

        # create rectangle
        exitrect = scribus.createRect(linkpos, 2, linksize, linksize,
                                      "exitrect" + str(page))
        scribus.setFillColor("White", exitrect)

        # create text in rectangle
        exittext = scribus.createText(linkpos, 4, linksize, linksize,
                                      "exittext" + str(page))

        scribus.setText("X", exittext)
        scribus.setFontSize(20, exittext)
        scribus.setTextAlignment(1, exittext)

        # create link annotation
        exitlink = scribus.createText(linkpos, 2, linksize, linksize,
                                      "exitlink" + str(page))
        #setLinkAnnotation(page,x,y,["name"])
        scribus.setLinkAnnotation(int(exittopage), 0, 0, exitlink)

        # add page number to iteration
        page += 1

    # go back to active layer
    scribus.setActiveLayer(activelayer)
Example #21
0
def generateContent(string, window):

    #generates all the elements/only one element
    start = 0
    end = 0
    if string == "all":
        #dont include the first line to make the data sort work [1:]
        #sort the the elements by date
        data = sorted(getCSVdata()[1:],
                      key=lambda row: dateFun(str.strip(row[5])),
                      reverse=True)
        end = len(data)
        print(str(end) + "  " + str(start))
        print("generating elements from all lines")
        window.destroy()
    elif RepresentsInt(string):
        start = int(string) - 1  #index shifting
        end = int(string)
        print("only generating line " + string)
        data = getCSVdata()
        window.destroy()
    else:
        print(string + " is not a valid value")
        print("exiting")
        window.destroy()
        sys.exit()

    if not scribus.haveDoc() > 0:  #do we have a doc?
        scribus.messageBox("importcvs2table",
                           "No opened document.\nPlease open one first.")
        sys.exit()
    userdim = scribus.getUnit()  #get unit and change it to mm
    scribus.setUnit(scribus.UNIT_MILLIMETERS)

    lineWidth = 3.92  #aka 1.383mm, kp warum

    rowDate = ""
    for i in range(start, end):

        rowName = str.strip(data[i][0])
        rowCategory = str.strip(data[i][1])
        rowDescription = str.strip(data[i][2])
        rowPrice = str.strip(data[i][3])
        rowPlace = str.strip(data[i][4])
        rowDate = str.strip(data[i][5])
        rowTime = str.strip(data[i][6])

        if rowName == "":  #skip empty csv lines
            continue

        print("add element: " + rowName)

        #random values
        hpos = 120.0
        vpos = 200.0
        hposition = 120.0
        vposition = 200.0

        objectlist = []  #list for all boxes

        x = 0  #sets the progress
        #create the blue box
        print("create the blue line")
        blueBox = scribus.createLine(hposition + 1, vposition, hposition + 1,
                                     vposition + 5.863)
        scribus.setLineColor("Cyan", blueBox)
        scribus.setLineWidth(lineWidth, blueBox)
        objectlist.append(blueBox)
        scribus.progressSet(x)

        x = 1
        #create the data character box
        #these are the width values for the numbers
        zero = 4.608
        one = 2.839
        two = 4.724
        three = 4.393
        four = 4.625
        five = 4.261
        six = 4.278
        seven = 4.261
        eight = 4.625
        nine = 4.708

        lenArray = [zero, one, two, three, four, five, six, seven, eight, nine]

        marginleft = 1.3
        margintop = 0.519  #substract, cause the box is heigher that the blue line
        cellwidthright = 10.951
        cellHeight = 8.282
        hposition = hposition + marginleft + 1
        textbox = scribus.createText(hposition, vposition - margintop,
                                     cellwidthright, cellHeight)
        scribus.setFont("Quicksand Regular", textbox)
        scribus.setFontSize(20.0, textbox)
        finalDate = ""
        rowDateLength = 0
        #checks if the rowDate is from 01-09, in that case remove the zero
        if rowDate[0] == '0':
            finalDate = rowDate[1]
            rowDateLength = lenArray[int(rowDate[1])]

        else:
            finalDate = rowDate[:2]
            rowDateLength = lenArray[int(rowDate[0])] + lenArray[int(
                rowDate[1])]

        scribus.insertText(finalDate, 0, textbox)
        print("day: " + finalDate)
        objectlist.append(textbox)
        scribus.progressSet(x)

        x = 2
        #create the month/day box
        print("create the box with the day and month")
        width = 19.447
        height = 8.025
        marginleft = rowDateLength  #gain that from the calculations above, depends on the width of the rowDate characters

        monthBox = scribus.createText(hposition + marginleft + 0.7, vposition,
                                      width, height)
        scribus.setFont("Quicksand Regular", monthBox)
        scribus.setFontSize(8.5, monthBox)

        month = ""
        m = rowDate[3:5]
        if m == '01':
            month = "Januar"
        elif m == '02':
            month = "Februar"
        elif m == '03':
            month = "März"
        elif m == '04':
            month = "April"
        elif m == '05':
            month = "Mai"
        elif m == '06':
            month = "Juni"
        elif m == '07':
            month = "Juli"
        elif m == '08':
            month = "August"
        elif m == '09':
            month = "September"
        elif m == '10':
            month = "Oktober"
        elif m == '11':
            month = "November"
        elif m == '12':
            month = "Dezember"
        else:
            print("cant determine month!")

        day = datetime.date(int(rowDate[6:]), int(m),
                            int(rowDate[:2])).weekday()
        dayName = ""

        if day == 0:
            dayName = "Montag"
        elif day == 1:
            dayName = "Dienstag"
        elif day == 2:
            dayName = "Mittwoch"
        elif day == 3:
            dayName = "Donnerstag"
        elif day == 4:
            dayName = "Freitag"
        elif day == 5:
            dayName = "Samstag"
        elif day == 6:
            dayName = "Sonntag"
        else:
            print("cant determine day!")

        text = month + "\n" + dayName
        scribus.setStyle("Kalender_neu_Monat und Tag", monthBox)
        scribus.insertText(text, 0, monthBox)
        print("month: " + month + " day: " + dayName)
        objectlist.append(monthBox)
        scribus.progressSet(x)

        x = 3
        #create the main text box
        print("create the main text box")
        margintop = 5.5
        hpos = hpos - 0.383  #i dont know why but scribus always places the element 0.383 right than it should be :/
        mainTextBox = scribus.createText(
            hpos, vposition + margintop, 43.0,
            45.0)  #minus eins weil der blaue balken seinen kasten overflowed

        #insert category
        print("insert the category: " + rowCategory)
        scribus.insertText(rowCategory, 0, mainTextBox)
        endCategory = scribus.getTextLength(mainTextBox)
        scribus.selectText(0, endCategory, mainTextBox)
        scribus.setFontSize(10.5, mainTextBox)
        scribus.selectText(0, endCategory, mainTextBox)
        scribus.setStyle("Kalender_Eventname", mainTextBox)

        #insert main text
        print("insert the main text")
        scribus.insertText("\n" + rowDescription, endCategory, mainTextBox)
        endMainText = scribus.getTextLength(mainTextBox) - endCategory
        scribus.selectText(endCategory, endMainText, mainTextBox)
        scribus.setStyle("Kalender_Eventbeschreibung", mainTextBox)

        #get start length to color everything black and set font size
        startAll = scribus.getTextLength(mainTextBox)
        createPlaceTimePrice(mainTextBox, "\n| Ort: ", "",
                             "Kalender_Eventname")

        #insert value for place
        createPlaceTimePrice(mainTextBox, rowPlace, "Heuristica Regular", "")

        #insert time letters
        createPlaceTimePrice(mainTextBox, " | Zeit: ", "Quicksand Regular", "")

        #insert time value
        createPlaceTimePrice(mainTextBox, rowTime, "Heuristica Regular", "")

        #insert price letters
        createPlaceTimePrice(mainTextBox, " | Eintritt: ", "Quicksand Regular",
                             "")

        #insert price value
        createPlaceTimePrice(mainTextBox, rowPrice, "Heuristica Regular", "")

        #setFontSize and black color for the whole detail box
        endAll = scribus.getTextLength(mainTextBox) - startAll
        scribus.selectText(startAll, endAll, mainTextBox)
        scribus.setFontSize(8.5, mainTextBox)
        scribus.selectText(startAll, endAll, mainTextBox)
        scribus.setTextColor("Black", mainTextBox)

        objectlist.append(mainTextBox)
        scribus.progressSet(x)

        #do some generell stuff
        scribus.groupObjects(objectlist)
        scribus.progressReset()
        scribus.setUnit(userdim)  # reset unit to previous value
        scribus.docChanged(True)
        scribus.statusMessage("Done")
        scribus.setRedraw(True)

    print("done")
    return 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)
Example #23
0
if not hasLeftTopMark or not hasRightTopMark:
	scribus.messageBox('Error', "Document should have left_top_mark and right_top_mark or starts with left_top_mark_offset_ and right_top_mark_offset_ with suffix in mm to measure current spine width. Read more at https://litvinovg.pro/scribus-spine-width.html",  scribus.ICON_WARNING, scribus.BUTTON_OK)
	sys.exit(1)

newSpineWidth = scribus.valueDialog('Spine width','Set spine width in mm.')
if newSpineWidth == "0":
	scribus.messageBox('Error', "Spine width could not be zero.",  scribus.ICON_WARNING, scribus.BUTTON_OK)
	sys.exit(1)
newWidth = float(newSpineWidth.replace(',','.'))
if newWidth < 0:
	scribus.messageBox('Error', "Spine width could not be negative",  scribus.ICON_WARNING, scribus.BUTTON_OK)
	sys.exit(1)

#set units to mm
scribus.setUnit(1)
PageX,PageY = scribus.getPageSize()
leftX, leftY = scribus.getPosition(leftSpineMarker)
rightX, rightY = scribus.getPosition(rightSpineMarker)
curSpineWidth = rightX - leftX - leftOffset - rightOffset

spineWidthDiff = newWidth - curSpineWidth
halfWidthDiff = spineWidthDiff / 2 

vGuides = [(PageX/2), (PageX/2 + newWidth/2), (PageX/2 - newWidth/2)]
hGuides = []

for item in pageItems:
	if item[0].startswith('spine_background'):
		X,Y = scribus.getPosition(item[0])
		hasSpineBackground = True
def init():
    scribus.openDoc(pwd("init.sla"))
    scribus.saveDocAs("/tmp/{}.sla".format(time.time()))
    scribus.setUnit(scribus.UNIT_MM)
Example #25
0
numselect = scribus.selectionCount()
count = 0
frames = []

if numselect == 0:
    scribus.messageBox('Selection Count', "You must have at least one object selected",
                       scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(2)

captionloc = scribus.valueDialog("Caption Location","Where to put the caption(s) -\n B/T/R/L?", "b")
captionloc = captionloc[0]
location = captionloc.upper()

pageunits = scribus.getUnit()
scribus.setUnit(scribus.UNIT_POINTS)

while count < numselect:
    frames.append(scribus.getSelectedObject(count))
    count += 1
    
for frame in frames:
    fwidth, fheight = scribus.getSize(frame)
    fx, fy = scribus.getPosition(frame)
    if location == "B":
        textf = scribus.createText(fx, fy+fheight, fwidth, 24)
    elif location == "T":
        textf = scribus.createText(fx, fy-24, fwidth, 24)
    elif location == "R":
        textf = scribus.createText(fx + fwidth, fy, 150, 40)
    elif location == "L":
if not scribus.haveDoc():
    scribus.messageBox('Usage Error',
                       'You need a Document open',
                       icon=0,
                       button1=1)
    sys.exit(2)

if scribus.selectionCount() == 0:
    scribus.messageBox('Usage Error',
                       'You need to select a frame',
                       icon=0,
                       button1=1)
    sys.exit(2)

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

item = scribus.getSelectedObject()
size = scribus.getSize(item)
position = scribus.getPosition(item)

thickness = 3

items_border = []

items_border.append(
    scribus.createRect(position[0], position[1], size[0], thickness))
items_border.append(
    scribus.createRect(position[0], position[1], thickness, size[1]))
items_border.append(
Example #27
0
def init_config():
    scribus.setUnit(scribus.UNIT_MILLIMETERS)
Example #28
0
def init_config():
    scribus.setUnit(scribus.UNIT_MILLIMETERS)
    (margin_top, margin_left, margin_right, margin_bottom) = scribus.getPageNMargins(scribus.currentPage())
    print "left " + str(margin_left)
    print "right " + str(margin_right)
    (width, height) = scribus.getPageNSize(scribus.currentPage())
    print "width " + str(width)
    print "height " + str(height)
    cell_width = (width - (margin_left + margin_right) - (gap * (n - 1))) / n
    print cell_width
    guide = []
    previous_guide = margin_left
    for i in range(0, n - 1):
        guide.append(previous_guide + cell_width)
        guide.append(previous_guide + cell_width + gap)
        previous_guide = previous_guide + cell_width + gap
    scribus.setHGuides(guide)

unit_current=scribus.getUnit() #get unit and change it to mm
scribus.setUnit(scribus.UNIT_MILLIMETERS)

page = scribus.getPageSize()
margin = scribus.getPageMargins()

# scribus.setHGuides([10,20,30])

setGuidesColumn(6, 5)
setGuidesRow(4, 5)



scribus.setUnit(unit_current)
def main(argv):

    scribus.setUnit(scribus.UNIT_MILLIMETERS)

    # get page size and page count
    pagesize = scribus.getPageSize()
    pagenum = scribus.pageCount()

    #create on page
    selectedpage = scribus.valueDialog(
        "Select page", "Create arrows and annotation links on page (1-" +
        str(pagenum) + ") :", "1")

    # get active layer, create new layer for exit buttons, set it as active
    #activelayer = scribus.getActiveLayer()
    scribus.createLayer("Arrowlinks")
    scribus.setActiveLayer("Arrowlinks")

    #progressbar max
    scribus.progressTotal(pagenum)

    arrowinitxpos = 10
    arrowinitypos = 30

    scribus.gotoPage(int(selectedpage))

    page = 1
    ###########################################

    for i in range(pagenum):
        # create rectangle
        #exitrect = scribus.createRect(arrowinitxpos, 50, 30, 30, "exitrect")

        #messagebar text
        scribus.messagebarText(
            "Creating arrows and annotation links on page " + selectedpage +
            "...")

        #progress bar
        scribus.progressSet(page)

        #create and distribute arrow
        arrowpoly = [
            10, 30, 30, 10, 50, 30, 40, 30, 40, 50, 20, 50, 20, 30, 10, 30
        ]
        arrowup = scribus.createPolygon(arrowpoly)
        scribus.sizeObject(10, 10, arrowup)
        scribus.moveObjectAbs(arrowinitxpos, arrowinitypos, arrowup)
        scribus.setFillColor("White", arrowup)

        #create and distribute links
        arrowlink = scribus.createText(arrowinitxpos, arrowinitypos + 11, 10,
                                       10, "link_to_page_" + str(page))
        #setLinkAnnotation(page,x,y,["name"])
        scribus.setLinkAnnotation(int(page), 0, 0, arrowlink)

        arrowinitxpos += 11

        if arrowinitxpos > 250:
            arrowinitypos += 24
            arrowinitxpos = 10

        # add page number to iteration
        page += 1