Ejemplo n.º 1
0
def main(argv):
    """Main method - here we check if we have a doc - else we open one. we get all the colors and write them to a csv file."""
    if scribus.haveDoc() > 0:  #DOC OPEN
    #get colors, get filename, write stuff
        cols = getColorsFromDoc()
        filename = scribus.fileDialog("color2csv: Save csv color file", defaultname="colors.csv",  issave=True ,  haspreview=False)
        
        #@TODO: optimize path checking
        if filename !="":
            if os.path.exists(filename): #make sure we don't accidentally overwrite existing files
                answer= scribus.messageBox("color2csv", "File already exists! \n do you want to overwrite it?",  icon=scribus.ICON_WARNING,  button1=scribus.BUTTON_YES,  button2=scribus.BUTTON_ABORT)
                if answer == scribus.BUTTON_YES:
                    writeColorCsvFile(filename,  cols)
                else:
                    sys.exit()
            else:
                writeColorCsvFile(filename,  cols)
        else:
            sys.exit()
    else: # NO DOC OPEN - open one!
        scribusfile = scribus.fileDialog("color2csv: Open scribus file",  "Scribus files(*.sla *.SLA *.sla.gz *.SLA.GZ)")
        if scribusfile !="":
            try:
                scribus.openDoc(scribusfile)
            except:
                scribus.messageBox("color2csv", "Could not open file!")
                sys.exit()
            #get colors, get filename, write stuff
            cols = getColorsFromDoc()
            filename = scribus.fileDialog("color2csv: Save csv color file", defaultname="colors.csv",  issave=True )
            writeColorCsvFile(filename,  cols)
        else:
            sys.exit()
 def exportAll2PDF(self):
     self.textfile = ""
     self.filenames = ""
     # outputfile = scribus.fileDialog('Enter name of file to save to', filter='PDF Files (*.pdf);;All Files (*)')
     for element in self.root.iter("file"):
         scribus.openDoc(str(element.text))
         filename = os.path.splitext(os.path.basename(element.text))
         # self.filenames=self.filenames+" "+filename[0]
         # scribus.messageBox("Export PDF",self.filenames,icon=0,button1=1)
         self.textfile = "/tmp/" + filename[0] + ".pdf"
         # files+= self.textfile+" "
         self.export2PDF()
         self.exportWeb()
         scribus.closeDoc()
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)
Ejemplo n.º 5
0
    def exportPDF(self, scribusFilePath, pdfFilePath):
        # Export to PDF
        scribus.openDoc(scribusFilePath)
        listOfPages = []
        i = 0
        while (i < scribus.pageCount()):
            i = i + 1
            listOfPages.append(i)

        pdfExport = scribus.PDFfile()
        pdfExport.info = CONST.APP_NAME
        pdfExport.file = str(pdfFilePath)
        pdfExport.pages = listOfPages
        pdfExport.save()
        scribus.closeDoc()
    def syncPageNumbers(self):
        scribus.messageBox("Debut", "Apply page numbers", icon=0, button1=1)
        i = 0
        totalpages = 1
        # parses the book file; for each book document
        for element in self.root.iter("file"):
            files = element.text
            thing = etree.parse(files)
            # scribus.messageBox("Debut",str(files),icon=0,button1=1)

            rawstr = r"""Start=".+" R"""
            matchstr = etree.tostring(thing)
            compile_obj = re.compile(rawstr)
            textpage = 'Start="' + str(totalpages) + '" R'
            newstr = compile_obj.subn(str(textpage), etree.tostring(thing))

            # Open file in Scribus to get the page quantity for each file through scribus own method
            doc = scribus.openDoc(files)
            pageqty = scribus.pageCount()
            totalpages += pageqty  # sets the amount of page from the beginning of the first file
            scribus.closeDoc()
            # scribus.messageBox("Debut","begins at "+str(newstr[0]),icon=0,button1=1)

            FILE = open(files, "w")
            FILE.write(newstr[0])
            FILE.close()
