#!/usr/bin/python
# -*- coding: utf-8 -*-


"""
Illustration de la création d'un document texte.
"""


__author__ = "Sébastien CHAZALLET"
__copyright__ = "Copyright 2012"
__credits__ = ["Sébastien CHAZALLET", "InsPyration.org", "Éditions ENI"]
__license__ = "GPL"
__version__ = "1.0"
__maintainer__ = "Sébastien CHAZALLET"
__email__ = "sebastien.chazallet@laposte.net"
__status__ = "Production"


from odf.opendocument import OpenDocumentText
from odf.style import Style, TextProperties, ParagraphProperties, TableColumnProperties
from odf.text import P
from odf.table import Table, TableColumn, TableRow, TableCell


heading1 = Style(name="Heading 1", family="paragraph")
heading1.addElement(ParagraphProperties(breakbefore="true", lineheight="24pt"))
heading1.addElement(TextProperties(fontfamily="Verdana", fontweight="bold", fontsize="20pt"))

heading2 = Style(name="Heading 2", family="paragraph")
heading2.addElement(ParagraphProperties(breakbefore="false", lineheight="24pt"))
heading2.addElement(TextProperties(fontfamily="Verdana", fontweight="italic", fontsize="16pt"))

tablecontents = Style(name="Table Contents", family="paragraph")
tablecontents.addElement(ParagraphProperties(numberlines="false", linenumber="0"))

column1 = Style(name="Left Column", family="table-column")
column1.addElement(TableColumnProperties(columnwidth="3cm"))

column2 = Style(name="Right Column", family="table-column")
column2.addElement(TableColumnProperties(columnwidth="7.5cm"))

t1 = P(stylename=heading1, text="Tome 1")
t2 = P(stylename=heading2, text="Chapitre premier")
t3 = P(text="Il etait une fois...")



content = [[
		P(stylename=tablecontents,text='Case 1 1'),
		P(stylename=tablecontents,text='Case 1 2'),
		P(stylename=tablecontents,text='Case 1 3'),
	], [
		P(stylename=tablecontents,text='Case 2 1'),
		P(stylename=tablecontents,text='Case 2 2'),
		P(stylename=tablecontents,text='Case 2 3'),
]]

table = Table()
table.addElement(TableColumn(numbercolumnsrepeated=1,stylename=column1))
table.addElement(TableColumn(numbercolumnsrepeated=2,stylename=column2))

for l in content:
	r = TableRow()
	for p in l:
		c = TableCell()
		c.addElement(p)
		r.addElement(c)
	table.addElement(r)

document = OpenDocumentText()
document.styles.addElement(heading1)
document.styles.addElement(heading2)
document.styles.addElement(tablecontents)
document.automaticstyles.addElement(column1)
document.automaticstyles.addElement(column2)

document.text.addElement(t1)
document.text.addElement(t2)
document.text.addElement(t3)

document.text.addElement(table)

document.save("test.odt")

