Beispiel #1
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  #
    #########################
    #copyPlayer("__player__","PLAYER 1")
    #copyPlayer("__player__","PLAYER 2")
    #copyPlayer("__player__","PLAYER 3")
    csv = scribus.fileDialog('Open input', 'CSV files (*.csv)')
    stuff = {
        'NAME': 'Mike Hingley',
        'ADDRESS': '22 Trinity Street, Cradley Heath, West Midlands',
        'PHOTO': '128.jpg'
    }
    print(os.path.dirname(os.path.realpath(sys.argv[0])))
    print os.getcwd()
    print(sys.path[0])
    print(os.path.abspath(''))
    sourceName = "__player__"
    if scribus.objectExists(sourceName):
        scribus.selectObject(sourceName)
        scribus.unGroupObject()
        childObjectCount = scribus.selectionCount()
        for x in range(0, childObjectCount):
            element = scribus.getSelectedObject(x)
            if scribus.getObjectType(str(element)) == 'TextFrame':
                current = scribus.getAllText(element)
                if current in stuff:
                    fontsize = scribus.getFontSize(element)
                    font = scribus.getFont(element)
                    scribus.setText(stuff[current], element)
                    scribus.setFont(font)
                    scribus.setFontSize(fontsize)
            if scribus.getObjectType(str(element)) == 'ImageFrame':
                current = scribus.getImageFile(element)
                currentName = os.path.basename(os.path.normpath(current))
                print current
                print currentName
                if currentName in stuff:
                    ExistingFolder = os.path.split(current)
                    print ExistingFolder[0]
                    newFile = os.path.join(ExistingFolder[0],
                                           stuff[currentName])
                    print newFile
                    scribus.loadImage(newFile, element)
            print scribus.getObjectType(str(element))
            print str(scribus.getSelectedObject(x))
        scribus.groupObjects()
        print "name = " + scribus.getSelectedObject()
        scribus.setNewName("__player__", scribus.getSelectedObject())
    def run(self):
        selCount = scribus.selectionCount()
        if selCount == 0:
            scribus.messageBox('Scribus Data Merger- Usage Error',
                               "There is no objects selected.\nPlease try again.",
                               scribus.ICON_WARNING, scribus.BUTTON_OK)
            sys.exit(2)

        csvData = self.loadCsvData()

        # Create a list with the names of the selected objects:
        selectedObjects = []

        # Loop through the selected objects and put their names into the list selectedObjects
        o = 0 
        while (o < selCount):
            selectedObjects.append(scribus.getSelectedObject(o))
            o = o + 1

        startingPage = scribus.currentPage()
        lastRow = len(csvData)
        if(self.__dataObject.getNumberOfLinesToMerge() != 'All'):
            lastRow = int(self.__dataObject.getNumberOfLinesToMerge())
        lastRow = min(lastRow, len(csvData)) # This will prevent the script from trying to merge data from non-existing rows in the data file
        currentPage = scribus.currentPage()
        rowNumber = 0
        insertPageBeforeThis = -1
        while (rowNumber < lastRow):
            if(scribus.pageCount() > currentPage):
                insertPageBeforeThis = currentPage + 1
            scribus.newPage(insertPageBeforeThis) # Inserts a page before the page given as an argument
            currentPage = currentPage + 1

            for selectedObject in selectedObjects: # Loop through the names of all the selected objects
                scribus.gotoPage(startingPage) # Set the working page to the one we want to copy objects from 
                scribus.copyObject(selectedObject)
                scribus.gotoPage(currentPage)
                scribus.pasteObject() # Paste the copied object on the new page

            scribus.docChanged(1)
            scribus.gotoPage(currentPage) # Make sure ware are on the current page before we call getAllObjects()
            newPageObejcts = scribus.getAllObjects()

            for pastedObject in newPageObejcts: # Loop through all the items on the current page
                objType = scribus.getObjectType(pastedObject)
                text = CONST.EMPTY
                if(objType == 'TextFrame'):
                    text = scribus.getAllText(pastedObject) # This should have used getText but getText does not return the text values of just pasted objects
                    text = self.replaceText(csvData[rowNumber], text)
                    scribus.setText(text, pastedObject)
                if(objType == 'ImageFrame'):
                    text = scribus.getImageFile(pastedObject)
                    # self.info("Image text", text)
                    # Todo: Find out if it is possible to replace text in the ImageFile property
                          
            rowNumber = rowNumber + 1
     
        scribus.setRedraw(1)
        scribus.docChanged(1)
        scribus.messageBox("Merge Completed", "Merge Completed", icon=scribus.ICON_INFORMATION, button1=scribus.BUTTON_OK)
