Exemple #1
0
def create_document():
    my_document = odf_new_document('text')
    style_filename = "estils/estils_programa.odt"
    style_document = odf_get_document(style_filename)
    my_document.delete_styles()
    my_document.merge_styles_from(style_document)
    return my_document
def get_slides_deck(decks_and_slides, output):
    new_deck = odf_new_document('presentation')
    new_deck.delete_styles()
    new_deck_body = new_deck.get_body()
    new_deck_manifest = new_deck.get_part(ODF_MANIFEST)

    for deck_and_slides in decks_and_slides:
        deck = odf_get_document(deck_and_slides.deck)
        if deck == None:
            continue
        new_deck.merge_styles_from(deck)
        deck_body = deck.get_body()
        deck_manifest = deck.get_part(ODF_MANIFEST)
        for slide in deck_and_slides.slides:
            try:
                slide_position = int(slide) - 1  # Assuming index starts with 1
                source_slide = deck_body.get_draw_page(position=slide_position)
            except:
                continue
            if source_slide == None:
                continue

            # Copy Images
            for image in source_slide.get_images():
                uri = image.get_url()
                media_type = deck_manifest.get_media_type(uri)
                new_deck_manifest.add_full_path(uri, media_type)
                new_deck.set_part(uri, deck.get_part(uri))

            new_deck_body.append(source_slide.clone())

    new_deck.save(target=output, pretty=True)
Exemple #3
0
    def get_document(self):
        result = BytesIO()
        document = odf_new_document('text')
        setup_document_styles(document)
        body = document.get_body()

        # Create the Table Of Content
        toc = odf_create_toc()
        # Changing the default "Table Of Content" Title :
        toc.set_title("Table of Content")

        # Do not forget to add every components to the document:
        body.append(toc)

        for table in self.tables:
            if hasattr(table, 'get_odt_data'):
                odt_data = table.get_odt_data(document)

                body.extend(odt_data)

        toc.fill()

        document.save(target=result, pretty=True)

        return result.getvalue()
def create_document():
    my_document = odf_new_document('text')
    style_filename = "estils/estils_programa.odt"
    style_document = odf_get_document(style_filename)
    my_document.delete_styles()
    my_document.merge_styles_from(style_document)
    return my_document
Exemple #5
0
def get_slides_deck(decks_and_slides, output):
    new_deck = odf_new_document('presentation')
    new_deck.delete_styles()
    new_deck_body = new_deck.get_body()
    new_deck_manifest = new_deck.get_part(ODF_MANIFEST)

    for deck_and_slides in decks_and_slides:
        deck = odf_get_document(deck_and_slides.deck)
        if deck == None:
            continue
        new_deck.merge_styles_from(deck)
        deck_body = deck.get_body()
        deck_manifest = deck.get_part(ODF_MANIFEST)
        for slide in deck_and_slides.slides:
            try:
                slide_position = int(slide) - 1 # Assuming index starts with 1
                source_slide = deck_body.get_draw_page(position = slide_position)
            except:
                continue
            if source_slide == None:
                continue

            # Copy Images
            for image in source_slide.get_images():
                uri = image.get_url()
                media_type = deck_manifest.get_media_type(uri)
                new_deck_manifest.add_full_path(uri, media_type)
                new_deck.set_part(uri, deck.get_part(uri))

            new_deck_body.append(source_slide.clone())

    new_deck.save(target=output, pretty=True)
Exemple #6
0
def create_table(labels, results):

    document = odf_new_document('spreadsheet')
    body = document.get_body()
    table = odf_create_table("results")

    row = odf_create_row()
    rnbr = 1
    for lang in sorted(results):
        cell = odf_create_cell()
        cell.set_value(lang, text=lang)
        row.set_cell(rnbr, cell)
        rnbr += 1
    table.set_row(0, row)

    lnbr = 1

    for i in range(len(labels)):
        row = odf_create_row()
        cell = odf_create_cell()
        cell.set_value(labels[i], text=labels[i])
        row.set_cell(0, cell)
        rnbr = 1
        for lang in sorted(results):
            cell = odf_create_cell()
            val = results[lang][i]
            cell.set_value(val, text="%.5f" % val, cell_type="float")
            row.set_cell(rnbr, cell)
            rnbr += 1
        table.set_row(lnbr, row)
        lnbr += 1

    body.append(table)
    document.save(target="__res2.ods", pretty=True)
