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)
Пример #2
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
Пример #3
0
def copyPlayer(sourceName, destinationName):
    if scribus.objectExists(sourceName):
        doc = scribus.getDocName()
        unit = scribus.getUnit()
        (PageWidth, PageHeight) = scribus.getPageSize()
        (iT, iI, iO, iB) = scribus.getPageMargins()
        NewPagepoint = PageHeight - iT - iB
        player = scribus.selectObject(sourceName)
        #Duplicate the object...
        scribus.duplicateObject(sourceName)
        x = scribus.getSelectedObject()
        newObjectName = str(x)
        size = scribus.getSize(newObjectName)
        scribus.moveObject(0, size[1], newObjectName)
        (x, y) = scribus.getPosition(newObjectName)
        scribus.setRedraw(1)
        scribus.docChanged(1)
        if (y + size[1] > NewPagepoint):
            currentPage = scribus.currentPage()
            scribus.newPage(-1)
            newPage = currentPage + 1
            scribus.copyObject(newObjectName)
            scribus.deleteObject(newObjectName)
            scribus.gotoPage(newPage)
            scribus.pasteObject(newObjectName)
            scribus.moveObjectAbs(iO, iT, newObjectName)
        scribus.setNewName(destinationName, sourceName)
        scribus.setNewName(sourceName, newObjectName)
Пример #4
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)
Пример #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 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()
Пример #8
0
    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 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
Пример #10
0
def main(argv):
    unit = scribus.getUnit()
    units = [' pts', 'mm', ' inches', ' picas', 'cm', ' ciceros']
    unitlabel = units[unit]
    if scribus.selectionCount() == 0:
        scribus.messageBox(
            'Scribus - Script Error',
            "There is no object selected.\nPlease select a text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox(
            'Scribus - Script Error',
            "You have more than one object selected.\nPlease select one text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    textbox = scribus.getSelectedObject()
    pageitems = scribus.getPageItems()
    boxcount = 1
    for item in pageitems:
        if (item[0] == textbox):
            if (item[1] != 4):
                scribus.messageBox('Scribus - Script Error',
                                   "This is not a textframe. Try again.",
                                   scribus.ICON_WARNING, scribus.BUTTON_OK)
                sys.exit(2)


# While we're finding out what kind of frame is selected, we'll also make sure we
# will come up with a unique name for our infobox frame - it's possible we may want
# more than one for a multicolumn frame.
        if (item[0] == ("infobox" + str(boxcount) + textbox)):
            boxcount += 1
    left, top = scribus.getPosition(textbox)
    o_width, o_height = scribus.getSize(textbox)
    o_cols = int(scribus.getColumns(textbox))
    o_gap = scribus.getColumnGap(textbox)

    columns_width = 0
    column_pos = 0
    o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols
    if (o_cols > 1):
        while (columns_width > o_cols or columns_width < 1):
            columns_width = scribus.valueDialog(
                'Width', 'How many columns width shall the ' + 'box be (max ' +
                str(o_cols) + ')?', '1')
            columns_width = int(columns_width)
        if (columns_width < o_cols):
            max = o_cols - columns_width
            while (column_pos <= max and column_pos <= 1):
                column_pos = scribus.valueDialog(
                    'Placement', 'In which column do you want '
                    'to place the box (1 to ' + str(o_cols) + ')?', '1')
            column_pos = int(column_pos) - 1
    if (o_cols == 1):
        columns_width = 1
    new_height = 0
    while (new_height <= 0):
        new_height = scribus.valueDialog(
            'Height', 'Your frame height is ' + str(o_height) + unitlabel +
            '. How tall\n do you want your ' + 'infobox to be in ' +
            unitlabel +
            '?\n If you load an image with the script, height will be\n calculated, so the value here will not\n matter in that case.',
            str(o_height))
        if (not new_height):
            sys.exit(0)
        new_height = float(new_height)
    new_top = -1
    while (new_top < 0):
        new_top = scribus.valueDialog(
            'Y-Pos',
            'The top of your infobox is currently\n' + str(top) + unitlabel +
            '. Where do you want \n' + 'the top to be in ' + unitlabel + '?',
            str(top))
        if (not new_top):
            sys.exit(0)
        new_top = float(new_top)
    framename = scribus.valueDialog(
        'Name of Frame', 'Name your frame or use this default name',
        "infobox" + str(boxcount) + textbox)
    if (not framename):
        sys.exit(0)
    frametype = 'text'
    frametype = scribus.valueDialog(
        'Frame Type',
        'Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image',
        frametype)
    if (not frametype):
        sys.exit(0)
    new_width = columns_width * o_colwidth + (columns_width - 1) * o_gap
    new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap)
    if (frametype == 'text'):
        new_textbox = scribus.createText(new_left, float(new_top), new_width,
                                         float(new_height), framename)
        scribus.setColumnGap(0, new_textbox)
        scribus.setColumns(1, new_textbox)
        scribus.textFlowMode(new_textbox, 1)
    else:
        if (frametype == 'imageL'):
            imageload = scribus.fileDialog(
                'Load image',
                'Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',
                haspreview=1)
            new_image = scribus.createImage(new_left,
                                            float(new_top), new_width,
                                            float(new_height), framename)
            scribus.textFlowMode(new_image, 1)
            scribus.loadImage(imageload, new_image)
            scribus.setScaleImageToFrame(1, 0, new_image)
            currwidth, currheight = scribus.getSize(new_image)
            Xscale, Yscale = scribus.getImageScale(new_image)
            if (Xscale != Yscale):
                scribus.sizeObject(currwidth, currheight * Xscale / Yscale,
                                   new_image)
            scribus.setScaleImageToFrame(1, 1, new_image)
        else:
            new_image = scribus.createImage(new_left,
                                            float(new_top), new_width,
                                            float(new_height), framename)
            scribus.textFlowMode(new_image, 1)
            scribus.setScaleImageToFrame(1, 1, new_image)