Ejemplo n.º 7
0
def main(argv):
    """Main method - here we check if we have a doc - else we open one. we get all the colors and write them to a csv file."""
    if scribus.haveDoc() > 0:  #DOC OPEN
        #get colors, get filename, write stuff
        cols = getColorsFromDoc()
        filename = scribus.fileDialog("color2csv: Save csv color file",
                                      defaultname="colors.csv",
                                      issave=True,
                                      haspreview=False)

        #@TODO: optimize path checking
        if filename != "":
            if os.path.exists(
                    filename
            ):  #make sure we don't accidentally overwrite existing files
                answer = scribus.messageBox(
                    "color2csv",
                    "File already exists! \n do you want to overwrite it?",
                    icon=scribus.ICON_WARNING,
                    button1=scribus.BUTTON_YES,
                    button2=scribus.BUTTON_ABORT)
                if answer == scribus.BUTTON_YES:
                    writeColorCsvFile(filename, cols)
                else:
                    sys.exit()
            else:
                writeColorCsvFile(filename, cols)
        else:
            sys.exit()
    else:  # NO DOC OPEN - open one!
        scribusfile = scribus.fileDialog(
            "color2csv: Open scribus file",
            "Scribus files(*.sla *.SLA *.sla.gz *.SLA.GZ)")
        if scribusfile != "":
            try:
                scribus.openDoc(scribusfile)
            except:
                scribus.messageBox("color2csv", "Could not open file!")
                sys.exit()
            #get colors, get filename, write stuff
            cols = getColorsFromDoc()
            filename = scribus.fileDialog("color2csv: Save csv color file",
                                          defaultname="colors.csv",
                                          issave=True)
            writeColorCsvFile(filename, cols)
        else:
            sys.exit()
Ejemplo n.º 8
0
    def OPEN(arg):
        marg = re.search(r'(.*?):(.*)', arg)
        if marg:
            [opath, code] = [marg.group(1), marg.group(2)]
        else:
            logger.error('..bad argument: [%s]', arg)
            return 'ERR_BAD_ARG: %s' % arg

        logger.info('! open document %s, code %s', opath, code)
        try:
            # scribus.closeDoc()
            scribus.openDoc(opath)

        except scribus.ScribusException:
            logger.error('.can not open [%s], because %s', opath,
                         sys.exc_info()[1].message)
            return 'ERR_BAD_OPEN: %s', sys.exc_info()[1].message

        return 'DONE'
Ejemplo n.º 9
0
    def exportPDF(self, scribusFilePath, pdfFilePath):
        import scribus

        d = os.path.dirname(pdfFilePath)
        if not os.path.exists(d):
            os.makedirs(d)

        # Export to PDF
        scribus.openDoc(scribusFilePath)
        listOfPages = []
        i = 0
        while (i < scribus.pageCount()):
            i = i + 1
            listOfPages.append(i)

        pdfExport = scribus.PDFfile()
        pdfExport.info = CONST.APP_NAME
        pdfExport.file = str(pdfFilePath)
        pdfExport.pages = listOfPages
        pdfExport.save()
        scribus.closeDoc()
Ejemplo n.º 10
0
def getColorsFromDocument():
    """gets colors from opend document. if there is no document, display dialog to chose a file. returns a list[name,c,m,y,k]"""
    def getColors():
        """gets the colors and returns a list[name,c,m,y,k]"""
        colorNames = scribus.getColorNames()
        list = []
        scribus.statusMessage("Reading Colors...")
        stepsTotal = len(colorNames)
        scribus.progressTotal(stepsTotal)
        steps = 0
        for name in colorNames:
            color = scribus.getColor(name)
            listitem = [name, color[0], color[1], color[2], color[3]]
            list.append(listitem)
            #update progress bar
            steps = steps + 1
            scribus.progressSet(steps)
        return list

    #check if we have a document - otherwise display open file dialog
    if scribus.haveDoc() > 0:
        pass
        list = getColors()
        return list
    else:
        pass
        #display file open dialog
        file = scribus.fileDialog(
            "ColorChart by Sebastian Stetter",
            'Scribus files(*.sla *.SLA *.sla.gz *.SLA.GZ)')
        #open file
        try:
            scribus.openDoc(file)
        except:
            scribus.messageBox("ColorChart by Sebastian Stetter",
                               "could not open file")
            sys.exit()
        list = getColors()
        return list