Exemple #7
0
 def test_mimetype(self):
     path = '../templates/drawing.otg'
     document = odf_new_document(path)
     mimetype = document.get_part('mimetype')
     self.assertFalse('template' in mimetype)
     manifest = document.get_part(ODF_MANIFEST)
     media_type = manifest.get_media_type('/')
     self.assertFalse('template' in media_type)
Exemple #8
0
 def test_mimetype(self):
     path = '../lpod/templates/drawing.otg'
     document = odf_new_document(path)
     mimetype = document.get_part('mimetype')
     self.assertFalse('template' in mimetype)
     manifest = document.get_part(ODF_MANIFEST)
     media_type = manifest.get_media_type('/')
     self.assertFalse('template' in media_type)
 def test_mimetype(self):
     path = "../templates/drawing.otg"
     document = odf_new_document(path)
     mimetype = document.get_part("mimetype")
     self.assertFalse("template" in mimetype)
     manifest = document.get_part(ODF_MANIFEST)
     media_type = manifest.get_media_type("/")
     self.assertFalse("template" in media_type)
Exemple #10
0
def init_doc(filename, mimetype):
    if mimetype in (ODF_TEXT, ODF_SPREADSHEET, ODF_PRESENTATION):
        output_doc = odf_get_document(filename)
        if mimetype == ODF_TEXT:
            # Extra for text: begin with a TOC
            output_body = output_doc.get_body()
            output_body.insert(odf_create_toc(), FIRST_CHILD)
    elif mimetype in (CSV_SHORT, CSV_LONG):
        output_doc = odf_new_document('spreadsheet')
        add_csv(filename, output_doc)
    else:
        raise NotImplementedError, mimetype
    return output_doc
Exemple #11
0
def init_doc(filename, mimetype):
    if mimetype in (ODF_TEXT, ODF_SPREADSHEET, ODF_PRESENTATION):
        output_doc = odf_get_document(filename)
        if mimetype == ODF_TEXT:
            # Extra for text: begin with a TOC
            output_body = output_doc.get_body()
            output_body.insert(odf_create_toc(), FIRST_CHILD)
    elif mimetype in (CSV_SHORT, CSV_LONG):
        output_doc = odf_new_document('spreadsheet')
        add_csv(filename, output_doc)
    else:
        raise NotImplementedError(mimetype)
    return output_doc
 def test_add_chart_structure_in_document(self):
     doc = odf_new_document('spreadsheet')
     name = add_chart_structure_in_document(doc)
     chart_content = odf_xmlpart(name+'/content.xml', doc)
     expected =(
       '<?xml version="1.0" encoding="UTF-8"?>\n'
       '<office:document-content '
       'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" '
       'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" '
       'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" '
       'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" '
       'xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" '
       'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" '
       'xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" '
       'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" '
       'xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" '
       'xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" '
       'xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" '
       'xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" '
       'xmlns:math="http://www.w3.org/1998/Math/MathML" '
       'xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" '
       'xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" '
       'xmlns:ooo="http://openoffice.org/2004/office" '
       'xmlns:ooow="http://openoffice.org/2004/writer" '
       'xmlns:oooc="http://openoffice.org/2004/calc" '
       'xmlns:dom="http://www.w3.org/2001/xml-events" '
       'xmlns:xforms="http://www.w3.org/2002/xforms" '
       'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
       'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
       'xmlns:rpt="http://openoffice.org/2005/report" '
       'xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" '
       'xmlns:xhtml="http://www.w3.org/1999/xhtml" '
       'xmlns:grddl="http://www.w3.org/2003/g/data-view#" '
       'xmlns:tableooo="http://openoffice.org/2009/table" '
       'xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" '
       'xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" '
       'office:version="1.2" '
       'grddl:transformation="http://docs.oasis-open.org/office/1.2/xslt/odf2rdf.xsl">\n\n  '
       '<office:automatic-styles/>\n  '
       '<office:body>\n    '
       '<office:chart/>\n  '
       '</office:body>\n'
       '</office:document-content>')
     self.assertEqual(chart_content.serialize(), expected)
