Beispiel #1
0
def get_imageframes_on_page(page_number, empty_only=False, name_filter=None):
    """
    page_number:  if 0 use current page, otherwise the given page
    set emty_only to return empty frames only
    name_filter: return frame if name conatins filter string
    returns a list of the image objects on the current page
    get all the items on the page
    """

    current_page = sc.currentPage()
    if page_number > 0:
        if page_number <= sc.pageCount():
            sc.gotoPage(page_number)
        else:
            logging.warning('Page {} out of rage.'.format(page_number))
            return []

    item_list = sc.getPageItems()
    # refine it to a list of only image objects
    objs = []
    for item in item_list:
        if item[1] == 2:  #type 2 == image
            add_image = True
            if empty_only:
                add_image = is_imageframe_empty(item[0]) and add_image
            if name_filter:
                if name_filter in item[0]:
                    add_image = True and add_image
                else:
                    add_image = False and add_image
            if add_image:
                objs.append(item[0])
    sc.gotoPage(current_page)
    return objs
def create_content():
    dirname = scribus.fileDialog("Select Directory", "", "", False, False,
                                 True)
    files = sorted(glob(os.path.join(dirname, "*")))
    if len(files) == 0:
        return

    scribus.progressReset()
    scribus.progressTotal(len(files))
    scribus.messagebarText("Creating pages...")
    progress = 0

    for f in files:

        scribus.progressSet(progress)
        progress = progress + 1

        add_image(f)

        if len(files) > progress:
            # add page for next image
            scribus.newPage(-1)

    scribus.progressReset()
    scribus.messagebarText("")
    scribus.deselectAll()
    scribus.gotoPage(1)
Beispiel #3
0
def exportText(root_folder):
    page = 1
    pagenum = scribus.pageCount()
    T = []
    content = []
    while (page <= pagenum):
        scribus.gotoPage(page)
        d = scribus.getPageItems()
        
        page_folder = root_folder+"/p"+str(page)
        if not os.path.isdir(page_folder):
			os.mkdir(page_folder)
        
        for item in d:
            if (item[1] == 4): # the item is a text
				textfile = folder+"/p"+str(page)+"/"+item[0]+".txt"
				output_file = open(textfile,'w')
				output_file.writelines(scribus.getAllText(item[0]))
				output_file.close()
				

        page += 1
        

    endmessage = "Text files successfully saved in "+root_folder
    scribus.messageBox("Finished", endmessage,icon=0,button1=1)
Beispiel #4
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)
def create_content():
    dirname = scribus.fileDialog("Select Directory", "", "", False, False, True)
    files = sorted(glob(os.path.join(dirname, "*")))
    if len(files) == 0:
        return

    scribus.progressReset()
    scribus.progressTotal(len(files))
    scribus.messagebarText("Creating pages...")
    progress = 0

    for f in files:

        scribus.progressSet(progress)
        progress = progress + 1

        add_image(f)

        if len(files) > progress:
            # add page for next image
            scribus.newPage(-1)

    scribus.progressReset()
    scribus.messagebarText("")
    scribus.deselectAll()
    scribus.gotoPage(1)
Beispiel #6
0
def createDefaultVal():
    scribus.gotoPage(1)
    if scribus.objectExists("myframe") == False:
        scribus.createText(-70, 10, 40, 10, "myframelabel")
        scribus.setText("Default Frame:", "myframelabel")
        scribus.setProperty("myframelabel", "m_PrintEnabled", False)

        scribus.createText(-30, 10, 10, 10, "myframe")
        scribus.setText("3", "myframe")
        scribus.setProperty("myframe", "m_PrintEnabled", False)

    if scribus.objectExists("myborder") == False:
        scribus.createText(-70, 30, 40, 10, "myborderlabel")
        scribus.setText("Default Border:", "myborderlabel")
        scribus.setProperty("myborderlabel", "m_PrintEnabled", False)

        scribus.createText(-30, 30, 10, 10, "myborder")
        scribus.setText("3", "myborder")
        scribus.setProperty("myborder", "m_PrintEnabled", False)

    if scribus.objectExists("mylayout") == False:
        scribus.createText(-70, 50, 40, 10, "mylayoutlabel")
        scribus.setText("Default Layout:", "mylayoutlabel")
        scribus.setProperty("mylayoutlabel", "m_PrintEnabled", False)

        scribus.createText(-30, 50, 10, 10, "mylayout")
        scribus.setText("h", "mylayout")
        scribus.setProperty("mylayout", "m_PrintEnabled", False)
 def flow(self):
     while(scribus.textOverflows(self.name) > 0 and scribus.getTextLines(self.name)):
         current = self.name
         scribus.newPage(-1)
         scribus.gotoPage( scribus.pageCount() )
         self.name = self.make_textframe()
         scribus.linkTextFrames(current, self.name)
def exportText(textfile):
    page = 1
    pagenum = scribus.pageCount()
    T = []
    content = []
    while (page <= pagenum):
        scribus.gotoPage(page)
        d = scribus.getPageItems()
        strpage = str(page)
        T.append('Page '+ strpage + '\n\n')
        for item in d:
            if (item[1] == 4):
                contents = scribus.getAllText(item[0])
                if (contents in content):
                    contents = 'Duplication, perhaps linked-to frame'
                T.append(item[0]+': '+ contents + '\n\n')
                content.append(contents)
            elif (item[1] == 2):
                imgname = scribus.getImageFile(item[0])
                T.append(item[0]+': ' + imgname + '\n')
        page += 1
        T.append('\n')
    output_file = open(textfile,'w')
    output_file.writelines(T)
    output_file.close()
    endmessage = textfile + ' was created'
    scribus.messageBox("Finished", endmessage,icon=0,button1=1)