Ejemplo n.º 11
0
def main():

    familles = get_families_ascii_names()
    for famille in familles:
        for n in range(1, 7):
            scribus.openDoc("template.sla")
            items = scribus.getPageItems()

            change_title(famille, n, items)
            change_number(famille, n, items)
            change_family(famille, n, items)
            change_advice(famille, n, items)
            change_family_members(famille, n, items)
            change_flavor(famille, n, items)
            change_background(famille, n, items)

            image = scribus.ImageExport()
            image.type = 'PNG'
            image.scale = 100
            image.saveAs(famille + "_" + str(n) + ".png")

            scribus.closeDoc()
def main(argv):
    """The main() function disables redrawing, sets a sensible generic
    status bar message, and optionally sets up the progress bar. It then runs
    the main() function. Once everything finishes it cleans up after the create()
    function, making sure everything is sane before the script terminates."""
    currentDoc = scribus.getDocName()
    try:
        scribus.statusMessage("Importing .csv table...")
        scribus.progressReset()
        create(argv)
        if scribus.haveDoc():
	  scribus.closeDoc()
	scribus.openDoc(currentDoc)
    finally:
        # Exit neatly even if the script terminated with an exception,
        # so we leave the progress bar and status bar blank and make sure
        # drawing is enabled.
        if scribus.haveDoc():
            scribus.setRedraw(True)
            scribus.closeDoc()
	scribus.openDoc(currentDoc)
        scribus.statusMessage("")
        scribus.progressReset()
Ejemplo n.º 13
0
def main():
    if not scribus.haveDoc():
        return

    filename = scribus.fileDialog('Select a document',
                                  'Scribus document (*.sla)')
    if not filename:
        return

    # find the masterpages in use in the source document
    scribus.openDoc(filename)
    pages = tuple(range(1, scribus.pageCount() + 1))
    masterpages = [scribus.getMasterPage(p) for p in pages]
    scribus.closeDoc()

    # the current page before importing
    page = scribus.currentPage()

    # import pages by creating them after the current one
    scribus.importPage(filename, pages, 1, 1)

    for i, masterpage in enumerate(masterpages):
        scribus.applyMasterPage(masterpage, page + 1 + i)
def main(argv):
    if not scribus.haveDoc():
        sys.exit(1)

    thecommand=""
    infile=os.getcwd()+"/this-is-a-temporary-file.sla"
    reimposed=os.getcwd()+"/reimposed-from-laidout.sla"

    thecommand="laidout --command 'Import(filename=\"" \
                +infile+"\", keepmystery=2)" \
                         +" Reimpose(orientation=landscape, paper=\"Tabloid\", imposition=\"Booklet\") " \
                         +" Export(filter=ScribusExportConfig(filename=\"" \
                +reimposed+"\", layout=\"Papers\"))' "
    #print "command:\n", thecommand

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


    try:
        os.system("/home/tom/p/sourceforge/laidout/src/laidout")
        #os.system(thecommand)

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

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

    #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- keep this around
    print "Removing temporary file ",infile,"..."
    os.remove(infile)