Пример #11
0
    sys.exit(1)

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)
Пример #12
0
def debug(label, value=''):
    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',
Пример #13
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)
Пример #14
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
Пример #15
0
def main(argv):

    unit = scribus.getUnit()
    units = [' pts','mm',' inches',' picas','cm',' ciceros']
    unitlabel = units[unit]
    if scribus.selectionCount() == 0:
        scribus.messageBox('Scribus - Script Error',
            "There is no object selected.\nPlease select a text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox('Scribus - Script Error',
            "You have more than one object selected.\nPlease select one text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)

    textbox = scribus.getSelectedObject()
    pageitems = scribus.getPageItems()
    boxcount = 1
    for item in pageitems:
        if (item[0] == textbox):
            if (item[1] != 4):
                scribus.messageBox('Scribus - Script Error', 
                          "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
                sys.exit(2)

# While we're finding out what kind of frame is selected, we'll also make sure we
# will come up with a unique name for our infobox frame - it's possible we may want
# more than one for a multicolumn frame.
        if (item[0] == ("infobox" + str(boxcount) + textbox)):
                boxcount += 1

    elem = textbox;
    pathUp = '';
    pathUpShort = "";

    while elem != None:
        elemId = getElemId(elem);
        pElemId = getParentElemId(elem);

        text = scribus.getText(elem);
        if (text.find("Holder")!=-1):
            text = "";
        
        pathUpShort = "<" + getElemName(elem) + " id=\"" + str(getElemId(elem)) + "\">" + text + "\n" + pathUpShort;
        pathUp = dumpElem(elem) + " // " +  pathUp;
        elem = findElemById(pElemId);

    if (pathUp != ''):
        pathUp = pathUp[0:len(pathUp)-4];
    if (pathUpShort != ''):
        pathUpShort = pathUpShort[0:len(pathUpShort)-1];

    #framename = scribus.valueDialog('XML Tree','XML Tree', elemName + '[@id=' + elemId + '] parent: ' + parent + ' text:' + text + "," + parent)
    #scribus.messagebarText("It works !!!");
    scribus.statusMessage(pathUp);
    #scribus.zoomDocument(200);
    #scribus.selectFrameText(0,100);
    #framename = scribus.valueDialog('XML Tree','XML Tree (Path UP)', pathUp);

    #t = scribus.qApp.mainWidget();
    
    #if (not framename) :
    #    sys.exit(0)
    #scribus.messageBox('XML struct',
    #        pathUp + "\n\n" + pathUpShort,
    #        scribus.ICON_WARNING, scribus.BUTTON_OK)

    #impl = getDOMImplementation();
    #newdoc = impl.createDocument(None, "root", None);

    newdoc = createDOMDocument();
    #xmlelem = createDOMElement(newdoc, root);
    #newdoc.documentElement.appendChild(xmlelem);
    x = newdoc.toxml();
    #x = str(dir(root));

    scribus.structview(x);
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]))
def main(argv):
    unit = scribus.getUnit()
    units = ['pts','mm','inches','picas','cm','ciceros']
    unitlabel = units[unit]
    