Beispiel #9
0
    def draw(self, tolevel):
        contents = []
        for (label, level, page) in self.sections:
            if level <= tolevel:
                text = label + chr(TAB) + str(page)
                style = "Contents" + str(level)
                contents.append((text, style))

        page = self.contentspage
        scribus.gotoPage(page)
        (width, height) = scribus.getPageSize()
        (top, left, right, bottom) = getCurrentPageMargins()
        frame = scribus.createText(left, top, width - right - left, TITLESIZE)
        insertTextWithStyle("Contents", "Title", frame)

        frame = scribus.createText(left, top + TITLESIZE, width - right - left,
                                   height - top - bottom - TITLESIZE)
        scribus.setColumns(2, frame)
        scribus.setColumnGap(COLUMNGAP, frame)
        for (text, style) in contents:
            insertTextWithStyle(text, style, frame)
            if scribus.textOverflows(frame):
                oldframe = frame
                page = page + 1
                scribus.gotoPage(page)
                (top, left, right, bottom) = getCurrentPageMargins()
                frame = scribus.createText(left, top + TITLESIZE,
                                           width - right - left,
                                           height - top - bottom - TITLESIZE)
                scribus.setColumns(2, frame)
                scribus.setColumnGap(COLUMNGAP, frame)
                scribus.linkTextFrames(oldframe, frame)
def exportText(textfile):
    page = 1
    pagenum = scribus.pageCount()
    T = []
    content = []
    while (page <= pagenum):
        scribus.gotoPage(page)
        d = scribus.getPageItems()
        strpage = str(page)
        T.append('Page ' + strpage + '\n\n')
        for item in d:
            if (item[1] == 4):
                contents = scribus.getAllText(item[0])
                if (contents in content):
                    contents = 'Duplication, perhaps linked-to frame'
                T.append(item[0] + ': ' + contents + '\n\n')
                content.append(contents)
            elif (item[1] == 2):
                imgname = scribus.getImageFile(item[0])
                T.append(item[0] + ': ' + imgname + '\n')
        page += 1
        T.append('\n')
    output_file = open(textfile, 'w')
    output_file.writelines(T)
    output_file.close()
    endmessage = textfile + ' was created'
    scribus.messageBox("Finished", endmessage, scribus.ICON_NONE,
                       scribus.BUTTON_OK)
Beispiel #11
0
 def draw(self, tolevel):
    contents = []
    for (label,level,page) in self.sections:
       if level <= tolevel:
          text = label + chr(TAB) + str(page)
          style = "Contents" + str(level)
          contents.append((text,style))
    
    page = self.contentspage
    scribus.gotoPage(page)
    (width,height) = scribus.getPageSize()
    (top,left,right,bottom) = getCurrentPageMargins()
    frame = scribus.createText(left, top, width-right-left, TITLESIZE)
    insertTextWithStyle("Contents","Title",frame)
    
    frame = scribus.createText(left, top+TITLESIZE, width-right-left, height-top-bottom-TITLESIZE)
    scribus.setColumns(2,frame)
    scribus.setColumnGap(COLUMNGAP,frame)
    for (text,style) in contents:
       insertTextWithStyle(text,style,frame)
       if scribus.textOverflows(frame):
          oldframe = frame
          page = page + 1
          scribus.gotoPage(page)
          (top,left,right,bottom) = getCurrentPageMargins()
          frame = scribus.createText(left, top+TITLESIZE, width-right-left, height-top-bottom-TITLESIZE)
          scribus.setColumns(2,frame)
          scribus.setColumnGap(COLUMNGAP,frame)
          scribus.linkTextFrames(oldframe,frame)
Beispiel #12
0
def fill_addresses(contacts):
    #on a page, we can put MAX_PAGE_CONTACTS contacts.
    nb_pages = (len(contacts) / MAX_PAGE_CONTACTS) + 1
    for curPage in range(0, nb_pages):
        start_contact = curPage * MAX_PAGE_CONTACTS
        end_contact = start_contact + (MAX_PAGE_CONTACTS -1)
        fill_page(contacts[start_contact:end_contact])
        if(end_contact < len(contacts)):
            scribus.newPage(-1)
            scribus.gotoPage(scribus.pageCount()-1)
Beispiel #13
0
def fill_addresses(contacts):
    #on a page, we can put MAX_PAGE_CONTACTS contacts.
    nb_pages = (len(contacts) / MAX_PAGE_CONTACTS) + 1
    for curPage in range(0, nb_pages):
        start_contact = curPage * MAX_PAGE_CONTACTS
        end_contact = start_contact + (MAX_PAGE_CONTACTS - 1)
        fill_page(contacts[start_contact:end_contact])
        if (end_contact < len(contacts)):
            scribus.newPage(-1)
            scribus.gotoPage(scribus.pageCount() - 1)
Beispiel #14
0
 def makeToc(self, firstPageNr):
     pagenum = scribus.pageCount()
     for page in range(1, pagenum + 1):
         scribus.gotoPage(page)
         pageitems = scribus.getPageItems()
         for item in pageitems:
             if item[1] != 4:
                 continue
             self.textbox = item[0]
             self.evalTocTemplate(firstPageNr)
     scribus.redrawAll()
	def run(self):
		sourceDir = scribus.fileDialog("Comic Directory", isdir=True)
		scribus.newDoc( self.pageSize, self.margins, scribus.PORTRAIT, 0, scribus.UNIT_MILLIMETERS, scribus.FACINGPAGES, scribus.FIRSTPAGERIGHT)

		for resource in os.walk(sourceDir):
			self.clean_up_and_queue(resource[0], resource[1], resource[2])

		scribus.gotoPage(1)

		test = re.compile("[0-9]{1,}\.(%s)$" % self.formats, re.IGNORECASE)
		files = filter(test.search, self.images)
		files.sort()

		nImages = len(files)

		if nImages % 4 > 0:
			print "not"
			numPages = ( ((nImages / 4) +1 ) * 4 )
		else:
			print ":p"
			numPages = nImages
		print numPages

		for page in range(1, numPages):
			scribus.newPage(-1)
		i = 1
		for file in files:
			scribus.gotoPage(i)
			self.createImagePage(file, "image_%s" % i)
			i = i + 1

		if os.path.isfile("%s/front_cover.jpg" % sourceDir):
			file = "%s/front_cover.jpg" % sourceDir
			scribus.newPage(1)
			scribus.gotoPage(1)
			self.createImagePage(file, "front_cover")

		if os.path.isfile("%s/back_cover.jpg" % sourceDir):
			file = "%s/back_cover.jpg" % sourceDir
			scribus.newPage(-1)
			scribus.gotoPage(scribus.pageCount())
			self.createImagePage(file, "back_cover")

		if os.path.isfile("%s/logo_cover.svg" % sourceDir):
			file = "%s/logo_cover.svg" % sourceDir
			scribus.gotoPage(1)
			scribus.placeSVG(file, 0, 0)