def main():
    # haben wir ein Dokument geoeffnet
    if scribus.haveDoc():
        # haben wir in diesem Dokument genau *ein* Objekt markiert
        if (scribus.selectionCount() == 1):
            # Ist dieses Objekt ein Bild, dann
            if (scribus.getObjectType() == "ImageFrame"):
                # lese den vollstaendigen Namen der datei (inkl. Pfad) in die Variable name
                name = scribus.getImageFile()
                # bastele einen neuen Namen aus dem Pfad, %VAR_ und dem Objektnamen und schreibe ihn als Standardwert in den Dialog
                newname = scribus.valueDialog(
                    os.path.split(name)[1] +
                    " wird ersetzt durch %VAR_[name]%",
                    "Variablenname ergänzen: ",
                    os.path.split(name)[0] + "/%VAR_" +
                    scribus.getSelectedObject() + "%")
                # uebernehme den Wert aus dem Dialogfenster (keine plausibilitaetspruefung. das ist ein beliebiger String
                scribus.loadImage(newname)
            else:
                scribus.messageBox("Fehler",
                                   "markierter Frame ist kein Bildrahmen",
                                   scribus.ICON_CRITICAL)
        else:
            scribus.messageBox("Fehler", "bitte *einen* Bildrahmen markieren",
                               scribus.ICON_CRITICAL)
    else:
        scribus.messageBox("Fehler", "kein Dokument geöffnet",
                           scribus.ICON_CRITICAL)
Beispiel #4
0
    def __init__(self):
        if not scribus.haveDoc():
            scribus.messageBox('Scribus - Script Error', "No document open", scribus.ICON_WARNING, scribus.BUTTON_OK)
            sys.exit(1)

        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)

        self.textbox = scribus.getSelectedObject()
        ftype = scribus.getObjectType(self.textbox)

        if ftype != "TextFrame":
            scribus.messageBox('Scribus - Script Error', "This is not a textframe. Try again.", scribus.ICON_WARNING,
                               scribus.BUTTON_OK)
            sys.exit(2)

        scribus.deleteText(self.textbox)
        self.insertPos = 0
        self.lastPStyle = ""
        self.insertText('Radtouren\n', 'Radtouren_titel')
def trovasostituisci(text_to_find,text_to_replace):
#itero tutti gli oggetti presenti in Scribus
  for obj in scribus.getAllObjects():
    #ottengo il tipo di oggetto di tutti gli elementi della pagina
    obj_type = scribus.getObjectType(obj)
    #controllo che il tipo di oggetto scribus sia TextFrame
    if obj_type == "TextFrame":
        #ottengo il testo contenuto in tutti gli oggetti
        obj_text = scribus.getText(obj)
        #text_to_find = "_F6%"
        #text_to_replace = "123 TESTO SOSTITUITO 123456789"
        #cerco la variabile text_to_find
        if text_to_find in obj_text:
          #se la trovo la sostituisco
          text_to_find = obj_text.replace(text_to_find, text_to_replace)
          scribus.setText(text_to_find, obj)
          scribus.setFontSize(8, obj)
