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 freeSpace(self, width, height):
    ypos = self.topmargin
    for obj in scribus.getAllObjects():
       if not obj in self.sidebar.frames:
          (x,y) = scribus.getPosition(obj)
          (w,h) = scribus.getSize(obj)
          if y + h > ypos:
             ypos = y + h + COLUMNGAP + 1
    if ypos + height <= self.pageheight - self.bottommargin and self.gotSpace(self.leftmargin, ypos, width, height):
       return ypos
    else:
       return -1
Exemplo n.º 3
0
 def freeSpace(self, width, height):
     ypos = self.topmargin
     for obj in scribus.getAllObjects():
         if not obj in self.sidebar.frames:
             (x, y) = scribus.getPosition(obj)
             (w, h) = scribus.getSize(obj)
             if y + h > ypos:
                 ypos = y + h + COLUMNGAP + 1
     if ypos + height <= self.pageheight - self.bottommargin and self.gotSpace(
             self.leftmargin, ypos, width, height):
         return ypos
     else:
         return -1
Exemplo n.º 4
0
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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def newFrame(self, height=MINFRAMESIZE, columns=2):
        """Start a new text frame.
         If we are working with 2 columns, we build each column as a seperate frame.
         Scribus does support multi column text frames, but with no keep-with-next
         functionality its of no use."""

        self.flushImages()
        if columns == 2 and self.frame != None and self.currentcolumn == 1:
            # Start the second column.
            (x, y) = scribus.getPosition(self.frame)
            (w, h) = scribus.getSize(self.frame)
            width = w
            xpos = x + w + COLUMNGAP
            ypos = y
            self.currentcolumn = 2
        else:
            # First column or full width frame
            while True:
                ypos = self.topmargin
                for obj in scribus.getAllObjects():
                    if obj in self.textframes:
                        (x, y) = scribus.getPosition(obj)
                        (w, h) = scribus.getSize(obj)
                        if y + h > ypos:
                            ypos = y + h + FRAMEGAP
                if ypos + height > self.pageheight - self.bottommargin:
                    self.newPage()
                    self.flushImages()
                else:
                    break
            xpos = self.leftmargin
            if columns == 1:
                width = self.pagewidth - self.leftmargin - self.rightmargin
                self.currentcolumn = 0
            else:
                width = self.columnwidth
                self.currentcolumn = 1

        self.frame = scribus.createText(xpos, ypos, width, height)
        self.contents = []
        self.buffer = []
        self.columns = columns
        self.framelinked = False
        self.textframes.append(self.frame)
Exemplo n.º 7
0
   def newFrame(self, height=MINFRAMESIZE, columns=2):
      """Start a new text frame.
         If we are working with 2 columns, we build each column as a seperate frame.
         Scribus does support multi column text frames, but with no keep-with-next
         functionality its of no use."""

      self.flushImages()
      if columns == 2 and self.frame != None and self.currentcolumn == 1:
         # Start the second column.
         (x,y) = scribus.getPosition(self.frame)
         (w,h) = scribus.getSize(self.frame)
         width = w
         xpos = x + w + COLUMNGAP
         ypos = y
         self.currentcolumn = 2
      else:
         # First column or full width frame
         while True:
            ypos = self.topmargin
            for obj in scribus.getAllObjects():
               if obj in self.textframes:
                  (x,y) = scribus.getPosition(obj)
                  (w,h) = scribus.getSize(obj)
                  if y + h > ypos: 
                     ypos = y + h + FRAMEGAP
            if ypos + height > self.pageheight - self.bottommargin:
               self.newPage()
               self.flushImages()
            else:
               break
         xpos = self.leftmargin
         if columns == 1: 
            width = self.pagewidth - self.leftmargin - self.rightmargin
            self.currentcolumn = 0
         else:            
            width = self.columnwidth
            self.currentcolumn = 1
                                
      self.frame = scribus.createText(xpos, ypos, width, height)
      self.contents = []
      self.buffer = []
      self.columns = columns
      self.framelinked = False
      self.textframes.append(self.frame)
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)
## 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
Exemplo n.º 10
0
 def raiseFrames(self, framelist):
     scribus.deselectAll()
     for i in scribus.getAllObjects():
         if i in framelist:
             scribus.selectObject(i)
     scribus.moveSelectionToFront()
Exemplo n.º 11
0
 def gotSpace(self, xpos, ypos, width, height):
     for obj in scribus.getAllObjects():
         if not obj in self.sidebar.frames:
             if self.clashes(xpos, ypos, width, height, obj):
                 return False
     return True
# 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)
Exemplo n.º 13
0
 def raiseFrames(self, framelist):
    scribus.deselectAll()
    for i in scribus.getAllObjects():
       if i in framelist:
          scribus.selectObject(i)      
    scribus.moveSelectionToFront()
Exemplo n.º 14
0
 def gotSpace(self, xpos, ypos, width, height):
    for obj in scribus.getAllObjects():
       if not obj in self.sidebar.frames:
          if self.clashes(xpos, ypos, width, height, obj):
             return False
    return True
Exemplo n.º 15
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))