#		result = scribus.messageBox('Debug', "%s" % self._comicInfo)

		scribus.setInfo("Fernando Michelotti", "Comics", "description")
		scribus.zoomDocument(-100)
		scribus.saveDoc()
Beispiel #16
0
 def evalTocEvents(self, runs, firstPageNr):
     toc = []
     pagenum = scribus.pageCount()
     foundEvents = 0
     for page in range(1, pagenum + 1):
         scribus.gotoPage(page)
         self.pageNr = firstPageNr + page - 1
         pageitems = scribus.getPageItems()
         for item in pageitems:
             if item[1] != 4:
                 continue
             tbox = item[0]
             tlen = scribus.getTextLength(tbox)
             logger.debug("tbox %s length %d", tbox, tlen)
             if tlen == 0:
                 continue
             scribus.selectText(0, tlen, tbox)
             allText = scribus.getText(
                 tbox)  # getAllText returns text of complete link chain!
             z = 0
             while True:
                 x = allText.find("_evtid_:", z)
                 if x < 0:
                     break
                 y = allText.find(STX, x)
                 evtId = allText[x + 8:y]
                 z = allText.find(ETX, y)
                 titel = allText[y + 1:z]
                 logger.debug("eventid %s, titel %s on page %d", evtId,
                              titel, self.pageNr)
                 event = self.gui.eventServer.getEventById(evtId, titel)
                 toc.append((self.pageNr, event))
                 foundEvents += 1
     logger.debug("sorting")
     toc.sort(key=lambda t: t[1].getDatumRaw())  # sortieren nach Datum
     for (pageNr, event) in toc:
         self.eventMsg = event.getTitel() + " vom " + event.getDatum()[0]
         logger.debug("event %s on page %d", self.eventMsg, self.pageNr)
         self.pageNr = pageNr
         for run in runs:
             self.run = run
             self.evalRun(event)
         self.insertText("\n", self.run)
     self.pageNr = None
     if foundEvents == 0:
         print("Noch keine Events gefunden")
     else:
         # remove template
         pos1, pos2, tbox = self.toBeDelPosToc
         scribus.selectText(pos1, pos2 - pos1, tbox)
         scribus.deleteText(tbox)
         scribus.redrawAll()
def listImages(filename):

    file_content = []
    for page in range(1, scribus.pageCount() + 1):
        scribus.gotoPage(page)
        file_content.append('Page ' + str(page) + '\n\n')
        for item in scribus.getPageItems():
            if item[1] == 2:
                file_content.append(scribus.getImageFile(item[0]) + '\n')

        file_content.append('\n')
    output_file = open(filename, 'w')
    output_file.writelines(file_content)
    output_file.close()
def get_all_empty_images_frames():
    image_frames = []
    for page in range(1, scribus.pageCount() + 1):
        page_image_frames = []
        scribus.gotoPage(page)
        # get all empty image frames on the page
        for item in scribus.getPageItems():
            if item[1] == 2:
                if scribus.getImageFile(item[0]) == "":
                    x, y = scribus.getPosition(item[0])
                    page_image_frames.append((item[0], x, y))
        # sort the frames by position
        page_image_frames.sort(key=lambda k: [k[2], k[1]])
        image_frames += [i[0] for i in page_image_frames]
    return image_frames
def front_matter():
    # load pages from other document
    if not os.path.exists(pwd("front_matter.sla")):
        print "not front matter, file not found!"
        return
    scribus.openDoc(pwd("front_matter.sla"))
    pages = scribus.pageCount()
    scribus.closeDoc()
    scribus.importPage(
        pwd("front_matter.sla"),  # filename
        tuple(range(1, pages+1)),  # range of pages to import
        1,  # insert (1) or replace(0)
        0,  # where to insert
    )
    scribus.gotoPage(pages+1)
def front_matter():
    # load pages from other document
    if not os.path.exists(pwd("front_matter.sla")):
        print "not front matter, file not found!"
        return
    scribus.openDoc(pwd("front_matter.sla"))
    pages = scribus.pageCount()
    scribus.closeDoc()
    scribus.importPage(
        pwd("front_matter.sla"),  # filename
        tuple(range(1, pages + 1)),  # range of pages to import
        1,  # insert (1) or replace(0)
        0,  # where to insert
    )
    scribus.gotoPage(pages + 1)
Beispiel #21
0
def get_placeholders():
    text_frames = []
    image_frames = []

    page_n = scribus.pageCount()
    for page in range(1, page_n + 1):
        scribus.gotoPage(page)
        for item in scribus.getPageItems():
            if item[1] == 2:
                placeholders = get_image_placeholders(item[0])
                if placeholders:
                    image_frames.append((item[0], placeholders))
            if item[1] == 4:
                placeholders = get_text_placeholders(item[0])
                if placeholders:
                    text_frames.append((item[0], placeholders))
    return text_frames, image_frames