Ejemplo n.º 15
0
def main(argv):
    if not scribus.haveDoc():
        sys.exit(1)

    thecommand = ""
    infile = os.getcwd() + "/this-is-a-temporary-file.sla"
    reimposed = os.getcwd() + "/reimposed-from-laidout.sla"

    thecommand="laidout --command 'Import(filename=\"" \
                +infile+"\", keepmystery=2)" \
                         +" Reimpose(orientation=landscape, paper=\"Tabloid\", imposition=\"Booklet\") " \
                         +" Export(filter=ScribusExportConfig(filename=\"" \
                +reimposed+"\", layout=\"Papers\"))' "
    #print "command:\n", thecommand

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

    try:
        os.system("/home/tom/p/sourceforge/laidout/src/laidout")
        #os.system(thecommand)

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

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

    #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- keep this around
    print "Removing temporary file ", infile, "..."
    os.remove(infile)
Ejemplo n.º 16
0
def getColorsFromDocument():
    """gets colors from opend document. if there is no document, display dialog to chose a file. returns a list[name,c,m,y,k]"""

    def getColors():
        """gets the colors and returns a list[name,c,m,y,k]"""
        colorNames = scribus.getColorNames()
        list = []
        scribus.statusMessage("Reading Colors...")
        stepsTotal = len(colorNames)
        scribus.progressTotal(stepsTotal)
        steps = 0
        for name in colorNames:
            color = scribus.getColor(name)
            listitem = [name, color[0], color[1], color[2], color[3]]
            list.append(listitem)
            # update progress bar
            steps = steps + 1
            scribus.progressSet(steps)
        return list

    # check if we have a document - otherwise display open file dialog
    if scribus.haveDoc() > 0:
        pass
        list = getColors()
        return list
    else:
        pass
        # display file open dialog
        file = scribus.fileDialog("ColorChart by Sebastian Stetter", "Scribus files(*.sla *.SLA *.sla.gz *.SLA.GZ)")
        # open file
        try:
            scribus.openDoc(file)
        except:
            scribus.messageBox("ColorChart by Sebastian Stetter", "could not open file")
            sys.exit()
        list = getColors()
        return list
Ejemplo n.º 17
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import scribus

scribus.openDoc('/Users/mforaste/Desktop/gabarit_test.sla')
scribus.setText('Resultat concluant : ' + sys.argv[1], 'Text4')
scribus.saveDoc()
scribus.closeDoc()
Ejemplo n.º 18
0
def main(argv):
    if not scribus.haveDoc():
        sys.exit(1)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- might cause problems, but keep around for research
    print "Removing temporary file ", infile, "..."
    os.remove(infile)
    print "All done!"
def init():
    scribus.openDoc(pwd("init.sla"))
    scribus.saveDocAs("/tmp/{}.sla".format(time.time()))
    scribus.setUnit(scribus.UNIT_MM)
Ejemplo n.º 20
0
def get_pages_range(sla_file):
    scribus.openDoc(sla_file)
    page_count = range(1, scribus.pageCount() + 1)
    scribus.closeDoc()

    return tuple(page_count)
Ejemplo n.º 21
0
    # Variables
    base_file = os.path.abspath(args.files[0])
    import_file = os.path.abspath(args.files[1])
    page_number = args.page - 1
    insert_position = 0 if args.before is True else 1  # 0 = before; 1 = after
    master_page = args.masterpage
    total_pages = get_pages_range(import_file)

    # Output path
    output_file = args.output

    if output_file is not None:
        output_file = os.path.abspath(args.output)

    # Importing `import_file`
    scribus.openDoc(base_file)
    scribus.importPage(
        import_file, total_pages, 1, insert_position, page_number
    )

    # Applying masterpage(s)
    if master_page is not None:
        for number in range(page_number + 2, page_number + len(total_pages) + 2):
            scribus.applyMasterPage(master_page, number)

    # Either overwriting `base_file` ..
    if output_file is None:
        scribus.saveDoc()
    # .. or creating new `output` file (requires `--output`)
    else:
        scribus.saveDocAs(output_file)
Ejemplo n.º 22
0
 def startDocument(self):
     """Open document"""
     scribus.openDoc(self.template)
     self.name = self.make_textframe()
Ejemplo n.º 23
0
IMG_TYPE = 2