Beispiel #6
0
def drawPlaceholders():
    page = scribus.getPageSize()
    margin = scribus.getPageMargins()

    # add the page margins
    rectangle = scribus.createRect(margin[1], margin[0],
                                   (page[0] - margin[1] - margin[2]),
                                   (page[1] - margin[0] - margin[3]))
    scribus.setFillColor('none', rectangle)
    scribus.setLineColor('Blue', rectangle)
    scribus.setLineWidth(0.4, rectangle)

    # add horizontal and vertical guides
    for item in scribus.getHGuides():
        line = scribus.createLine(0, item, page[0], item)
        scribus.setLineColor('Black', line)
        scribus.setLineWidth(0.6, line)
        scribus.setLineStyle(scribus.LINE_DASHDOT, line)

    for item in scribus.getVGuides():
        line = scribus.createLine(item, 0, item, page[0])
        scribus.setLineColor('Black', line)
        scribus.setLineWidth(0.6, line)
        scribus.setLineStyle(scribus.LINE_DASHDOT, line)

    # add a "crossed frame" for missing images
    for item in scribus.getAllObjects():
        if scribus.getObjectType(item) == 'ImageFrame':
            image = scribus.getImageFile(item)
            if image == '':
                pos = scribus.getPosition(item)
                size = scribus.getSize(item)
                rectangle = scribus.createRect(pos[0], pos[1], size[0],
                                               size[1])
                scribus.setFillColor('none', rectangle)
                scribus.setLineColor('Black', rectangle)
                scribus.setLineWidth(0.4, rectangle)
                line = scribus.createLine(pos[0], pos[1], pos[0] + size[0],
                                          pos[1] + size[1])
                scribus.setLineColor('Black', line)
                scribus.setLineWidth(0.4, line)
                line = scribus.createLine(pos[0], pos[1] + size[1],
                                          pos[0] + size[0], pos[1])
                scribus.setLineColor('Black', line)
                scribus.setLineWidth(0.4, line)
Beispiel #7
0
def getSelection():
    '''Returns a list of the selected TextFrame objects.
    Returns an empty list if there is no TextFrame Object currently selected.'''
    try:
        filtered_selection = [
        ]  # list we're going to use to put all the TextFrame elements
        # first, we check if there is something to work on
        if scribus.selectionCount() > 0:
            # then we check for each element
            # if it's a TextFrame object.
            # if so, we add it's name to the filtered list.
            for i in range(0, scribus.selectionCount()):
                if scribus.getObjectType(
                        scribus.getSelectedObject(i)) == 'TextFrame':
                    filtered_selection.append(scribus.getSelectedObject(i))
        return filtered_selection
    except:
        print error_message_selection_error
        scribus.messageBox(TITLE, error_message_selection_error,
                           scribus.ICON_WARNING)
        return []
def drawPlaceholders():
    page = scribus.getPageSize()
    margin = scribus.getPageMargins()

    # add the page margins
    rectangle = scribus.createRect(margin[1], margin[0], (page[0] - margin[1] - margin[2]), (page[1] - margin[0] - margin[3]))
    scribus.setFillColor('none', rectangle)
    scribus.setLineColor('Blue', rectangle)
    scribus.setLineWidth(0.4, rectangle)

    # add horizontal and vertical guides
    for item in scribus.getHGuides():
        line = scribus.createLine(0, item , page[0], item)
        scribus.setLineColor('Black', line)
        scribus.setLineWidth(0.6, line)
        scribus.setLineStyle(scribus.LINE_DASHDOT, line)

    for item in scribus.getVGuides():
        line = scribus.createLine(item, 0 , item, page[0])
        scribus.setLineColor('Black', line)
        scribus.setLineWidth(0.6, line)
        scribus.setLineStyle(scribus.LINE_DASHDOT, line)

    # add a "crossed frame" for missing images
    for item in scribus.getAllObjects():
        if scribus.getObjectType(item) == 'ImageFrame':
            image = scribus.getImageFile(item)
            if image == '':
                pos = scribus.getPosition(item)
                size = scribus.getSize(item)
                rectangle = scribus.createRect(pos[0], pos[1], size[0], size[1])
                scribus.setFillColor('none', rectangle)
                scribus.setLineColor('Black', rectangle)
                scribus.setLineWidth(0.4, rectangle)
                line = scribus.createLine(pos[0], pos[1] , pos[0] + size[0], pos[1] + size[1])
                scribus.setLineColor('Black', line)
                scribus.setLineWidth(0.4, line)
                line = scribus.createLine(pos[0], pos[1] + size[1], pos[0] + size[0], pos[1])
                scribus.setLineColor('Black', line)
                scribus.setLineWidth(0.4, line)