def fileMatchingTextFrame(sampleFrameName, pattern):
    pagenum = scribus.pageCount()
    for page in range(1, pagenum + 1):
        scribus.gotoPage(page)
        d = scribus.getPageItems()
        for item in d:
            # print(item)
            frameName = item[0]
            if (item[1] == 4):
                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)
def fileMatchingTextFrame(sampleFrameName, pattern):
    pagenum = scribus.pageCount()
    for page in range(1, pagenum + 1):
        scribus.gotoPage(page)
        d = scribus.getPageItems()
        for item in d:
            # print(item)
            frameName = item[0]
            if (item[1] == 4):
                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)
Beispiel #24
0
def processTemplate(xlat):
    if xlat is None:
        return
    logger.info(r'! process template')
    page = 1
    pagenum = scribus.pageCount()
    while page <= pagenum:
        logger.info(r'.process page ' + str(page))
        scribus.gotoPage(page)
        pitems = scribus.getPageItems()

        for item in [p for p in pitems if p[1] == 4]:
            logger.info(r'..process item: [%s] ', item)
            buf = scribus.getAllText(item[0])
            logger.info(r'...cur text: [%s]', buf)
            phc = None
            # try to figure placeholder
            mbuf = re.search(r'[{]+(\w+)[}]+', buf)
            if mbuf is not None:
                # placeholder text
                phc = mbuf.group(1)
                Automator3.codes[item[0]] = phc
            else:
                # have we been here before?
                if item[0] in Automator3.codes:
                    phc = Automator3.codes[item[0]]

            # ok. do we have a xlat for this?
            if phc is not None and phc in xlat:
                nstr = xlat[phc]
            else:
                nstr = buf

            try:
                scribus.replaceText(nstr, item[0])
                logger.info('...new text: ' + str(nstr))
            except scribus.ScribusException:
                logger.error('.. scribus setText failed')

        page += 1

    logger.info('! done processing template')
def exportText(filename):
    file_content = []
    content = []
    for page in range(1, scribus.pageCount() + 1):
        scribus.gotoPage(page)
        file_content.append('Page ' + str(page) + '\n\n')
        for item in scribus.getPageItems():
            if item[1] == 4:
                contents = scribus.getAllText(item[0])
                if contents in content:
                    contents = 'Duplication, perhaps linked-to frame'
                file_content.append(item[0] + ': ' + contents + '\n\n')
                content.append(contents)
            elif item[1] == 2:
                imgname = scribus.getImageFile(item[0])
                file_content.append(item[0] + ': ' + imgname + '\n')
        file_content.append('\n')
    output_file = open(filename, 'w')
    output_file.writelines(file_content)
    output_file.close()
Beispiel #26
0
 def createNewPage(self, tbox):
     curPage = scribus.currentPage()
     if curPage < scribus.pageCount() - 1:
         where = curPage + 1
     else:
         where = -1
     logger.debug("cur=%d name=%s pc=%d wh=%d", curPage, tbox,
                  scribus.pageCount(), where)
     cols = scribus.getColumns(tbox)
     colgap = scribus.getColumnGap(tbox)
     x, y = scribus.getPosition(tbox)
     w, h = scribus.getSize(tbox)
     mp = scribus.getMasterPage(curPage)
     scribus.newPage(where, mp)  # return val?
     scribus.gotoPage(curPage + 1)
     newBox = scribus.createText(x, y, w, h)
     scribus.setColumns(cols, newBox)
     scribus.setColumnGap(colgap, newBox)
     scribus.linkTextFrames(tbox, newBox)
     logger.debug("link from %s to %s", tbox, newBox)
     return newBox
    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)
Beispiel #28
0
 def rmEventIdMarkers(self):
     pagenum = scribus.pageCount()
     for page in range(1, pagenum + 1):
         scribus.gotoPage(page)
         pageitems = scribus.getPageItems()
         for item in pageitems:
             if item[1] != 4:
                 continue
             tbox = item[0]
             # frameLinks nonempty only if starten called from same gui
             if self.frameLinks.get(
                     tbox
             ) is not None:  # i.e. if tbox is not the root of a link chain
                 continue
             # TODO find out if tbox is a linked frame
             tlen = scribus.getTextLength(tbox)
             if tlen == 0:
                 continue
             scribus.selectText(0, tlen, tbox)
             allText = scribus.getAllText(
                 tbox)  # getAllText returns text of complete link chain!
             z = 0
             xl = []
             while True:
                 x = allText.find("_evtid_:", z)
                 if x < 0:
                     break
                 y = allText.find(STX, x)
                 evtId = allText[x + 8:y]
                 z = allText.find(ETX, y)
                 titel = allText[y + 1:z]
                 xl.append((x, z + 1 - x))
             for (x, l) in reversed(xl):  # the reversed is important!
                 scribus.selectText(x, l, tbox)
                 scribus.deleteText(tbox)
     scribus.redrawAll()
Beispiel #29
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
def new_page():
    scribus.newPage(-1)
    scribus.gotoPage(scribus.pageCount())
    add_page_number()
Beispiel #31
0
def main(argv):

    scribus.setUnit(scribus.UNIT_MILLIMETERS)

    # get page size
    pagesize = scribus.getPageSize()

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

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

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

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

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

    #progressbar max
    scribus.progressTotal(pagenum)

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

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

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

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

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

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

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

        # add page number to iteration
        page += 1

    # go back to active layer
    scribus.setActiveLayer(activelayer)
def new_page():
    scribus.newPage(-1)
    scribus.gotoPage(scribus.pageCount())
    add_page_number()
Beispiel #33
0
 def gotoPage(self,page):
    scribus.gotoPage(page)
    (self.topmargin, self.leftmargin, self.rightmargin, self.bottommargin) = getCurrentPageMargins()
    self.columnwidth = (self.pagewidth - self.leftmargin - self.rightmargin - COLUMNGAP) / 2
    "\"", "“", "”", "\r"
]