directory = sys.argv[-1]
filenames = glob.glob(directory + '/[0-9]*.sla')
# Cards whose text is too long, and must therefore use a smaller font
indices_with_long_text = [10, 12, 23, 39, 44, 46, 57]
# HACK! I'm sorry :(
files_with_long_text = [
    "{}{}.sla".format(directory, i) for i in indices_with_long_text
]
if not filenames:
    print("No documents with expected name found in " + directory)
for infile in filenames:
    print("Opening " + infile)
    scribus.openDoc(infile)
    # Auto-scale the picture
    try:
        # Find which image object we must change
        images = [s for s in scribus.getPageItems() if s[1] == IMG_TYPE]
        frame = sorted(images, key=lambda s: s[2])[-1][0]
        # frame should be "Image9" if all elements are rendered
        scribus.setScaleImageToFrame(True, name=frame)
        scribus.saveDoc()
    except NoValidObjectError, err:
        print("Image not found in " + infile)
    # Change the text size if necessary
    print(infile)
    if infile in files_with_long_text:
        print("Found " + infile + "!!!")
        try:
def main(argv):
    if not scribus.haveDoc():
        sys.exit(1)

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

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

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

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

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

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

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

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


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

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

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

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

    #if (os.path.isfile(reimposed)): os.remove(reimposed) <-- might cause problems, but keep around for research
    print "Removing temporary file ",infile,"..."
    os.remove(infile)
    print "All done!"
Ejemplo n.º 25
0
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)
Ejemplo n.º 26
0
import scribus
import argparse

parser = argparse.ArgumentParser(
    description="Deletes page from an `.sla` file")

parser.add_argument(
    "file",
    default=None,
    help="SLA file to be processed",
)

parser.add_argument(
    "--page",
    type=int,
    help="Number of pages being deleted",
)

if __name__ == "__main__":
    args = parser.parse_args()

    # Open document
    scribus.openDoc(os.path.abspath(args.file))

    # Delete page
    scribus.deletePage(args.page)

    # Save & close document
    scribus.saveDoc()
    scribus.closeDoc()
      for the_file in os.listdir(baseDirName):
	file_path = os.path.join(baseDirName, the_file)
	try:
	  if os.path.isfile(file_path):
	    os.unlink(file_path)
	except Exception, e:
	  print e
    
    
    #Make Document Temporary
    scribus.saveDoc()
    scribus.saveDocAs(tmpFileName)
    scribus.messagebarText("Dokument in Bearbeitung, bitte warten")
    scribus.closeDoc()
    scribus.messagebarText("Dokument in Bearbeitung, bitte warten")
    scribus.openDoc(tmpFileName)
    
    
    scribus.selectText(0, 1, idtextstring)
    idfont = scribus.getFont(idtextstring)
    idfonSize = scribus.getFontSize(idtextstring)
    idtextcolor = scribus.getTextColor(idtextstring)
    idtextshade = scribus.getTextShade(idtextstring)
    
    scribus.selectText(0, 1, gertextstring)
    gerfont = scribus.getFont(gertextstring)
    gerfonSize = scribus.getFontSize(gertextstring)
    gertextcolor = scribus.getTextColor(gertextstring)
    gertextshade = scribus.getTextShade(gertextstring)
    
    scribus.selectText(0, 1, lattextstring)
def init():
    scribus.openDoc(pwd("init.sla"))
    scribus.saveDocAs("/tmp/{}.sla".format(time.time()))
    scribus.setUnit(scribus.UNIT_MM)
Ejemplo n.º 29
0
def processFile():
   