Exemple #13
0
 def test_add_chart_structure_in_document(self):
     doc = odf_new_document('spreadsheet')
     name = add_chart_structure_in_document(doc)
     chart_content = odf_xmlpart(name + '/content.xml', doc)
     expected = (
         '<?xml version="1.0" encoding="UTF-8"?>\n'
         '<office:document-content '
         'xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" '
         'xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" '
         'xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" '
         'xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" '
         'xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" '
         'xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" '
         'xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" '
         'xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" '
         'xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" '
         'xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" '
         'xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" '
         'xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" '
         'xmlns:math="http://www.w3.org/1998/Math/MathML" '
         'xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" '
         'xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" '
         'xmlns:ooo="http://openoffice.org/2004/office" '
         'xmlns:ooow="http://openoffice.org/2004/writer" '
         'xmlns:oooc="http://openoffice.org/2004/calc" '
         'xmlns:dom="http://www.w3.org/2001/xml-events" '
         'xmlns:xforms="http://www.w3.org/2002/xforms" '
         'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '
         'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '
         'xmlns:rpt="http://openoffice.org/2005/report" '
         'xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" '
         'xmlns:xhtml="http://www.w3.org/1999/xhtml" '
         'xmlns:grddl="http://www.w3.org/2003/g/data-view#" '
         'xmlns:tableooo="http://openoffice.org/2009/table" '
         'xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" '
         'xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0" '
         'office:version="1.2" '
         'grddl:transformation="http://docs.oasis-open.org/office/1.2/xslt/odf2rdf.xsl">\n\n  '
         '<office:automatic-styles/>\n  '
         '<office:body>\n    '
         '<office:chart/>\n  '
         '</office:body>\n'
         '</office:document-content>')
     self.assertEqual(chart_content.serialize(), expected)
# -*- coding: UTF-8 -*-
from lpod.document import odf_new_document
from lpod.heading import odf_create_heading
from lpod.paragraph import odf_create_paragraph

document = odf_new_document('text')
body = document.get_body()

# Let's add another section to make our document clear:

body.append(odf_create_heading(1, u"Tables"))
body.append(odf_create_paragraph(u"A 3x3 table:"))

# Creating a table :

from lpod.table import odf_create_table
table = odf_create_table(u"Table 1", width=3, height=3)
body.append(table)
Exemple #15
0
 def test_drawing_type(self):
     document = odf_new_document('drawing')
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS['odg'])
Exemple #16
0
 def test_spreadsheet_type(self):
     document = odf_new_document('spreadsheet')
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS['ods'])
Exemple #17
0
from lpod.document import odf_get_document, odf_new_document

filename = "presentation_base.odp"

# For convenience we use some remote access to the document
#from urllib2 import urlopen
#filename = urlopen("http://arsaperta.org/presentation_base.odp")
presentation_base = odf_get_document(filename)

output_filename = "my_extracted_slides.odp"

if __name__ == "__main__":
    #extract = sys.argv[1:]
    extract = " 3 5 2 2"

    extracted = odf_new_document('presentation')

    body_base = presentation_base.get_body()
    body_extracted = extracted.get_body()

    # Important, copy styles too:
    extracted.delete_styles()
    extracted.merge_styles_from(presentation_base)

    for i in extract.split():
        try:
            slide_position = int(i) - 1
            slide = body_base.get_draw_page(position=slide_position)
        except:
            continue
        if slide is None:
Exemple #18
0
        print "Need some old picture !"
        parser.print_help()
        exit(0)
    if not options.new_img:
        print "Need some new picture !"
        parser.print_help()
        exit(0)
    if not sources:
        print "Need some ODF source !"
        parser.print_help()
        exit(0)

    t0 = time.time()
    old_content_footprint = make_footprint(file(options.old_img).read())
    # making the new image content :
    buffer = odf_new_document('text')
    url = buffer.add_file(options.new_img)
    new_content = buffer.get_part(url)

    for source in sources:
        if os.path.isdir(source):
            for root, dirs, files in os.walk(source):
                for name in files:
                    replace_odf_pics(os.path.join(root, name),
                                     old_content_footprint, new_content)
        else:
            replace_odf_pics(source, old_content_footprint, new_content)
    elapsed = int(time.time() - t0)
    print "%s images updated from %s images in %s ODF files in %s sec." % (
        counter_hit, counter_image, counter_odf, elapsed)
