testpresentations.py 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # Copyright (C) 2007-2010 Søren Roug, European Environment Agency
  4. #
  5. # This is free software. You may redistribute it under the terms
  6. # of the Apache license and the GNU General Public License Version
  7. # 2 or at your option any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public
  15. # License along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # Contributor(s):
  19. #
  20. import unittest
  21. from odf.opendocument import OpenDocumentPresentation, OpenDocumentText
  22. from odf import draw, style, table, text
  23. from odf.element import IllegalChild
  24. from odf.namespaces import TEXTNS
  25. from elementparser import ElementParser
  26. class TestPresentations(unittest.TestCase):
  27. def assertContains(self, stack, needle):
  28. self.assertNotEqual(-1, stack.find(needle))
  29. def assertNotContains(self, stack, needle):
  30. self.assertEqual(-1, stack.find(needle))
  31. def testTable(self):
  32. """ Create a presentation with a page layout called MyLayout
  33. """
  34. presdoc = OpenDocumentPresentation()
  35. # We must describe the dimensions of the page
  36. pagelayout = style.PageLayout(name="MyLayout")
  37. presdoc.automaticstyles.addElement(pagelayout)
  38. pagelayout.addElement(style.PageLayoutProperties(margin="0cm", pagewidth="28cm", pageheight="21cm", printorientation="landscape"))
  39. # Every drawing page must have a master page assigned to it.
  40. masterpage = style.MasterPage(name="MyMaster", pagelayoutname=pagelayout)
  41. presdoc.masterstyles.addElement(masterpage)
  42. # Style for the title frame of the page
  43. # We set a centered 34pt font with yellowish background
  44. titlestyle = style.Style(name="MyMaster-title", family="presentation")
  45. titlestyle.addElement(style.ParagraphProperties(textalign="center"))
  46. titlestyle.addElement(style.TextProperties(fontsize="34pt"))
  47. titlestyle.addElement(style.GraphicProperties(fillcolor="#ffff99"))
  48. presdoc.styles.addElement(titlestyle)
  49. # Style for the photo frame
  50. mainstyle = style.Style(name="MyMaster-main", family="presentation")
  51. presdoc.styles.addElement(mainstyle)
  52. # Create style for drawing page
  53. dpstyle = style.Style(name="dp1", family="drawing-page")
  54. presdoc.automaticstyles.addElement(dpstyle)
  55. page = draw.Page(stylename=dpstyle, masterpagename=masterpage)
  56. presdoc.presentation.addElement(page)
  57. titleframe = draw.Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt")
  58. page.addElement(titleframe)
  59. textbox = draw.TextBox()
  60. titleframe.addElement(textbox)
  61. textbox.addElement(text.P(text="Presentation"))
  62. mainframe = draw.Frame(stylename=mainstyle, width="720pt", height="500pt", x="0pt", y="56pt")
  63. page.addElement(mainframe)
  64. mainframe.addElement(table.Table())
  65. if __name__ == '__main__':
  66. unittest.main()