# get page size
    pagesize = scribus.getPageSize()

    
# ask for layout style
    layout_style = scribus.valueDialog("Select Mirror", layout_text, "v")
    if layout_style == "":
        sys.exit()

        

# v = vertical mirror
    if layout_style == "v":            
        # warn and exit if no selection
        if scribus.selectionCount() == 0:
            scribus.messageBox("Error", "Select an object first!", icon=scribus.ICON_WARNING)
            sys.exit()
        
        #create mirror guides
        scribus.setVGuides(scribus.getHGuides() + [pagesize[0]/2])
        
        #get selected object
        selection_name = scribus.getSelectedObject(0)
        objectpos = scribus.getPosition(selection_name)
        objectsize = scribus.getSize(selection_name)
        
        #duplicate object
        scribus.duplicateObject(selection_name)
        
        #move object
        newobjectpos = (pagesize[0] - (objectpos[0] + objectsize[0]) , objectpos[1])
        scribus.moveObjectAbs(newobjectpos[0], objectpos[1], selection_name)
        
        #flip object
        scribus.flipObject(1,0,selection_name)

        

# h = horizontal mirror
    if layout_style == "h":            
        # warn and exit if no selection
        if scribus.selectionCount() == 0:
            scribus.messageBox("Error", "Select an object first!", icon=scribus.ICON_WARNING)
            sys.exit()
        
        #create mirror guides
        scribus.setHGuides(scribus.getHGuides() + [pagesize[1]/2])
        
        #get selected object
        selection_name = scribus.getSelectedObject(0)
        objectpos = scribus.getPosition(selection_name)
        objectsize = scribus.getSize(selection_name)
        
        #duplicate object
        scribus.duplicateObject(selection_name)
        
        #move object
        newobjectpos = (objectpos[0] , pagesize[1] - (objectpos[1] + objectsize[1]))
        scribus.moveObjectAbs(objectpos[0], newobjectpos[1], selection_name)
        
        #flip object
        scribus.flipObject(0,1,selection_name)