Exemple #19
0
 def test_spreadsheet_type(self):
     document = odf_new_document('spreadsheet')
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS['ods'])
Exemple #20
0
 def test_presentation_template(self):
     path = '../lpod/templates/presentation.otp'
     self.assert_(odf_new_document(path))
 def test_text_type(self):
     document = odf_new_document("text")
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS["odt"])
 def test_drawing_template(self):
     path = "../templates/drawing.otg"
     self.assert_(odf_new_document(path))
 def test_text_template(self):
     path = "../templates/text.ott"
     self.assert_(odf_new_document(path))
    def __init__(self, name, price):
        self.name = "Product %s" % name
        self.price = price

def make_catalog():
    cat_list = []
    price = 10.0
    for p in range(5):
        cat_list.append(Product(chr(65 + p), price))
        price += 10.5
    return cat_list

tax_rate = .196

if __name__=="__main__":
    commercial = odf_new_document('text')
    body = commercial.get_body()
    catalog = make_catalog()

    title1 = odf_create_heading(1, u"Basic commercial document")
    body.append(title1)
    title11 = odf_create_heading(2, u"Available products")
    body.append(title11)
    paragraph = odf_create_paragraph(u"Here the list:")
    body.append(paragraph)

    # List of products in a list :
    product_list = odf_create_list()
    body.append(product_list)
    for product in catalog:
        item = odf_create_list_item(u"%-10s, price: %.2f €" % (
Exemple #25
0
def setup():
    global testdoc, odf_renderer, mkdown
    testdoc = odf_new_document('presentation')
    odf_renderer = odpdown.ODFRenderer(testdoc, u'Nimbus Mono L')
    mkdown = mistune.Markdown(renderer=odf_renderer)
 def test_spreadsheet_type(self):
     document = odf_new_document("spreadsheet")
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS["ods"])
Exemple #27
0
 def test_text_template(self):
     path = '../lpod/templates/text.ott'
     self.assert_(odf_new_document(path))
 def test_presentation_type(self):
     document = odf_new_document("presentation")
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS["odp"])
Exemple #29
0
 def __init__(self, name):
     self.document = document = odf_new_document('spreadsheet')
     self.table = table = odf_create_table(name)
     document.get_body().append(table)
     document.insert_style(self.header_style, automatic=True)
 def test_drawing_type(self):
     document = odf_new_document("drawing")
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS["odg"])
Exemple #31
0
from lpod.variable import odf_create_date_variable, odf_create_time_variable
from lpod.variable import odf_create_chapter_variable
from lpod.variable import odf_create_filename_variable
from lpod.table import odf_create_table
from lpod.styles import rgb2hex
from lpod import __version__, __installation_path__

# Hello messages
print 'lpod installation test'
print ' Version           : %s' % __version__
print ' Installation path : %s' % __installation_path__
print
print 'Generating test_output/use_case2.odt ...'

# Go
document = odf_new_document('text')
body = document.get_body()

# 1- The image
# ------------
image = Image.open('samples/image.png')
width, height = image.size
paragraph = odf_create_paragraph(style=u"Standard")
# 72 ppp
frame = odf_create_frame('frame1', 'Graphics',
                         str(width / 72.0) + 'in',
                         str(height / 72.0) + 'in')