Beispiel #9
0
def main():
    md_name = scribus.fileDialog("Select a file", 'Markdown (*.md)')
    if not md_name:
        return

    f = NamedTemporaryFile(suffix='.html')
    markdown.markdownFromFile(md_name, f)
    f.flush()

    html_name = f.name

    i = 0
    while True:
        ob_name = scribus.getSelectedObject(i)

        if not ob_name:
            break

        if scribus.getObjectType(ob_name) == 'TextFrame':
            scribus.insertHtmlText(html_name, ob_name)

        i += 1
Beispiel #10
0
def main():
    if sc.selectionCount() == 2:
        images = ( sc.getSelectedObject(0), sc.getSelectedObject(1) )
        for image in images:
            if sc.getObjectType(image) != "ImageFrame":
                logging.debug(f"Image type {sc.getObjectType(image)}, but 'ImageFrame' expected")
                error_msg(f'{image} not an image frame. But type {sc.getObjectType(image)}')
        image_files = (sc.getImageFile(images[0]), sc.getImageFile(images[1]))
        # keep Scale and Offset, before reset by image load
        image_0_offset = sc.getImageOffset(images[0])
        image_0_scale  = sc.getImageScale(images[0])
        image_1_offset = sc.getImageOffset(images[1])
        image_1_scale  = sc.getImageScale(images[1])
        sc.loadImage(image_files[1], images[0]) 
        sc.loadImage(image_files[0], images[1]) 
        if sc.getSize(images[0]) == sc.getSize(images[1]):
            # Frames have the same size swap scale and offset
            logging.debug(f"Frames have the same size {sc.getSize(images[0])}, swap offset and scale")
            logging.debug(f"Image 0: {images[0]}, Image 1: {images[1]}")
            logging.debug(f"Image properties: offset {sc.getImageOffset(images[0])}, scale {image_0_scale}")

            sc.setImageOffset(*image_1_offset, images[0])
            sc.setImageScale(*image_1_scale, images[0])
            sc.setImageOffset(*image_0_offset, images[1])
            sc.setImageScale(*image_0_scale, images[1])
        else:
            # scale and center
            logging.debug("Different size scale and center, both.")
            for name in images:
                x, y = sff.scale_to_frame(name)
                sff.center_image(name, x, y)


    else:
        logging.debug(f"{sc.selectionCount()} frames selected.")
        error_msg(f'{sc.selectionCount()} frames selected')
imageFrame = []
if scribus.selectionCount() == 0:
    for page in range(scribus.pageCount()):
        scribus.gotoPage(page + 1)
        scribus.messagebarText("Processing Page " + str(page))
        scribus.redrawAll()
        for item in scribus.getPageItems():
            if (item[1] == 4):
                textFrame.append(item[0])
            elif (item[1] == 2):
                imageFrame.append(item[0])
else:
    for i in range(scribus.selectionCount()):
        item = scribus.getSelectedObject(i)
        selectedFrame.append(item)
        if scribus.getObjectType(item) == "TextFrame":
            textFrame.append(item)
        if scribus.getObjectType(item) == "ImageFrame":
            imageFrame.append(item[0])