Пример #18
0
def main(argv):
    unit = scribus.getUnit()
    units = [' pts','mm',' inches',' picas','cm',' ciceros']
    unitlabel = units[unit]
    if scribus.selectionCount() == 0:
        scribus.messageBox('Scribus - Script Error',
            "There is no object selected.\nPlease select a text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox('Scribus - Script Error',
            "You have more than one object selected.\nPlease select one text frame and try again.",
            scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    textbox = scribus.getSelectedObject()
    pageitems = scribus.getPageItems()
    boxcount = 1
    for item in pageitems:
        if (item[0] == textbox):
            if (item[1] != 4):
                scribus.messageBox('Scribus - Script Error', 
                          "This is not a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
                sys.exit(2)

# While we're finding out what kind of frame is selected, we'll also make sure we
# will come up with a unique name for our infobox frame - it's possible we may want
# more than one for a multicolumn frame.
        if (item[0] == ("infobox" + str(boxcount) + textbox)):
                boxcount += 1
    left, top = scribus.getPosition(textbox)
    o_width, o_height = scribus.getSize(textbox)
    o_cols = int(scribus.getColumns(textbox))
    o_gap = scribus.getColumnGap(textbox)
            
    columns_width = 0
    column_pos = 0
    o_colwidth = (o_width - ((o_cols - 1) * o_gap)) / o_cols
    if (o_cols > 1):
        while (columns_width > o_cols or columns_width < 1):
            columns_width = scribus.valueDialog('Width',
                                            'How many columns width shall the '+
                                            'box be (max ' + str(o_cols) + ')?','1')
            columns_width = int(columns_width)
        if (columns_width < o_cols):
            max = o_cols - columns_width
            while (column_pos <= max and column_pos <= 1):
                column_pos = scribus.valueDialog('Placement',
                                         'In which column do you want '
                                         'to place the box (1 to ' +
                                         str(o_cols) + ')?','1')
            column_pos = int(column_pos) - 1 
    if (o_cols == 1):
	columns_width = 1
    new_height = 0
    while (new_height == 0):
        new_height = scribus.valueDialog('Height','Your frame height is '+ str(o_height) +
                                                 unitlabel +'. How tall\n do you want your ' +
                                                 'infobox to be in '+ unitlabel +'?\n If you load an image, height will be\n calculated, so the value here does not\n matter.', str(o_height))
    new_top = -1
    while (new_top < 0):
        new_top = scribus.valueDialog('Y-Pos','The top of your infobox is currently\n'+ str(top) +
                                                 unitlabel +'. Where do you want \n' +
                                                 'the top to be in '+ unitlabel +'?', str(top))
    framename = scribus.valueDialog('Name of Frame','Name your frame or use this default name',"infobox" + str(boxcount) + textbox)
    frametype = 'text'
    frametype = scribus.valueDialog('Frame Type','Change to anything other\n than "text" for image frame.\nEnter "imageL" to also load an image',frametype)
    new_width = columns_width * o_colwidth + (columns_width-1) * o_gap
    new_left = left + ((column_pos) * o_colwidth) + ((column_pos) * o_gap)
    if (frametype == 'text'):
        new_textbox = scribus.createText(new_left, float(new_top), new_width, float(new_height),framename)
        scribus.setColumnGap(0, new_textbox)
        scribus.setColumns(1, new_textbox)
        scribus.textFlowMode(new_textbox, 1)
    else:
        if (frametype == 'imageL'):
	    imageload = scribus.fileDialog('Load image','Images(*.jpg *.png *.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',haspreview=1)
	    new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename)
	    scribus.loadImage(imageload, new_image)
            scribus.messageBox('Please Note',"Your frame will be created once you click OK.\n\nUse the Context Menu to Adjust Frame to Image.\n\nIf your image does not fill the width completely,\nstretch the frame vertically first.",scribus.BUTTON_OK)
        else:
	    new_image = scribus.createImage(new_left, float(new_top), new_width, float(new_height),framename)
        scribus.textFlowMode(new_image, 1)
        scribus.setScaleImageToFrame(scaletoframe=1, proportional=1, name=new_image)
Пример #19
0
def main(argv):
    unit = scribus.getUnit()
    units = ['pts', 'mm', 'inches', 'picas', 'cm', 'ciceros']
    unitlabel = units[unit]

    #layout_style = ""
    #frame = 3
    #border = 3

    # layout style
    layout_style = scribus.valueDialog("Layout Style", layout_text, mylayout)

    if layout_style == "h":
        scribus.messageBox("Help", help_text)
        sys.exit()

    if layout_style == "v":
        createDefaultVal()
        sys.exit()
    if layout_style == "":
        sys.exit()

# frame
    frame_str = scribus.valueDialog(
        "Set Page Frame", "Set page frame size (" + unitlabel +
        ") :\n(positive for page margin,\nnegative for page bleed)\n", myframe)

    if frame_str != "":
        frame = float(frame_str)
    else:
        sys.exit()

# border
    if int(layout_style) > 1:
        border_str = scribus.valueDialog(
            "Add Image Border",
            "Add border around images (" + unitlabel + ") :\n", myborder)
        if border_str != "":
            border = float(border_str)
        else:
            sys.exit()
    else:
        border = 0

    bleed = -frame

    # get page size
    xysize = scribus.getPageSize()
    size = (xysize[0] + 2 * bleed, xysize[1] + 2 * bleed)
    #scribus.createImage(0, 0, size[0]/2, size[1]/2)

    # layouts
    # one image on two pages (put it on the left page)
    if layout_style == "0":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            (size[0] * 2) - border - bleed * 2,
                            size[1] - border)