internal_name = 'Pictures/image.png'
image = odf_create_image(internal_name)
frame.append(image)
paragraph.append(frame)
Exemple #32
0
            crop_size = True

    output_file = options.output
    if not output_file.endswith(".odp"):
        output_file += ".odp"

    # Collecting images
    collect_sources(sources)
    if not images_pool:         # unable to find images
        print "no image found !"
        parser.print_help()
        exit(0)

    # Creation of the output Presentation document :
    # presentation = odf_new_document_from_type('presentation')  # 092
    presentation = odf_new_document('presentation')

    # Presentation got a body in which content is stored
    presentation_body = presentation.get_body()

    # For each image, we create a page in the presentation and display the image
    # and some text on this frame
    for image in images_pool:
        # add the file to the document
        uri = presentation.add_file(image.path)

        # Create an underlying page for the image and the text
        page = odf_create_draw_page("Page "+ image.name)

        # Create a frame for the image
        image_frame = odf_create_image_frame(
Exemple #33
0
 def test_drawing_template(self):
     path = '../templates/drawing.otg'
     self.assert_(odf_new_document(path))
# -*- coding: UTF-8 -*-
# Let's add another section to make our document clear:
# Annotations are notes that don’t appear in the document but typically on a
# side bar in a desktop application. So they are not printed.
from lpod.document import odf_new_document
from lpod.paragraph import odf_create_paragraph

from lpod.heading import odf_create_heading

document = odf_new_document("text")
body = document.get_body()

body.append(odf_create_heading(1, u"Annotations"))
paragraph = odf_create_paragraph(u"A paragraph with an annotation in the middle.")
body.append(paragraph)

# Annotations are inserted like notes but they are simpler:

paragraph.insert_annotation(after=u"annotation", body=u"It's so easy!", creator=u"Luis")

# Annotation arguments are quite different:
# after   =>  The word after what the annotation is inserted.
# body    =>  The annotation itself, at the end of the page.
# creator =>  The author of the annotation.
# date    =>  A datetime value, by default datetime.now().
Exemple #35
0
 def test_text_type(self):
     document = odf_new_document('text')
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS['odt'])
from lpod import __version__, __installation_path__
from lpod.document import odf_new_document
from lpod.table import odf_create_cell, odf_create_row
from lpod.table import odf_create_table
from lpod.style import odf_create_table_cell_style
from lpod.style import make_table_cell_border_string
from lpod.style import odf_create_style, rgb2hex

# Hello messages
print 'lpod installation test'
print ' Version           : %s' % __version__
print ' Installation path : %s' % __installation_path__
print
print 'Generating color chart in my_color_chart.ods ...'

document = odf_new_document('spreadsheet')
body = document.get_body()
table = odf_create_table(u'chart')

for y in xrange(0, 256, 8):
    row = odf_create_row()
    for x in xrange(0, 256, 32):
        cell_value = (x, y, (x + y) % 256)
        border_rl = make_table_cell_border_string(thick='0.20cm',
                                                  color='white')
        border_bt = make_table_cell_border_string(
            thick='0.80cm',
            color='white',
        )
        style = odf_create_table_cell_style(
            color='grey',
Exemple #37
0
 def test_presentation_type(self):
     document = odf_new_document('presentation')
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS['odp'])
Exemple #38
0
        u"date": date.today().strftime(u"%d/%m/%Y"),
        u"homme": homme,
        u"genre": u"M." if homme else u"Mme",
        u"nom": u"Michu",
        u"enum1": {
            'label': u"Revenu",
            'value': 1234.56
        },
        u"enum2": {
            'label': u"Âge",
            'value': 65
        },
        u"couleur": u"rouge",
        u"gras": u"gras comme un moine",
        u"élément": odf_create_span(u"élément", style='T2')
    }


if __name__ == '__main__':
    try:
        output = argv[1]
    except IndexError:
        print >> stderr, "Usage: %s <output document>" % argv[0]
        exit(1)
    document = odf_new_document('test_template.ott')
    stl_odf(document, get_namespace())
    if exists(output):
        remove(output)
    document.save(output)
    print 'Document "%s" generated.' % output
# This the .odt file with some pictures in it we will display on a presentation
# filename = "collection.odt"
# ODF export of Wikipedia article Hitchhiker's Guide to the Galaxy (CC-By-SA)
filename = "collection.odt"
# For convenience, take it from the remote URI:
#filename="http://www.odfgr.org/wiki/example-wikipedia-article/;download"

# We will copy all image from collection.odt, build a presentation with the
# images and save it in this file:
output_filename = "my_presentation_of_text_picts.odp"

# Open the input document
doc_source = odf_get_document_extend(filename)

# Making of the output Presentation document :
presentation_output = odf_new_document('presentation')

# Presentation got a body in which elements are stored
presentation_body = presentation_output.get_body()
presentation_manifest = presentation_output.get_part(ODF_MANIFEST)