# print textFrame
# print imageFrame

scribus.deselectAll()
chars = []
for item in textFrame:
    scribus.deselectAll()
    scribus.selectObject(item)
    n = scribus.getTextLength()
    for i in range(n):
        scribus.selectText(i, 1)
# encoding: utf-8
try:
    import scribus
except ImportError:
    print('This script must be run from inside Scribus')
import sys

if scribus.selectionCount() != 1 or scribus.getObjectType() != 'TextFrame':
    scribus.messageBox('Script failed',
                       'You need to select one text frame selected.')
    sys.exit(2)

PLACEHOLDER_START = '{'
PLACEHOLDER_END = '}'

VALUES = {'name': 'Goofy', 'color': 'blue', 'food': 'pizza'}

len_start = len(PLACEHOLDER_START)
len_end = len(PLACEHOLDER_END)

scribus.selectText(0, 0)
text = scribus.getText()

i = text.find(PLACEHOLDER_START)
while i != -1:
    j = text.find(PLACEHOLDER_END, i)
    if j == -1:
        break

    key = text[i + 1:j]
    # print('>>>' + key)
# add horizontal and vertical guides
for item in scribus.getHGuides():
    line = scribus.createLine(0, item , page[0], item)
    scribus.setLineColor('Black', line)
    scribus.setLineWidth(0.6, line)
    scribus.setLineStyle(scribus.LINE_DASHDOT, line)

for item in scribus.getVGuides():
    line = scribus.createLine(item, 0 , item, page[1])
    scribus.setLineColor('Black', line)
    scribus.setLineWidth(0.6, line)
    scribus.setLineStyle(scribus.LINE_DASHDOT, line)

# add a "crossed frame" for missing images
for item in scribus.getAllObjects():
    if scribus.getObjectType(item) == 'ImageFrame':
        image = scribus.getImageFile(item)
        if image == '':
            pos = scribus.getPosition(item)
            size = scribus.getSize(item)
            rectangle = scribus.createRect(pos[0], pos[1], size[0], size[1])
            scribus.setFillColor('none', rectangle)
            scribus.setLineColor('Black', rectangle)
            scribus.setLineWidth(0.4, rectangle)
            line = scribus.createLine(pos[0], pos[1] , pos[0] + size[0], pos[1] + size[1])
            scribus.setLineColor('Black', line)
            scribus.setLineWidth(0.4, line)
            line = scribus.createLine(pos[0], pos[1] + size[1], pos[0] + size[0], pos[1])
            scribus.setLineColor('Black', line)
            scribus.setLineWidth(0.4, line)
                    print(frameName + " found")
                    position = scribus.getPosition(frameName)
                    scribus.selectObject(sampleFrameName)
                    scribus.duplicateObject()
                    #duplicateFrameName = scribus.getSelectedObject()
                    scribus.moveObjectAbs(position[0], position[1])
                    scribus.deleteObject(frameName)
                    # TODO: rename the duplicate to the old frameName


checkForOneFrameSelected()

currentFrameName = scribus.getSelectedObject()
print(currentFrameName)