# one image on one full page
    if layout_style == "1":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] - border * 2, size[1] - border * 2)

# two vertical images
    if layout_style == "2":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] - border * 2)

        #guides
        scribus.setVGuides(
            [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed])
        #scribus.setHGuides([size[1]/2-border-bleed, size[1]/2+border-bleed])

# two horizontal images
    if layout_style == "22":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed,
                            size[0] - border * 2, size[1] / 2 - border * 2)

        #guides
        #scribus.setVGuides([size[0]/2-border-bleed, size[0]/2+border-bleed])
        scribus.setHGuides(
            [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed])

# one vertical image left, two horizontal images right
    if layout_style == "3":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed,
                            size[1] / 2 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)

        #guides
        scribus.setVGuides(
            [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed])
        scribus.setHGuides(
            [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed])

# one vertical image left, two horizontal images right
    if layout_style == "33":
        scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] - border * 2)
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)

        #guides
        scribus.setVGuides(
            [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed])
        scribus.setHGuides(
            [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed])

# one image on top, two images on bottom
    if layout_style == "333":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed,
                            size[1] / 2 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)

        #guides
        scribus.setVGuides(
            [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed])
        scribus.setHGuides(
            [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed])

# one image on top, two images on bottom
    if layout_style == "3333":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed,
                            size[0] - border * 2, size[1] / 2 - border * 2)

        #guides
        scribus.setVGuides(
            [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed])
        scribus.setHGuides(
            [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed])

# four horizontal images
    if layout_style == "4":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed,
                            size[1] / 2 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 2 - border * 2)

        #guides
        scribus.setVGuides(
            [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed])
        scribus.setHGuides(
            [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed])