# For each image, we create a page in the presentation and display the image
# and some text on this frame
# First, get all image elements available in document:
images_source = doc_source.get_body().get_images()
manifest_source = doc_source.get_part(ODF_MANIFEST)

for image in images_source:
    # we use the get_part function from lpod to get the actual content
    # of the images, with the URI link to the image as argument
    uri = image.get_url()
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# ok lpod 1.0
"""
Create a spreadsheet with one table.
"""
import os

# Import from lpod
from lpod.document import odf_new_document
from lpod.table import odf_create_table

if __name__=="__main__":

    # creating an empty spreadsheet document:
    document = odf_new_document('spreadsheet')

    # Each sheet of a spreadsheet is a table:
    # setting drom the beginning width (columns) and height (rows)
    # is not mandatory, but a good practice, since lpod don't check
    # actual existence of cells
    body = document.get_body()
    table = odf_create_table(u"First Table", width = 20, height = 3)
    body.append(table)

    # A table contains rows, we can append some more.
    for r in range(2):
        table.append_row()
    print "rows in the table (3+2):", len(table.get_rows())

    #  A row contains cells
Exemple #41
0
    add_option_output(parser, complement='("-" for stdout)')

    # Parse !
    options, filenames = parser.parse_args()

    # Arguments
    if not filenames:
        parser.print_help()
        exit(1)
    target = options.output
    if target is None:
        printerr('"-o" option mandatory (use "-" to print to stdout)')
        exit(1)
    check_target_file(target)

    output_document = odf_new_document('presentation')
    output_meta = output_document.get_part(ODF_META)
    output_meta.set_title(u"Interop Budapest Demo")

    # Styles
    styles = output_document.get_part(ODF_STYLES)
    first_master_page = styles.get_master_page()
    if first_master_page is None:
        raise ValueError, "no master page found"

    for i, filename in enumerate(filenames):
        # TODO folders and collections
        printinfo("Processing %s..." % filename)
        result = urlsplit(filename)
        scheme = result.scheme
        if not scheme:
Exemple #42
0
    def runJob(self):
        if not self.requestStop:
            print resource_filename("filomanager.stages", "templates/menu-chef.ott")
            document = odf_new_document(resource_filename("filomanager.stages", "templates/menu-chef.ott"))
            body = document.get_body()
            t_starters = body.get_table(name=self.env["Menu-chef"]["starters-list-name"])
            r_starters = t_starters.get_row(0).clone()
            t_firsts = body.get_table(name=self.env["Menu-chef"]["first-courses-list-name"])
            r_firsts = t_firsts.get_row(0).clone()
            t_seconds = body.get_table(name=self.env["Menu-chef"]["second-courses-list-name"])
            r_seconds = t_seconds.get_row(0).clone()

        if not self.requestStop:
            self.logInfo(logging.INFO, "extract data from quickOrder", 20)

            res = postgresql.extractChefMenu(
                host=self.env["QuickOrder DB"]["host"],
                dbName=self.env["QuickOrder DB"]["dbname"],
                User=self.env["QuickOrder DB"]["user"],
                Pass=self.env["QuickOrder DB"]["password"],
            )

            i_starters, i_firsts, i_seconds = 0, 0, 0
            for row in res:
                if row["category"] == "antipasto":
                    r = r_starters
                    t = t_starters
                    i = i_starters
                    i_starters += 1
                elif row["category"] == "primo":
                    r = r_firsts
                    t = t_firsts
                    i = i_firsts
                    i_firsts += 1
                elif row["category"] == "secondo":
                    r = r_seconds
                    t = t_seconds
                    i = i_seconds
                    i_seconds += 1

                descCell = r.get_cell(0)
                if self.translate is None:
                    text = row["description"]
                else:
                    text = gtranslate.translate(row["description"], src="it", to=self.translate)
                descCell.set_value(text.decode("utf-8"))
                priceCell = r.get_cell(1)
                priceCell.set_value(row["price"])
                r.set_cell(0, descCell)
                r.set_cell(1, priceCell)
                t.insert_row(i, r)
        # 				print row['category'] + " " + row['description'] + " " + str(row['price'])

        if not self.requestStop:
            if self.translate is None:
                lang = "it"
            else:
                lang = self.translate
            outputFileName = (
                self.env["Menu-chef"]["file-output-dir"]
                + "/"
                + self.today.strftime("%d-%m-%Y")
                + "-"
                + lang
                + "_"
                + self.env["Menu-chef"]["file-output-name"]
                + "."
                + self.env["Menu-chef"]["file-output-format"]
            )
            document.save(outputFileName)
            self.logInfo(logging.INFO, "open document " + outputFileName, 75)
            os.system("lowriter " + outputFileName)
