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


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


__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 OpenDocumentPresentation
from odf.style import Style, MasterPage, PageLayout, PageLayoutProperties, \
TextProperties, GraphicProperties, ParagraphProperties, DrawingPageProperties
from odf.text import P
from odf.draw  import Page, Frame, TextBox, Image


document = OpenDocumentPresentation()

heading = Style(name="Heading", family="presentation")
heading.addElement(ParagraphProperties(textalign="center"))
heading.addElement(TextProperties(fontsize="48pt"))
heading.addElement(GraphicProperties(fillcolor="#1e7bcb"))
document.styles.addElement(heading)
image = Style(name="Image", family="presentation")
document.styles.addElement(image)

pagelayout = PageLayout(name="BasicLayout")
pagelayout.addElement(PageLayoutProperties(margin="0pt", pagewidth="800pt", pageheight="600pt", printorientation="landscape"))
document.automaticstyles.addElement(pagelayout)

masterpage = MasterPage(name="BasicMaster", pagelayoutname=pagelayout)
document.masterstyles.addElement(masterpage)
transition = Style(name="Moving", family="drawing-page")
transition.addElement(DrawingPageProperties(transitiontype="automatic", transitionstyle="move-from-top", duration="PT5S"))
document.automaticstyles.addElement(transition)

page = Page(stylename=transition, masterpagename=masterpage)
frame1 = Frame(stylename=heading, width="720pt", height="56pt", x="40pt", y="10pt")
page.addElement(frame1)
textbox = TextBox()
frame1.addElement(textbox)
textbox.addElement(P(text='Proprietes'))
frame2 = Frame(stylename=image, width="720pt", height="480pt", x="60pt", y="56pt")
page.addElement(frame2)
href = document.addPicture('hello.pdf.png')
frame2.addElement(Image(href=href))
document.presentation.addElement(page)

page = Page(stylename=transition, masterpagename=masterpage)
frame1 = Frame(stylename=heading, width="720pt", height="56pt", x="40pt", y="10pt")
page.addElement(frame1)
textbox = TextBox()
frame1.addElement(textbox)
textbox.addElement(P(text='Page 2, pour le test'))
frame2 = Frame(stylename=image, width="720pt", height="480pt", x="60pt", y="56pt")
page.addElement(frame2)
frame2.addElement(Image(href=href))

document.presentation.addElement(page)

document.save('test.odp')