def frontPage(LogoPath, ChurchPath, ChurchImage, Citation, CitationLocation):
    #scribus.setText('Gemeindebrief   DIGITAL Buxtehude',"Oben")

    #Line upper left corner
    l_line = scribus.createLine(10,10,10,33,"l_Line")
    scribus.setLineWidth(0.75, l_line)
    scribus.setLineColor("NAK-blau 100%", l_line)
    scribus.setLineShade("NAK-blau 100%", l_line)

    #Headline
    t_headline = scribus.createText(10,22,128,20,"t_Headline")
    scribus.setText("Gemeindebrief", t_headline)
    scribus.selectText(1, 100, t_headline)
    scribus.setCharacterStyle(
        "Erste Seite - Gemeindebrief - gross", t_headline)
    scribus.deselectAll()
    # Digital - Text
    t_digitalText = scribus.createText(107,27,30,7, "t_Digital")
    scribus.selectText(1, 100, t_digitalText)
    scribus.setCharacterStyle(
        "Erste Seite - Gemeindebrief - gross", t_digitalText)
    scribus.deselectAll()
    # Congregation - Text
    t_congregationText = scribus.createText(10,35.250, 70, 6, "t_Congregation")
    scribus.selectText(1, 100, t_congregationText)
    scribus.setCharacterStyle(
        "Erste Seite - Gemeindebrief - klein", t_congregationText)
    scribus.deselectAll()

    # Month Year
    t_monthYear = scribus.createText(56, 46.500, 82, 10, "t_MonthYear")
    scribus.selectText(1, 100, t_monthYear)
    scribus.setCharacterStyle(
        "Erste Seite - Gemeindebrief - Monat", t_monthYear)
    scribus.deselectAll()

    # Logo charitable
    i_charitable = scribus.createImage(10, 46, 35.5, 9, "i_NAC_charitable")
    scribus.loadImage(LogoPath + "Logo_NAK_karitativ_HQ.tiff", i_charitable)
    scribus.setImageScale(0.0613, 0.0613, i_charitable)
    
    # Church image
    i_churchImage = scribus.createImage(10,57,128,100,"i_Church")
    scribus.loadImage(ChurchPath + ChurchImage, i_churchImage)
    scribus.setImageScale(1, 1, i_churchImage)
    scribus.setImageOffset(-18.244, -0.342, i_churchImage)
    
    # Citation
    t_citation = scribus.createText(42.500, 162.500,95.500,4.500, "t_Citation")
    # OverflowCheck
    scribus.setText(Citation, t_citation)
    scribus.selectText(1, 100, t_citation)
    scribus.setCharacterStyle("Erste Seite - Bibelzitat - Text", t_citation)
    scribus.deselectAll()
    # Citation Location
    t_citationLocation = scribus.createText(42.500, 170, 95.500, 3, "t_CitationLocation")
    scribus.setText(CitationLocation, t_citationLocation)
    scribus.selectText(1, 100, t_citationLocation)
    scribus.setCharacterStyle(
        "Erste Seite - Bibelzitat - Ort", t_citationLocation)
    scribus.deselectAll()

    # NAC
    t_nac = scribus.createText(52.500,195,66,5,"t_NAC")
    scribus.setText("Neuapostolische Kirche", t_nac)
    scribus.selectText(1, 100, t_nac)
    scribus.setCharacterStyle("Erste Seite - NAK", t_nac)
    scribus.deselectAll()
    # North and east germany
    t_northEastGermany = scribus.createText(52.500, 195, 66, 5, "t_NorthEastGermany")
    scribus.setText("Nord- und Ostdeutschland", t_northEastGermany)
    scribus.selectText(1, 100, t_northEastGermany)
    scribus.setCharacterStyle(
        "Erste Seite - Nord- und Ostdeutschland", t_northEastGermany)
    scribus.deselectAll()

    # NAC Logo
    i_nacLogo = scribus.createImage(122, 184, 16, 16,"i_Logo")
    scribus.loadImage("L:\\GB\\Bilder\\Logos\\Logo_NAK_HQ.tif", i_nacLogo)
    scribus.setImageScale(0.0384, 0.0384, i_nacLogo)

    scribus.saveDocAs()