# six images 3 + 3
    if layout_style == "6":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(size[0] / 3 + border - bleed, 0 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage((size[0] / 3) * 2 + border - bleed,
                            0 + border - bleed, size[0] / 3 - border * 2,
                            size[1] / 2 - border * 2)
        scribus.createImage(0 + border - bleed, size[1] / 2 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage(size[0] / 3 + border - bleed,
                            size[1] / 2 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 2 - border * 2)
        scribus.createImage((size[0] / 3) * 2 + border - bleed,
                            size[1] / 2 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 2 - border * 2)

        #guides
        scribus.setVGuides([
            size[0] / 3 - border - bleed, size[0] / 3 - bleed + border,
            (size[0] / 3) * 2 - border - bleed,
            (size[0] / 3) * 2 + border - bleed
        ])
        scribus.setHGuides(
            [size[1] / 2 - border - bleed, size[1] / 2 + border - bleed])

# six images 2 +2 + 2
    if layout_style == "66":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed, 0 + border - bleed,
                            size[0] / 2 - border * 2,
                            (size[1] / 3) - border * 2)
        scribus.createImage(0 + border - bleed, size[1] / 3 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed,
                            size[1] / 3 + border - bleed,
                            size[0] / 2 - border * 2,
                            (size[1] / 3) - border * 2)
        scribus.createImage(0 + border - bleed,
                            (size[1] / 3) * 2 + border - bleed,
                            size[0] / 2 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage(size[0] / 2 + border - bleed,
                            (size[1] / 3) * 2 + border - bleed,
                            size[0] / 2 - border * 2,
                            (size[1] / 3) - border * 2)

        #guides
        scribus.setVGuides(
            [size[0] / 2 - border - bleed, size[0] / 2 + border - bleed])
        scribus.setHGuides([
            size[1] / 3 - border - bleed, size[1] / 3 + border - bleed,
            (size[1] / 3) * 2 - border - bleed,
            (size[1] / 3) * 2 + border - bleed
        ])


# nine images
    if layout_style == "9":
        scribus.createImage(0 + border - bleed, 0 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage(size[0] / 3 + border - bleed, 0 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage((size[0] / 3) * 2 + border - bleed,
                            0 + border - bleed, size[0] / 3 - border * 2,
                            size[1] / 3 - border * 2)
        scribus.createImage(0 + border - bleed, size[1] / 3 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage(size[0] / 3 + border - bleed,
                            size[1] / 3 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage((size[0] / 3) * 2 + border - bleed,
                            size[1] / 3 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage(0 + border - bleed,
                            (size[1] / 3) * 2 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage(size[0] / 3 + border - bleed,
                            (size[1] / 3) * 2 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 3 - border * 2)
        scribus.createImage((size[0] / 3) * 2 + border - bleed,
                            (size[1] / 3) * 2 + border - bleed,
                            size[0] / 3 - border * 2, size[1] / 3 - border * 2)

        #guides
        scribus.setVGuides([
            size[0] / 3 - border - bleed, size[0] / 3 - bleed + border,
            (size[0] / 3) * 2 - border - bleed,
            (size[0] / 3) * 2 + border - bleed
        ])
        scribus.setHGuides([
            size[1] / 3 - border - bleed, size[1] / 3 + border - bleed,
            (size[1] / 3) * 2 - border - bleed,
            (size[1] / 3) * 2 + border - bleed
        ])
Пример #20
0
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)
def main(argv):
    if not scribus.haveDoc():
        sys.exit(1)

    os.chdir(os.path.expanduser("~"))

     ####
     ####  If you have a different location of your laidout program change it here:
     ####
    laidoutexecutable="/usr/bin/laidout"
    
    if os.path.exists(laidoutexecutable)==False:
        laidoutexecutable="/usr/local/bin/laidout"
    if os.path.exists(laidoutexecutable)==False:
        print "Could not find Laidout!"
        print "Please change scribus-call-laidout-to-impose-gui.py to have a correct path!"
        #scribus.messageBox("Could not find Laidout!",
        #                   "Please change line 37 in scribus-call-laidout-to-impose-gui.py to have a correct path!")
        #laidoutexecutable=scribus.valueDialog("Laidout path","You do not appear to have Laidout installed! Please enter a valid path for running Laidout","/usr/bin/laidout")
        laidoutexecutable=scribus.fileDialog('Please locate Laidout executable!!', defaultname='/usr/bin/laidout', issave=False)
        print "New laidout executable path: "+laidoutexecutable

     #fail if still not found
    if os.path.exists(laidoutexecutable)==False:
        scribus.messageBox("Could not find Laidout!",
                           "Please either change line for \'laidoutexecutable=\"/usr/bin/laidout\"\' in scribus-call-laidout-to-impose-gui.py"
                           " to have a correct path, or enter a valid path.")
        sys.exit(1)
        

    thecommand=""
    infile=os.getcwd()+"/this-is-a-temporary-file.sla"  #note this saves to a very random area usually!!
    reimposed=os.getcwd()+"/this-is-reimposed-from-laidout.sla" #  seems like directory of the plugin

    #infile =tempfile.NamedTemporaryFile()  <-- maybe this can be used instead?? how to create, get filename, then let laidout open??
    #outfile=tempfile.NamedTemporaryFile()  <-- maybe this can be used instead??

    size=scribus.getPageSize()
    units=scribus.getUnit()
    width=0
    height=0
    print "size "+str(size[0])+","+str(size[1])
    print "units "+str(units)
    if (units==scribus.UNIT_MILLIMETERS):
        width=size[0]/10/2.54
        height=size[1]/10/2.54
    elif (units==scribus.UNIT_PICAS):
        width=size[0]/6
        height=size[1]/6
    elif (units==scribus.UNIT_POINTS):
        width=size[0]/72
        height=size[1]/72
    elif (units==scribus.UNIT_INCHES):
        width=size[0]
        height=size[1]
    else:
        print "unknown units!!!"
        scribus.messageBox("Unknown units!","For some reason, scribus.getUnit() did not return units known to this script!"
                                            "This is probably a bug with the script.")

    #thecommand="/bin/ls"
    thecommand=laidoutexecutable+" --impose-only " \
                         +"'in=\""+infile+"\" " \
                         +" out=\""+reimposed+"\" " \
                         +" prefer=\"booklet\"" \
                         +" width=\""+str(width)+"\"" \
                         +" height=\""+str(height)+"\"" \
                         +"'"
    #print "command:\n", thecommand

    try:
        print "Creating temporary file ",infile,"..."
        scribus.saveDocAs(infile)
    except:
        print "Could not save as ",infile
        sys.exit(1)


    try:
        print "Trying: "+thecommand
        os.system(thecommand)

    except:
        print "An error occured trying to run the system command:\n",thecommand
        sys.exit(1)

    if os.path.exists(reimposed)==False:
        print "Reimposed file was not generated!"
        sys.exit(1)

    #scribus.closeDoc() #closes the "original" document, which has been rename to infile upon saveDocAs()
    scribus.openDoc(reimposed) #open the brand spanking new reimposed document

    #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- might cause problems, but keep around for research
    print "Removing temporary file ",infile,"..."
    os.remove(infile)
    print "All done!"
Пример #22
0
def main(argv):
    if not scribus.haveDoc():
        sys.exit(1)

    os.chdir(os.path.expanduser("~"))

    ####
    ####  If you have a different location of your laidout program change it here:
    ####
    laidoutexecutable = "/usr/bin/laidout"

    if os.path.exists(laidoutexecutable) == False:
        laidoutexecutable = "/usr/local/bin/laidout"

    if os.path.exists(laidoutexecutable) == False:
        print "Could not find Laidout!"
        print "Please change scribus-call-laidout-to-impose-gui.py to have a correct path!"
        #scribus.messageBox("Could not find Laidout!",
        #                   "Please change line 37 in scribus-call-laidout-to-impose-gui.py to have a correct path!")
        #laidoutexecutable=scribus.valueDialog("Laidout path","You do not appear to have Laidout installed! Please enter a valid path for running Laidout","/usr/bin/laidout")
        laidoutexecutable = scribus.fileDialog(
            'Please locate Laidout executable!!',
            defaultname='/usr/bin/laidout',
            issave=False)
        print "New laidout executable path: " + laidoutexecutable

    #fail if still not found
    if os.path.exists(laidoutexecutable) == False:
        scribus.messageBox(
            "Could not find Laidout!",
            "Please either change line for \'laidoutexecutable=\"/usr/bin/laidout\"\' in scribus-call-laidout-to-impose-gui.py"
            " to have a correct path, or enter a valid path.")
        sys.exit(1)

    thecommand = ""
    infile = os.getcwd(
    ) + "/this-is-a-temporary-file.sla"  #note this saves to a very random area usually!!
    reimposed = os.getcwd(
    ) + "/this-is-reimposed-from-laidout.sla"  #  seems like directory of the plugin

    #infile =tempfile.NamedTemporaryFile()  <-- maybe this can be used instead?? how to create, get filename, then let laidout open??
    #outfile=tempfile.NamedTemporaryFile()  <-- maybe this can be used instead??

    size = scribus.getPageSize()
    units = scribus.getUnit()
    width = 0
    height = 0
    print "size " + str(size[0]) + "," + str(size[1])
    print "units " + str(units)
    if (units == scribus.UNIT_MILLIMETERS):
        width = size[0] / 10 / 2.54
        height = size[1] / 10 / 2.54
    elif (units == scribus.UNIT_PICAS):
        width = size[0] / 6
        height = size[1] / 6
    elif (units == scribus.UNIT_POINTS):
        width = size[0] / 72
        height = size[1] / 72
    elif (units == scribus.UNIT_INCHES):
        width = size[0]
        height = size[1]
    else:
        print "unknown units!!!"
        scribus.messageBox(
            "Unknown units!",
            "For some reason, scribus.getUnit() did not return units known to this script!"
            "This is probably a bug with the script.")

    #thecommand="/bin/ls"
    thecommand=laidoutexecutable+" --impose-only " \
                         +"'in=\""+infile+"\" " \
                         +" out=\""+reimposed+"\" " \
                         +" prefer=\"booklet\"" \
                         +" width=\""+str(width)+"\"" \
                         +" height=\""+str(height)+"\"" \
                         +"'"
    #print "command:\n", thecommand

    try:
        print "Creating temporary file ", infile, "..."
        scribus.saveDocAs(infile)
    except:
        print "Could not save as ", infile
        sys.exit(1)

    try:
        print "Trying: " + thecommand
        os.system(thecommand)

    except:
        print "An error occured trying to run the system command:\n", thecommand
        sys.exit(1)

    if os.path.exists(reimposed) == False:
        print "Reimposed file was not generated!"
        sys.exit(1)

    #scribus.closeDoc() #closes the "original" document, which has been rename to infile upon saveDocAs()
    scribus.openDoc(reimposed)  #open the brand spanking new reimposed document

    #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- might cause problems, but keep around for research
    print "Removing temporary file ", infile, "..."
    os.remove(infile)
    print "All done!"
    (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)
Пример #24
0
def main(argv):
    unit = scribus.getUnit()
    units = ['pts', 'mm', 'inches', 'picas', 'cm', 'ciceros']
    unitlabel = units[unit]

    # get page size
    xysize = scribus.getPageSize()

    # ask for layout style
    layout_style = scribus.valueDialog("Guides Layout", layout_text, "1")
    if layout_style == "":
        sys.exit()

# 0 = erase all guides
    if layout_style == "0":
        #guides
        scribus.setVGuides([])
        scribus.setHGuides([])
        sys.exit()

# 1 = guides around page
    if layout_style == "1":
        # set guides distance
        pageguides_str = scribus.valueDialog(
            "Create Guides around Page",
            "Set distance to page borders (" + unitlabel +
            ") :\n\n- positive (e.g. 3) for page margin\n\n- negative (e.g. -3) for page bleed\n",
            "3")
        if pageguides_str != "":
            pageguides = float(pageguides_str)
        else:
            sys.exit()

        #set guides
        scribus.setVGuides(scribus.getVGuides() +
                           [pageguides, xysize[0] - pageguides])
        scribus.setHGuides(scribus.getHGuides() +
                           [pageguides, xysize[1] - pageguides])

# 2 = guides around selected object
    if layout_style == "2":
        # set guides distance
        objectguides_str = scribus.valueDialog(
            "Create Guides around selected Objects",
            "Set distance to object borders (" + unitlabel +
            ") :\n\n- 0 for around the object borders\n\n- positive (e.g. 3) towards inside the object\n\n- negative (e.g. -3) towards outside the object\n",
            "0")
        if objectguides_str != "":
            objectguides = float(objectguides_str)
        else:
            sys.exit()

        if scribus.selectionCount() == 0:
            scribus.messageBox("Error",
                               "Select an object first !",
                               icon=scribus.ICON_WARNING)
            sys.exit()

        #get selected object
        selection_name = scribus.getSelectedObject(0)
        objectpos = scribus.getPosition(selection_name)
        objectsize = scribus.getSize(selection_name)

        #set guides
        scribus.setVGuides(scribus.getVGuides() + [
            objectpos[0] + objectguides, objectpos[0] + objectsize[0] -
            objectguides
        ])
        scribus.setHGuides(scribus.getHGuides() + [
            objectpos[1] + objectguides, objectpos[1] + objectsize[1] -
            objectguides
        ])