button = scribus.messageBox(
    'Confirmation', 'You should only scramble a copy of your document',
    scribus.ICON_WARNING, scribus.BUTTON_OK, scribus.BUTTON_CANCEL)
print button
if button == scribus.BUTTON_CANCEL:
    sys.exit(2)

selectedFrame = []
textFrame = []
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])
of the same name in the new location. It the image is there, the link will be
replaced.

You would be wise to work on a copy of the original to avoid accidentally include
the wrong images.
"""

import scribus
import os.path

page_n = scribus.pageCount()
item_missing = []

# create a list of items with a brokein link
for page_i in range(0, page_n) :
    scribus.gotoPage(page_i + 1)
    item_list = scribus.getPageItems()
    #print(item_list)
    for item in item_list :
        if item[1] == 2 :
            image_filepath = ""
            image_filepath = scribus.getImageFile(item[0])
            print(image_filepath)
            if image_filepath != "" and not os.path.isfile(image_filepath) :
                item_missing.append((item[0], image_filepath))
# print(item_missing)

# read the link for the first image with a broken link and try to apply the path
# to each other image with a broken link
if item_missing :
    if scribus.messageBox("Missing images", "There are missing images. Do you want to look for them?", scribus.ICON_WARNING, scribus.BUTTON_YES, scribus.BUTTON_NO) == scribus.BUTTON_YES:
Beispiel #36
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

""" This Script redo hyphenation for the whole document """

import random
try:
    import scribus
except ImportError:
    print "This script only runs from within Scribus."
    sys.exit(1)

 

pRange = xrange(1, scribus.pageCount())
for p in pRange:
	scribus.gotoPage(p)
	items = scribus.getPageItems()
	for i in items:
		iname, itype, iorder = i
		if itype == 4:
			scribus.dehyphenateText(iname)
			scribus.hyphenateText(iname)

    # 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)

layer = scribus.getActiveLayer()

if ('placeholder' in scribus.getLayers()) :
    scribus.setActiveLayer('placeholder')
else:
    scribus.createLayer('placeholder')

for page in range(1, scribus.pageCount() + 1):
    scribus.gotoPage(page)
    drawPlaceholders()

scribus.setActiveLayer(layer)
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)
filecontent = filecontent.replace('PTYPE="16"', 'PTYPE="4"')
# quick and dirty workaround for setting PRINTABLE attribute to 1 if not already set:
filecontent = filecontent.replace('CLIPEDIT="1" PWIDTH=',
                                  'CLIPEDIT="1" PRINTABLE="1" PWIDTH=')
filecontent = filecontent.replace('CLIPEDIT="0" PWIDTH=',
                                  'CLIPEDIT="0" PRINTABLE="1" PWIDTH=')
filecontent = re.sub(r"(<DefaultStyle[^>].*?>)", "", filecontent)
filecontent = re.sub(r"(<TableData[^>].*?>)", "", filecontent)
filecontent = re.sub(r"(<Cell [^>].*?>)", "", filecontent)

newfile = slafile.replace(".sla", "_1-4.sla")
if os.path.isfile(newfile):
    scribus.messageBox(
        "Error: The file already exists", "The file '" + newfile +
        "' already exists.\The script has stopped; Please rename the existing file."
    )
else:
    ofile = open(newfile, "w").write(filecontent)
    scribus.openDoc(newfile)

    anzahl = scribus.pageCount()

    for seite in range(1, anzahl + 1):
        scribus.gotoPage(seite)
        objects = scribus.getAllObjects()
        for x in objects:
            width, height = scribus.getSize(x)
            scribus.sizeObject(100, 100, x)
            scribus.sizeObject(width, height, x)
            scribus.setLineShade(100, x)
                        "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 only one object and try again.", scribus.ICON_WARNING, scribus.BUTTON_OK)
     sys.exit(2)
 paste2 = scribus.valueDialog('Paste to...',"Paste where?\n(all, odd, even)","all")
 selframe = scribus.getSelectedObject()
 pages = scribus.pageCount()
 currpage = scribus.currentPage()
 scribus.copyObject(selframe)
 if (paste2 == 'all'):
     i = 1
     while (i <= pages):
         if (i != currpage):
             scribus.gotoPage(i)
             scribus.pasteObject(selframe)
         i=i+1
 elif (paste2 == 'odd'):
     i = 1
     while (i <= pages):
         if (i != currpage):
             scribus.gotoPage(i)
             scribus.pasteObject(selframe)
         i=i+2
 elif (paste2 == 'even'):
     i = 2
     while (i <= pages):
         if (i != currpage):
             scribus.gotoPage(i)
             scribus.pasteObject(selframe)
Beispiel #41
0
    def handleEnd(self):
        self.linkType = self.gui.getLinkType()
        self.gliederung = self.gui.getGliederung()
        self.includeSub = self.gui.getIncludeSub()
        self.start = self.gui.getStart()
        self.end = self.gui.getEnd()

        pos1, pos2, tbox = self.toBeDelPosParam
        scribus.selectText(pos1, pos2 - pos1, tbox)
        scribus.deleteText(tbox)

        pagenum = scribus.pageCount()
        for page in range(1, pagenum + 1):
            scribus.gotoPage(page)
            pageitems = scribus.getPageItems()
            for item in pageitems:
                if item[1] != 4:
                    continue
                self.textbox = item[0]
                self.evalTemplate()

        # hyphenate does not work
        # pagenum = scribus.pageCount()
        # for page in range(1, pagenum + 1):
        #     scribus.gotoPage(page)
        #     pageitems = scribus.getPageItems()
        #     for item in pageitems:
        #         if item[1] != 4:
        #             continue
        #         self.textbox = item[0]
        #         b = scribus.hyphenateText(self.textbox) # seems to have no effect!

        pagenum = scribus.pageCount()
        for page in range(1, pagenum + 1):
            scribus.gotoPage(page)
            pageitems = scribus.getPageItems()
            for item in pageitems:
                if item[1] != 4:
                    continue
                tbox = item[0]
                tbox2 = tbox
                while scribus.textOverflows(tbox2):
                    tbox2 = self.createNewPage(tbox2)
                    self.frameLinks[
                        tbox2] = tbox  # frame tbox2 has tbox as root

        scribus.redrawAll()
        ausgabedatei = self.ausgabedatei
        if ausgabedatei is None or ausgabedatei == "":
            ausgabedatei = "ADFC_" + self.gliederung + (
                "_I_" if self.includeSub else "_"
            ) + self.start + "-" + self.end + "_" + self.linkType[0] + ".sla"
        try:
            scribus.saveDocAs(ausgabedatei)
        except Exception as e:
            print("Ausgabedatei", ausgabedatei,
                  "konnte nicht geschrieben werden")
            raise e
        finally:
            self.touren = []
            self.termine = []
            # self.gui.destroy()
            # self.gui.quit()
            self.gui.disableStart()
def main(argv):

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

    info_text = '''
    Welcome to Auto-Photobook!
    
    1. Select the process mode:
        9f = creates a 9x9 layout on each page and fill them with images.
        4f = creates a 4x4 layout on each page and fill them with images.
        
        9e = creates an empty 9x9 layout on each page.
        4e = creates an empty 4x4 layout on each page.
        
        9f+4f = creates a filled 9x9 layout on odd pages and a filled 4x4 layout on even pages.
        9e+4e = creates an empty 9x9 layout on odd pages and an empty 4x4 layout on even pages.
        
        9f+4e = creates a filled 9x9 layout on odd pages and an empty 4x4 layout on even pages (default).
        9e+4f = creates an empty 9x9 layout on odd pages and a filled 4x4 layout on even pages.

    2. Select a document layout, the margins (they need to be equal) and the bleed (if needed). Ignore the number of pages.
    
    3. Define the space between the images (default: 6mm).
    
    4a. If "9f" or "4f" is in your mode, you can choose an image folder and an image filter will be prompted.
    4b. Otherwise, set the amount of pages you want to create (default: 10 pages).
    
    5. Wait until it is done...
    
    6. Adjust you layouts and move your images as you need.
    
    
    Process mode:'''

    # start dialog, choose mode

    #scribus.messageBox("Auto-Photobook", info_text)
    todo = scribus.valueDialog("Auto-Photobook", info_text, "9f+4e")
    todo = list(todo.split("+"))

    # wrong process mode
    if "9f" not in todo and "9e" not in todo and "4f" not in todo and "9e" not in todo:
        scribus.messageBox(
            "Error", "Wrong process mode. Auto-Photobook was cancelled.")
        sys.exit()

    # show new document dialog
    newdoc = scribus.newDocDialog()

    # exit if cancelled
    if newdoc == False:
        scribus.messageBox("Exit", "Auto-Photobook was cancelled.")
        sys.exit()

    if scribus.haveDoc:
        scribus.setUnit(scribus.UNIT_MILLIMETERS)
        (w, h) = scribus.getPageSize()

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

        # delete all pages except the first:
        pageamount = scribus.pageCount()
        while pageamount > 1:
            scribus.deletePage(pageamount)
            pageamount = scribus.pageCount()

        # set image border and bleed
        border = int(
            scribus.valueDialog("Space between images",
                                "Define the space between the images (mm).",
                                "6"))
        #border = 6

        # reset image border for easier calculations
        border = border * 0.75

        if "9f" in todo or "4f" in todo:
            # ask for workdir
            workdir = scribus.fileDialog("Open directory with images",
                                         "",
                                         haspreview=False,
                                         issave=False,
                                         isdir=True)
            #workdir = "/media/sda7/Programming/Python/scribus_auto_photobook/pics"

            # file filter
            filefilter = scribus.valueDialog(
                "File filter",
                "File filter examples: \n\n* or *.* = add all files\n*.jpg = add .jpg files only\nIMG_*.* = add all files starting with IMG_\n\nThis filter is case sensitive!",
                "*.*")

            # get image paths
            filelist = sorted(glob.glob(os.path.join(workdir, filefilter)))
            #filelist = sorted(glob.glob(os.path.join(workdir, "*")))

            # count files
            filesinworkdir = len(filelist)
            scribus.messageBox(
                "Files in directory",
                "Images matched in folder: " + str(filesinworkdir))

            #error
            if filesinworkdir == 0:
                scribus.messageBox("Error", "This directory is empty.")
                sys.exit()

            #messagebar text
            scribus.messagebarText("Importing images...")

            #progressbar max
            scribus.progressTotal(filesinworkdir)

            # set maxpages (not needed here but needs to be assigned)
            maxpages = len(filelist)

        else:
            # ask for page amount
            maxpages = int(
                scribus.valueDialog("Set page amount",
                                    "How many pages you want to create?",
                                    "10"))

            #progressbar max
            scribus.progressTotal(maxpages)

        # get page size (without bleed)
        size = scribus.getPageSize()

        # get margins
        margins = scribus.getPageMargins()[0]

        # set page final size
        final_size = (size[0] - margins, size[1] - margins)

        # simplify calc for 9x9 layout
        guide_layout_x = final_size[0] / 3 - margins / 3
        guide_layout_y = final_size[1] / 3 - margins / 3

        # set indexes
        page = 1
        pic = 0

        #create pages, add and load images
        x = True
        while x == True:
            scribus.progressSet(page)
            scribus.gotoPage(page)

            # create 9x9 layout
            if "9f" in todo or "9e" in todo:

                #guides
                scribus.setVGuides([
                    margins + guide_layout_x - border,
                    margins + guide_layout_x + border / 2,
                    margins + guide_layout_x * 2 - border / 2,
                    margins + guide_layout_x * 2 + border
                ])
                scribus.setHGuides([
                    margins + guide_layout_y - border,
                    margins + guide_layout_y + border / 2,
                    margins + guide_layout_y * 2 - border / 2,
                    margins + guide_layout_y * 2 + border
                ])

                # create images
                scribus.createImage(margins, margins,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image1")
                scribus.createImage(margins + guide_layout_x + border / 2,
                                    margins,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image2")
                scribus.createImage(margins + guide_layout_x * 2 + border,
                                    margins,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image3")

                scribus.createImage(margins,
                                    margins + guide_layout_y + border / 2,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image4")
                scribus.createImage(margins + guide_layout_x + border / 2,
                                    margins + guide_layout_y + border / 2,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image5")
                scribus.createImage(margins + guide_layout_x * 2 + border,
                                    margins + guide_layout_y + border / 2,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image6")

                scribus.createImage(margins,
                                    margins + guide_layout_y * 2 + border,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image7")
                scribus.createImage(margins + guide_layout_x + border / 2,
                                    margins + guide_layout_y * 2 + border,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image8")
                scribus.createImage(margins + guide_layout_x * 2 + border,
                                    margins + guide_layout_y * 2 + border,
                                    guide_layout_x + border - border * 2,
                                    guide_layout_y - border,
                                    "page" + str(page) + "image9")

                #load and scale images
                if "9f" in todo:

                    try:
                        scribus.loadImage(filelist[pic],
                                          "page" + str(page) + "image1")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image1")

                        scribus.loadImage(filelist[pic + 1],
                                          "page" + str(page) + "image2")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image2")

                        scribus.loadImage(filelist[pic + 2],
                                          "page" + str(page) + "image3")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image3")

                        scribus.loadImage(filelist[pic + 3],
                                          "page" + str(page) + "image4")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image4")

                        scribus.loadImage(filelist[pic + 4],
                                          "page" + str(page) + "image5")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image5")

                        scribus.loadImage(filelist[pic + 5],
                                          "page" + str(page) + "image6")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image6")

                        scribus.loadImage(filelist[pic + 6],
                                          "page" + str(page) + "image7")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image7")

                        scribus.loadImage(filelist[pic + 7],
                                          "page" + str(page) + "image8")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image8")

                        scribus.loadImage(filelist[pic + 8],
                                          "page" + str(page) + "image9")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image9")

                    except:
                        x = False

                    # increase picture index
                    pic += 9

                # add page
                scribus.newPage(-1)
                page += 1

            # create 4x4 layout
            if "4f" in todo or "4e" in todo:

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

                # create images
                scribus.createImage(margins, margins,
                                    size[0] / 2 - border * 0.75 - margins,
                                    size[1] / 2 - border * 0.75 - margins,
                                    "page" + str(page) + "image1")
                scribus.createImage(size[0] / 2 + border * 0.75, margins,
                                    size[0] / 2 - border * 0.75 - margins,
                                    size[1] / 2 - border * 0.75 - margins,
                                    "page" + str(page) + "image2")

                scribus.createImage(margins, size[1] / 2 + border * 0.75,
                                    size[0] / 2 - border * 0.75 - margins,
                                    size[1] / 2 - border * 0.75 - margins,
                                    "page" + str(page) + "image3")
                scribus.createImage(size[0] / 2 + border * 0.75,
                                    size[1] / 2 + border * 0.75,
                                    size[0] / 2 - border * 0.75 - margins,
                                    size[1] / 2 - border * 0.75 - margins,
                                    "page" + str(page) + "image4")

                #load and scale images
                if "4f" in todo:
                    try:

                        scribus.loadImage(filelist[pic],
                                          "page" + str(page) + "image1")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image1")

                        scribus.loadImage(filelist[pic + 1],
                                          "page" + str(page) + "image2")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image2")

                        scribus.loadImage(filelist[pic + 2],
                                          "page" + str(page) + "image3")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image3")

                        scribus.loadImage(filelist[pic + 3],
                                          "page" + str(page) + "image4")
                        scribus.setScaleImageToFrame(True,
                                                     proportional=True,
                                                     name="page" + str(page) +
                                                     "image4")

                    except:
                        x = False

                    # increase picture index
                    pic += 4

                # add page
                scribus.newPage(-1)
                page += 1

            #scribus.setImageOffset(0, 0, "imagename"+str(page))
            #scribus.setScaleFrameToImage(name="imagename"+str(page))

            # stop if maxpages reached
            if page > maxpages:
                x = False

        #delete last blank page
        scribus.deletePage(page)
    scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1)
    sys.exit(2)

charsIgnore = ["-", "–", "­", " ", ".", ":", ";", ";", "?", "!", "\n", "'", "‘", "’", "," "\"", "“", "”", "\r"]

button = scribus.messageBox('Confirmation', 'You should only scramble a copy of your document', scribus.ICON_WARNING, scribus.BUTTON_OK, scribus.BUTTON_CANCEL)
print button
if button == scribus.BUTTON_CANCEL :
    sys.exit(2)

selectedFrame = []
textFrame = []
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])
Beispiel #44
0
 def gotoPage(self, page):
     scribus.gotoPage(page)
     (self.topmargin, self.leftmargin, self.rightmargin,
      self.bottommargin) = getCurrentPageMargins()
     self.columnwidth = (self.pagewidth - self.leftmargin -
                         self.rightmargin - COLUMNGAP) / 2
Beispiel #45
0
of the same name in the new location. It the image is there, the link will be
replaced.

You would be wise to work on a copy of the original to avoid accidentally include
the wrong images.
"""