Exemple #43
0
 def test_drawing_type(self):
     document = odf_new_document('drawing')
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS['odg'])
        print "Need some old picture !"
        parser.print_help()
        exit(0)
    if not options.new_img:
        print "Need some new picture !"
        parser.print_help()
        exit(0)
    if not sources:
        print "Need some ODF source !"
        parser.print_help()
        exit(0)

    t0 = time.time()
    old_content_footprint = make_footprint(file(options.old_img).read())
    # making the new image content :
    buffer = odf_new_document('text')
    url = buffer.add_file(options.new_img)
    new_content = buffer.get_part(url)

    for source in sources:
        if os.path.isdir(source):
            for root, dirs, files in os.walk(source):
                for name in files:
                    replace_odf_pics(os.path.join(root, name),
                                     old_content_footprint,
                                     new_content)
        else:
            replace_odf_pics(source,
                            old_content_footprint,
                            new_content)
    elapsed = int(time.time() - t0)
Exemple #45
0
 def test_spreadsheet_template(self):
     path = '../lpod/templates/spreadsheet.ots'
     self.assert_(odf_new_document(path))
# -*- coding: UTF-8 -*-
# I want to write "Hello World" in the middle of the first page.

from lpod.document import odf_new_document
from lpod.frame import odf_create_text_frame
from lpod.draw_page import odf_create_draw_page

document = odf_new_document('presentation')
body = document.get_body()

page = odf_create_draw_page('page1', name=u"Page 1")
body.append(page)
text_frame = odf_create_text_frame([u"Hello", u"World"],
        size=('7cm', '5cm'), position=('11cm', '8cm'),
        style=u"colored", text_style=u"big")
Exemple #47
0
 def test_drawing_template(self):
     path = '../lpod/templates/drawing.otg'
     self.assert_(odf_new_document(path))
Exemple #48
0
 def test_text_template(self):
     path = '../templates/text.ott'
     self.assert_(odf_new_document(path))
Exemple #49
0
 def test_text_type(self):
     document = odf_new_document('text')
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS['odt'])
Exemple #50
0
 def test_spreadsheet_template(self):
     path = '../templates/spreadsheet.ots'
     self.assert_(odf_new_document(path))
Exemple #51
0
 def test_presentation_type(self):
     document = odf_new_document('presentation')
     self.assertEqual(document.get_mimetype(), ODF_EXTENSIONS['odp'])
Exemple #52
0
 def test_presentation_template(self):
     path = '../templates/presentation.otp'
     self.assert_(odf_new_document(path))
Exemple #53
0
 else:
     if options.styles_from:
         outdoc = odf_get_document(options.styles_from).clone()
         outdoc.get_body().clear()
         outdoc.path = outfile
         outtype = outdoc.get_type()
     else:
         try:
             mimetype = ODF_EXTENSIONS[extension]
         except KeyError:
             raise ValueError, ("output filename not recognized: " +
                                extension)
         outtype = mimetype[mimetype.rindex('.') + 1:]
         if '-template' in outtype:
             outtype = mimetype[mimetype.rindex('-') + 1:]
         outdoc = odf_new_document(outtype)
 # Convert function
 converter = locals().get('%s_to_%s' % (intype, outtype))
 if converter is None:
     raise NotImplementedError, "unsupported combination"
 # Remove output file
 if not target_file_checked:
     check_target_file(outfile)
 # Convert!
 converter(indoc, outdoc)
 if isinstance(outdoc, odf_document):
     outdoc.save(outfile)
 else:
     try:
         outdoc.close()
     except AttributeError:
Exemple #54
0
def setup():
    global testdoc, odf_renderer, mkdown
    testdoc = odf_new_document('presentation')
    odf_renderer = odpdown.ODFRenderer(testdoc)
    mkdown = mistune.Markdown(renderer=odf_renderer)