def colors():
    scribus.defineColorCMYKFloat("NAK-blau 100%", 68.0, 34.0, 0.0, 0.0)
    scribus.defineColorRGB("Tabelle-Hintergrund", 215, 225, 243)
    scribus.deleteColor("Blue")
    scribus.deleteColor("Cool Black")
    scribus.deleteColor("Cyan")
    scribus.deleteColor("Green")
    scribus.deleteColor("Magenta")
    scribus.deleteColor("Red")
    scribus.deleteColor("Registration")
    scribus.deleteColor("Rich Black")
    scribus.deleteColor("Warm Black")
    scribus.deleteColor("Yellow")

def createCharStyle(Name, Font, FontSize, Features="", BaseLineOffset = 0, Tracking = 0):
    scribus.createCharStyle(
        Name,
        font=Font,
        fontsize=FontSize,
        features=Features,
        fillcolor="",
        fillshade=1.0,
        strokecolor="Black",
        strokeshade=1.0,
        baselineoffset=BaseLineOffset,
        shadowxoffset=0,
        shadowyoffset=0,
        outlinewidth=0,
        underlineoffset=0,
        underlinewidth=0,
        strikethruoffset=0,
        strikethruwidth=0,
        scaleh=1,
        scalev=1,
        tracking=Tracking
    )


def createParagraphStyle(Name, LineSpacingMode, Alignment, LeftMargin, RightMargin, GapBefore, GapAfter, FirstIndent, CharStyle, LineSpacing = 0, HasDropCap = 0, DropCapLines = 0 ):
    
    if (LineSpacingMode != 0 and HasDropCap != 0 ):
        scribus.createParagraphStyle(
            Name,
            linespacingmode=LineSpacingMode,
            alignment=Alignment,
            leftmargin=LeftMargin,
            rightmargin=RightMargin,
            gapbefore=GapBefore,
            gapafter=GapAfter,
            firstindent=FirstIndent,
            hasdropcap=HasDropCap,
            dropcaplines=DropCapLines,
            charstyle=CharStyle)
    if (LineSpacingMode == 0 and HasDropCap != 0):
        scribus.createParagraphStyle(
            Name,
            linespacingmode=LineSpacingMode,
            linespacing=LineSpacing,
            alignment=Alignment,
            leftmargin=LeftMargin,
            rightmargin=RightMargin,
            gapbefore=GapBefore,
            gapafter=GapAfter,
            firstindent=FirstIndent,
            hasdropcap=HasDropCap,
            dropcaplines=DropCapLines,
            charstyle=CharStyle)
    if (LineSpacingMode != 0 and HasDropCap == 0):
        scribus.createParagraphStyle(
            Name,
            linespacingmode=LineSpacingMode,
            alignment=Alignment,
            leftmargin=LeftMargin,
            rightmargin=RightMargin,
            gapbefore=GapBefore,
            gapafter=GapAfter,
            firstindent=FirstIndent,
            hasdropcap=HasDropCap,
            charstyle=CharStyle)
    if (LineSpacingMode == 0 and HasDropCap == 0):
        scribus.createParagraphStyle(
            Name,
            linespacingmode=LineSpacingMode,
            linespacing=LineSpacing,
            alignment=Alignment,
            leftmargin=LeftMargin,
            rightmargin=RightMargin,
            gapbefore=GapBefore,
            gapafter=GapAfter,
            firstindent=FirstIndent,
            hasdropcap=HasDropCap,
            charstyle=CharStyle)


def processInterfaceFile(InterfaceFile):
     with open(InterfaceFile) as lfiInterfaceFile:
        larrData = json.load(lfiInterfaceFile)

    # Output: {'name': 'Bob', 'languages': ['English', 'Fench']}
    print(larrData)

    for larrAction in larrData:
        print(lstrFile)
        scribus.openDoc(lstrFile)
        lstrFilename = os.path.splitext(scribus.getDocName())[0]
        pdf = scribus.PDFfile()
        pdf.compress = True
        pdf.compressmtd = 1
        pdf.quality = 2
        pdf.file = lstrFilename+".pdf"
        pdf.save()
        scribus.closeDoc()