import scribus
import os.path

page_n = scribus.pageCount()
item_missing = []

# create a list of items with a brokein link
for page_i in range(0, page_n):
    scribus.gotoPage(page_i + 1)
    item_list = scribus.getPageItems()
    #print(item_list)
    for item in item_list:
        if item[1] == 2:
            image_filepath = ""
            image_filepath = scribus.getImageFile(item[0])
            print(image_filepath)
            if image_filepath != "" and not os.path.isfile(image_filepath):
                item_missing.append((item[0], image_filepath))
# print(item_missing)

# read the link for the first image with a broken link and try to apply the path
# to each other image with a broken link
if item_missing:
    if scribus.messageBox(
 
This script moves all images to a new layer called "Ghostlayer",
the idea being that you can show/hide, print-export/not as desired.
 
"""
import scribus

if scribus.haveDoc():

    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.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)
Beispiel #48
0

# open CSV file
data = getCSVdata(delim=delim, qc=qc)

# Process data
scribus.messagebarText("Processing "+str(nol)+" elements")
scribus.progressTotal(len(data))
for row in data:
    scribus.messagebarText("Processing "+str(nol)+" elements")
    celltext = row[numcol].strip()
    if len(celltext)!=0:
        createCell(celltext, cr, cc, CARDWIDTH, CARDHEIGHT, MARGINS[0], MARGINS[2], isBlack)
        nol=nol+1
        if cr==colstotal and cc==rowstotal:
            #create new page
            scribus.newPage(-1)
            scribus.gotoPage(scribus.pageCount())
            cr=1
            cc=1
        else:
            if cr==colstotal:
                cr=1
                cc=cc+1
            else:
                cr=cr+1
        scribus.progressSet(nol)
scribus.messagebarText("Processed "+str(nol)+" items. ")
scribus.progressReset()

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  #
    #########################
    script = "Aufschlussdoku.py"
    version = "20140107"
    csvfile = scribus.fileDialog("csv2table :: open file", "*.csv")
    fname_ext = csvfile[csvfile.rfind("/") + 1:]
    fname_noext = fname_ext[:fname_ext.rfind(".")]
    reader = csv.reader(open(csvfile, "rb"), delimiter=";")
    boxes = [["strat_d", 2.25], ["strat_n", 2.25], ["strat_b", 6.5], ["strat_p", 2.3], ["strat_a", 3.9]]
    start_x = float(1.9075)
    start_y = float(10.5)
    strats = []
    strat_ct = int(0)
    strat_ok = float(0.0)
    print getpass.getuser()

    for line in reader:
        if line[0].find("Tiefe bis [m]") <> 0:
            start_x_0 = start_x
            strat_ct = strat_ct + 1
            strat_d = line[0].replace(",", ".");
            strat_uk = float(strat_d) + float(strat_ok)
            strat_draw = float(strat_d) * 2.0
            strat_uk_draw = start_y + strat_draw

            if strat_uk_draw > 26.4:
                nPage = scribus.currentPage() + 1
                pageendtext = "Fortsetzung nächste Seite"
                #print nPage
                scribus.createText(start_x_0 + 0.1, start_y + 0.1, 17, 0.5, "box_txt_pageend")
                scribus.sentToLayer("profil_txt", "box_txt_pageend")
                scribus.setText(pageendtext, "box_txt_pageend")
                scribus.setStyle("Buchner_sehrklein", "box_txt_pageend")
                scribus.newPage(-1,"Buchner_Standard")
                scribus.gotoPage(nPage)
                start_y = float(5.5)
                strat_uk_draw = start_y + strat_draw
                
            box_nr = int(0)
            #print strat_uk
            #print "aktuelle Seite:", scribus.currentPage()

            #print strat_uk
            strat_uk_txt = str(strat_uk).replace(".", ",");
            #print strat_uk_txt
            strat_h = line[0]
            strat_n = line[1]
            strat_b = line[2]
            strat_p = line[3]
            strat_a = line[4]
            strat = [strat_d, strat_uk, strat_h, strat_n, strat_b, strat_p, strat_a]
            #print strat
            strats.append(strat)

            for box in boxes:
                box_n = box[0] + str(strat_ct)
                box_txt = strat[box_nr + 2]
                box_txt_n = box_n + "txt"
                
                #print box_nr
                #print box_txt
                #print box_n, box_txt_n, dimensions[1], position
                scribus.createRect(start_x_0, start_y, float(box[1]), strat_draw, box_n)
                scribus.setLineWidth(0.567, box_n)
                scribus.sentToLayer("profil_rahmen", box_n)
                if box_nr == 0:
                    scribus.createText(start_x_0 + 0.1, start_y + (strat_draw) - 0.4, float(box[1]) - 0.2, 0.4, box_txt_n)
                    #print strat_uk_txt
                    scribus.setText(strat_uk_txt, box_txt_n)
                else:
                    scribus.createText(start_x_0 + 0.1, start_y + 0.1, float(box[1]) - 0.2, (strat_draw) - 0.1, box_txt_n)
                    scribus.setText(box_txt, box_txt_n)
                scribus.setStyle("Buchner_Standard schmal", box_txt_n)
                scribus.sentToLayer("profil_txt", box_txt_n)
                start_x_0 = start_x_0 + float(box[1])
                box_nr = box_nr + 1
            #print "end: strat count:", strat_ct
            start_y = strat_uk_draw
            start_x_0 = start_x
            strat_ok = strat_ok + float(strat_d)
    print "end: all"
    scribus.createText(start_x_0 + 0.1, start_y + 0.1, 17, 0.5, "box_txt_end")
    scribus.sentToLayer("profil_txt", "box_txt_end")
    endtext = "Erstellt von " + getpass.getuser() + " mit " + fname_ext + ", " + script + " (V" + version + ")"
    scribus.setText(endtext, "box_txt_end")
    scribus.setStyle("Buchner_sehrklein", "box_txt_end")
    scribus.saveDocAs(fname_noext + ".sla")