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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
def duplicate_content(pages, named_items):
    """ duplicate the content of pages at the end of the document
        and track the new item names for the items in named_items
    return the list of created item names from named_items """
    result = {}
    page_n = scribus.pageCount()
    for page in pages:
        scribus.gotoPage(page)
        items = [item[0] for item in scribus.getPageItems()]
        scribus.newPage(-1, scribus.getMasterPage(page))
        page_n += 1

        for item in items:
            scribus.gotoPage(page)
            scribus.copyObject(item)
            scribus.gotoPage(page_n)
            scribus.pasteObject()
            if item in named_items:
                result[item] = scribus.getSelectedObject()
    return result
Exemplo n.º 4
0
def main():
    pass

    n = scribus.selectionCount()
    if n == 0:
        scribus.messageBox('Error', 'No item selected')
        return

    items = []
    for i in range(n):
        items.append(scribus.getSelectedObject(i))

    for item in items:
        pos = scribus.getPosition(item)
        dx, dy = pos
        scribus.pasteObject()
        new_item = scribus.getSelectedObject()
        pos = scribus.getPosition(new_item)
        dx, dy = dx - pos[0], dy - pos[1]
        scribus.moveObject(dx, dy, new_item)
        scribus.deleteObject(item)
    scribus.createLayer(fantome)
    working = scribus.getActiveLayer()
    page = 1
    pagenum = scribus.pageCount()
    while (page <= pagenum):
        scribus.gotoPage(page)
        scribus.setActiveLayer(working)  # maybe not necessary?
        pageitems = scribus.getPageItems()

        for item in pageitems:
            if (item[1] == 2):
                imagebox = item[0]
                scribus.selectObject(imagebox)
                scribus.copyObject(imagebox)
                scribus.setActiveLayer(fantome)
                scribus.pasteObject(imagebox)
                scribus.deleteObject(imagebox)
                scribus.setActiveLayer(working)
        page += 1
    scribus.setLayerPrintable(fantome,
                              0)  # comment this out to do manually later
    scribus.setLayerVisible(fantome,
                            0)  # comment this out to do manually later
    scribus.setRedraw(1)
    scribus.docChanged(1)
    scribus.messageBox("Finished", "That should do it!", icon=0, button1=1)

else:
    scribus.messageBox('Usage Error',
                       'You need a Document open',
                       icon=0,
import scribus

if not scribus.haveDoc():
    scribus.messagebarText("No .") 
    sys.exit()

path = "/tmp/t/lot_forum"
extensions = ['jpg', 'png', 'tif']
filenames = [f for f in os.listdir(path)
              if any(f.endswith(ext) for ext in extensions)]
if not filenames:
    scribus.messagebarText("No image found.") 
    sys.exit()

page = 1
n_pages = scribus.pageCount()

scribus.copyObject()

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

for filename in filenames:
    if page <= n_pages:
        scribus.gotoPage(page)
    else:
        scribus.newPage(-1)
        scribus.gotoPage(scribus.pageCount())
        page_item = scribus.pasteObject()
        scribus.loadImage(filename, page_item)
Exemplo n.º 7
0
        scribus.messageBox('Scribus - Usage Error',
                           "There is no object selected.\nPlease try again.",
                           scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    if scribus.selectionCount() > 1:
        scribus.messageBox('Scribus - Usage Error', "You have more than one object selected.
                                 \nPlease select one object and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
        sys.exit(2)
    pagelist = scribus.valueDialog('Paste to...',"Paste to which pages?
                                 \n(page numbers, separated by white space)","1")
    pageslist = pagelist.split()
    selframe = scribus.getSelectedObject()
    pages = scribus.pageCount()
    for p in pageslist:
        p_no = int(p)
        if ((p_no > pages) or (p_no < 1)):
            scribus.messageBox('OOPS!', "You have a page number outside the range of pages in your document",
                      scribus.ICON_WARNING, scribus.BUTTON_OK)
            sys.exit(2)
    scribus.copyObject(selframe)
    for p in pageslist:
        p_no = int(p)
        scribus.gotoPage(p_no)
        scribus.pasteObject(selframe)
    scribus.setRedraw(1)
    scribus.docChanged(1)
    scribus.messageBox("Finished", "Done",icon=0,button1=1)
else:
    scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1)
    sys.exit(2)
 
  fantome = "Ghostlayer"
  scribus.createLayer(fantome)
  working = scribus.getActiveLayer()
  page = 1
  pagenum = scribus.pageCount()
  while (page <= pagenum):
    scribus.gotoPage(page)
    scribus.setActiveLayer(working)  # maybe not necessary?  
    pageitems = scribus.getPageItems()
 
    for item in pageitems:
      if (item[1] == 2):
	imagebox = item[0]
	scribus.selectObject(imagebox)
	scribus.copyObject(imagebox)
	scribus.setActiveLayer(fantome)
	scribus.pasteObject(imagebox)
	scribus.deleteObject(imagebox)
	scribus.setActiveLayer(working)
    page += 1
  scribus.setLayerPrintable(fantome, 0)  # comment this out to do manually later
  scribus.setLayerVisible(fantome, 0)    # comment this out to do manually later
  scribus.setRedraw(1)
  scribus.docChanged(1)
  scribus.messageBox("Finished", "That should do it!",icon=0,button1=1)
 
else:
    scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1)
    sys.exit(2)