if (scribus.getObjectType(currentFrameName) == 4):
    scribus.messageBox('Scribus - Usage Error',
                       "You did not select a textframe. Try again.",
                       scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(2)

# the pattern is the name of the current frame up to the first digit
# and with the "Copy of " at the beginning stripped away.
matchNonDigit = re.compile(r'(^\D+)')
matchResult = matchNonDigit.search(currentFrameName)
pattern = matchResult.group(1)
pattern = remove_copy_prefix(pattern)
pattern = remove_copy_prefix(pattern)
print("pattern: " + pattern)

scribus.duplicateObject()
Beispiel #15
0
import sys

if not scribus.haveDoc():
    scribus.messageBox('Error', 'You need a Document open.', icon=0, button1=1)
    sys.exit(2)

if scribus.selectionCount() != 1:
    scribus.messageBox('Error',
                       "Please select the target text frame.",
                       scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(2)

toc_frame = scribus.getSelectedObject()

if scribus.getObjectType(toc_frame) != 'TextFrame':
    scribus.messageBox('Error',
                       "Please select the target text frame.",
                       scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(2)

toc_styles = {'h1': 'toc1', 'h2': 'toc2', 'h3': 'toc3'}
toc_content = []

for page in range(1, scribus.pageCount() + 1):
    scribus.gotoPage(page)
    for item in scribus.getPageItems():
        if item[1] == 4:
            scribus.deselectAll()
            scribus.selectObject(item[0])
            content = scribus.getFrameText()
imageFrame = []
if scribus.selectionCount() == 0:
    for page in range(scribus.pageCount()) :
        scribus.gotoPage(page + 1)
        scribus.messagebarText("Processing Page "+str(page))
        scribus.redrawAll()
        for item in scribus.getPageItems() :
            if (item[1] == 4):
                textFrame.append(item[0])
            elif (item[1] == 2) :
                imageFrame.append(item[0])
else :
    for i in range(scribus.selectionCount()) :
        item = scribus.getSelectedObject(i)
        selectedFrame.append(item)
        if scribus.getObjectType(item) == "TextFrame" :
            textFrame.append(item)
        if scribus.getObjectType(item) == "ImageFrame" :
            imageFrame.append(item[0])

# print textFrame
# print imageFrame

scribus.deselectAll()
chars = []
for item in textFrame :
    scribus.deselectAll()
    scribus.selectObject(item)
    n = scribus.getTextLength()
    for i in range(n) :
        scribus.selectText(i, 1)
Beispiel #17
0
    if pageNumber % 2 == 0:
        return 50
    return 40


if __name__ == "__main__":

    x = getX(scribus.currentPage())

    headerText = scribus.createText(x, 80, 750, 30)
    headerUnderline = scribus.createLine(x, 110, 160, 110)
    bodyText = scribus.createText(x, 120, 750, 1030)
    scribus.setColumns(4, bodyText)
    scribus.setColumnGap(10, bodyText)

    if scribus.getObjectType(bodyText) == "TextFrame":
        fileName = scribus.fileDialog("Open odt file", 'ODT files (*.odt)')
        text = removeEmptyStrings(parse(fileName))
        header = detag(header(text))
        body = body(text)

        scribus.deleteText(bodyText)
        scribus.insertText(lines(detag(body))[0], -1, bodyText)
        scribus.setStyle("first_paragraph", bodyText)

        for p in lines(detag(body))[1:]:
            scribus.insertText("\n" + p, -1, bodyText)
            scribus.setStyle("eot", bodyText)
        for tag in extractModifiers(body):
            scribus.selectText(tag['start'], tag['length'], bodyText)
            if tag['tag'] == "bold":
Beispiel #18
0
if frame_n == 0:
    scribus.messageBox('Error:', 'No frame selected')
    sys.exit(1)
elif frame_n > 1:
    scribus.messageBox('Error:', 'Please select one single frame')
    sys.exit(1)

item = scribus.getSelectedObject(0)

path_images = None
filename_png = None
path_png = None
path_svg = None

if (scribus.getObjectType(item) == 'TextFrame'):
    path = scribus.getAllText()
    if path != '':
        base_path = os.path.dirname(scribus.getDocName())
        filename_png = os.path.join(base_path, path)
elif (scribus.getObjectType(item) == 'ImageFrame'):
    filename_png = scribus.getImageFile()

if path_png == '':
    filename_png = None

if filename_png == None:
    scribus.messageBox(
        'Error:',
        'You need to select a text frame containing the path to the image or an image frame with an old version of the image'
    )
Beispiel #19
0
# © 2018, MIT license, Ale Rimoldi <*****@*****.**>

import scribus
import sys

if not scribus.haveDoc():
    scribus.messageBox('Usage Error', 'You need a Document open')
    sys.exit(2)

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

item = scribus.getSelectedObject()

if (scribus.getObjectType(item) != 'TextFrame'):
    scribus.messageBox('Usage Error', 'You need to select a text frame')
    sys.exit(2)

print(scribus.getTextLength(item))
if scribus.getTextLength(item) > 0:
    scribus.messageBox('Usage Error', 'The text frame should be empty')
    sys.exit(2)

answer = scribus.valueDialog('Numbered lines', 'Start number, step', '1,1')
start, step = answer.split(',')
start = int(start)
step = int(step)

i = start
print(scribus.textOverflows(item))
                if frameName != sampleFrameName and remove_copy_prefix(frameName).startswith(pattern):
                    print(frameName + " found")
                    position = scribus.getPosition(frameName)
                    scribus.selectObject(sampleFrameName)
                    scribus.duplicateObject()
                    #duplicateFrameName = scribus.getSelectedObject()
                    scribus.moveObjectAbs(position[0], position[1])
                    scribus.deleteObject(frameName)
                    # TODO: rename the duplicate to the old frameName

checkForOneFrameSelected()
 
currentFrameName = scribus.getSelectedObject()
print(currentFrameName)

if (scribus.getObjectType(currentFrameName) == 4):
    scribus.messageBox('Scribus - Usage Error', "You did not select a textframe. Try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
    sys.exit(2)

# the pattern is the name of the current frame up to the first digit
# and with the "Copy of " at the beginning stripped away.
matchNonDigit = re.compile(r'(^\D+)')
matchResult = matchNonDigit.search(currentFrameName)
pattern = matchResult.group(1)
pattern = remove_copy_prefix(pattern)
pattern = remove_copy_prefix(pattern)
print("pattern: " + pattern)

scribus.duplicateObject()
duplicateFrameName = scribus.getSelectedObject()
## contribution from jvr14115, https://github.com/berteh/ScribusGenerator/issues/116
## run from within Scribus > Script > run Script

import os
import re
import scribus

Edoc = scribus.getDocName()
Edoc = Edoc.replace('.sla', '')
file_name = Edoc + 'Elements.csv'
Edoc = Edoc.replace('Elements.csv', '')
Edoc = re.search(r'(.*)/(.*)', Edoc).group(2)
f = open(file_name, 'w+')
f.write('Template,Element,ElementType')
f.write('\n')
objL = scribus.getAllObjects()
for obj in objL:
    objT = scribus.getObjectType(obj)
    Evar = ''
    if objT == 'ImageFrame':
        Etype = 'image'
        Evar = scribus.getImageFile(obj)
    if objT == 'TextFrame':
        Etype = 'text'
        Evar = scribus.getAllText(obj)
    if '%VAR_' in Evar:
        Evar = re.sub('^[^%VAR_]*%VAR_', '', Evar)
        Evar = Evar[:-1]
        f.write(Edoc + ';"' + Evar + '";' + Etype + '\n')
f.close
Beispiel #22
0
import scribus
import os
import glob
pageNum = scribus.pageCount()
print(pageNum)

result = ""

os.chdir(os.path.dirname(scribus.getDocName()) + "/../png")
listeImages = sorted(glob.glob("*"))

itemNum = 0
for i in range(1, pageNum + 1):

    scribus.gotoPage(i)
    for o in scribus.getAllObjects():
        if (scribus.getObjectType(o) == "ImageFrame"):
            if (scribus.getSize(o)[0] >= scribus.getPageSize()[0] * 0.99):
                #result = result + "item:" + str(itemNum) + " page:" + str(i) + " name: " + o + "\n" + " imageFile:" + scribus.getImageFile(o)
                scribus.loadImage(listeImages[itemNum], o)
                itemNum = itemNum + 1

#scribus.messageBox("caption", result)
#scribus.messageBox("listeImages", "\n".join(listeImages))