[Python-modules-commits] [python-odf] 111/118: Fixed the xlink:type attribute
Wolfgang Borgert
debacle at moszumanska.debian.org
Fri Oct 3 21:27:29 UTC 2014
This is an automated email from the git hooks/post-receive script.
debacle pushed a commit to reference refs/remotes/upstream/master
in repository python-odf.
commit b5effe04d7dff44ca9b2c69fbb0cc553069a4e07
Author: Søren Roug <soren.roug at eea.europa.eu>
Date: Sun Sep 15 17:44:15 2013 +0000
Fixed the xlink:type attribute
---
odf/attrconverters.py | 9 ++-
odf/draw.py | 4 +
odf/grammar.py | 190 ++++++++++++++++++++++-----------------------
odf/meta.py | 1 +
odf/opendocument.py | 18 ++++-
odf/presentation.py | 1 +
odf/svg.py | 2 +
odf/table.py | 2 +
odf/text.py | 2 +
odfmeta/odfmeta | 6 +-
tests/testpresentations.py | 80 +++++++++++++++++++
tests/testtext.py | 22 ++++++
12 files changed, 238 insertions(+), 99 deletions(-)
diff --git a/odf/attrconverters.py b/odf/attrconverters.py
index c9fac9f..7bbf81e 100644
--- a/odf/attrconverters.py
+++ b/odf/attrconverters.py
@@ -43,7 +43,7 @@ def cnv_boolean(attribute, arg, element):
return "false"
if str(arg).lower() in ("1","true","yes"):
return "true"
- raise ValueError, "'%s' not allowed as Boolean value for %s" % (str(arg), attribute)
+ raise ValueError, "'%s' not allowed as Boolean value for %s" % (str(arg), attribute[1])
# Potentially accept color values
def cnv_color(attribute, arg, element):
@@ -281,6 +281,11 @@ def cnv_xlinkshow(attribute, arg, element):
raise ValueError, "'%s' not allowed" % str(arg)
return str(arg)
+def cnv_xlinktype(attribute, arg, element):
+ if arg != "simple":
+ raise ValueError, "Value of '%s' must be 'simple'" % attribute[1]
+ return arg
+
attrconverters = {
((ANIMNS,u'audio-level'), None): cnv_double,
@@ -1575,7 +1580,7 @@ attrconverters = {
((XLINKNS,u'href'), None): cnv_anyURI,
((XLINKNS,u'show'), None): cnv_xlinkshow,
((XLINKNS,u'title'), None): cnv_string,
- ((XLINKNS,u'type'), None): cnv_string,
+ ((XLINKNS,u'type'), None): cnv_xlinktype,
((XMLNS,u'id'), None): cnv_NCName,
}
diff --git a/odf/draw.py b/odf/draw.py
index 7692e5a..e877e73 100644
--- a/odf/draw.py
+++ b/odf/draw.py
@@ -49,6 +49,7 @@ def DrawElement(name=None, **args):
# Autogenerated
def A(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (DRAWNS,'a'), **args)
def Applet(**args):
@@ -94,9 +95,11 @@ def Equation(**args):
return Element(qname = (DRAWNS,'equation'), **args)
def FillImage(**args):
+ args.setdefault('type', 'simple')
return DrawElement(qname = (DRAWNS,'fill-image'), **args)
def FloatingFrame(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (DRAWNS,'floating-frame'), **args)
def Frame(**args):
@@ -160,6 +163,7 @@ def Path(**args):
return StyleRefElement(qname = (DRAWNS,'path'), **args)
def Plugin(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (DRAWNS,'plugin'), **args)
def Polygon(**args):
diff --git a/odf/grammar.py b/odf/grammar.py
index debe34e..d621e5c 100644
--- a/odf/grammar.py
+++ b/odf/grammar.py
@@ -5001,14 +5001,14 @@ allowed_attributes = {
(TABLENS,u'cell-range-address'),
),
(CHARTNS,u'chart'):(
+ (CHARTNS,u'class'),
(CHARTNS,u'column-mapping'),
(CHARTNS,u'row-mapping'),
+ (CHARTNS,u'style-name'),
(SVGNS,u'height'),
(SVGNS,u'width'),
- (CHARTNS,u'style-name'),
- (CHARTNS,u'class'),
- (XLINKNS,u'type'),
(XLINKNS,u'href'),
+ (XLINKNS,u'type'),
(XMLNS,u'id'),
),
(CHARTNS,u'data-label'):(
@@ -5026,12 +5026,12 @@ allowed_attributes = {
),
# allowed_attributes
(CHARTNS,u'equation'):(
+ (CHARTNS,u'automatic-content'),
+ (CHARTNS,u'display-equation'),
(CHARTNS,u'display-r-square'),
(CHARTNS,u'style-name'),
- (CHARTNS,u'display-equation'),
(SVGNS,u'x'),
(SVGNS,u'y'),
- (CHARTNS,u'automatic-content'),
),
(CHARTNS,u'error-indicator'):(
(CHARTNS,u'dimension'),
@@ -5150,18 +5150,18 @@ allowed_attributes = {
(NUMBERNS,u'boolean'):(
),
(NUMBERNS,u'boolean-style'):(
+ (NUMBERNS,u'country'),
+ (NUMBERNS,u'language'),
(NUMBERNS,u'rfc-language-tag'),
(NUMBERNS,u'script'),
- (NUMBERNS,u'transliteration-language'),
- (STYLENS,u'name'),
- (STYLENS,u'display-name'),
- (NUMBERNS,u'language'),
(NUMBERNS,u'title'),
- (NUMBERNS,u'country'),
+ (NUMBERNS,u'transliteration-country'),
(NUMBERNS,u'transliteration-format'),
+ (NUMBERNS,u'transliteration-language'),
(NUMBERNS,u'transliteration-style'),
+ (STYLENS,u'display-name'),
+ (STYLENS,u'name'),
(STYLENS,u'volatile'),
- (NUMBERNS,u'transliteration-country'),
),
(NUMBERNS,u'currency-style'):(
(NUMBERNS,u'rfc-language-tag'),
@@ -5188,20 +5188,20 @@ allowed_attributes = {
),
# allowed_attributes
(NUMBERNS,u'date-style'):(
+ (NUMBERNS,u'automatic-order'),
+ (NUMBERNS,u'country'),
+ (NUMBERNS,u'format-source'),
+ (NUMBERNS,u'language'),
(NUMBERNS,u'rfc-language-tag'),
(NUMBERNS,u'script'),
- (NUMBERNS,u'transliteration-language'),
- (STYLENS,u'name'),
- (STYLENS,u'display-name'),
- (NUMBERNS,u'language'),
(NUMBERNS,u'title'),
- (NUMBERNS,u'country'),
+ (NUMBERNS,u'transliteration-country'),
(NUMBERNS,u'transliteration-format'),
+ (NUMBERNS,u'transliteration-language'),
(NUMBERNS,u'transliteration-style'),
- (NUMBERNS,u'format-source'),
+ (STYLENS,u'display-name'),
+ (STYLENS,u'name'),
(STYLENS,u'volatile'),
- (NUMBERNS,u'transliteration-country'),
- (NUMBERNS,u'automatic-order'),
),
(NUMBERNS,u'day'):(
(NUMBERNS,u'style'),
@@ -5261,18 +5261,18 @@ allowed_attributes = {
),
# allowed_attributes
(NUMBERNS,u'percentage-style'):(
+ (NUMBERNS,u'country'),
+ (NUMBERNS,u'language'),
(NUMBERNS,u'rfc-language-tag'),
(NUMBERNS,u'script'),
- (NUMBERNS,u'transliteration-language'),
- (STYLENS,u'name'),
- (STYLENS,u'display-name'),
- (NUMBERNS,u'language'),
(NUMBERNS,u'title'),
- (NUMBERNS,u'country'),
+ (NUMBERNS,u'transliteration-country'),
(NUMBERNS,u'transliteration-format'),
+ (NUMBERNS,u'transliteration-language'),
(NUMBERNS,u'transliteration-style'),
+ (STYLENS,u'display-name'),
+ (STYLENS,u'name'),
(STYLENS,u'volatile'),
- (NUMBERNS,u'transliteration-country'),
),
(NUMBERNS,u'quarter'):(
(NUMBERNS,u'style'),
@@ -5293,34 +5293,34 @@ allowed_attributes = {
(NUMBERNS,u'text-content'):(
),
(NUMBERNS,u'text-style'):(
+ (NUMBERNS,u'country'),
+ (NUMBERNS,u'language'),
(NUMBERNS,u'rfc-language-tag'),
(NUMBERNS,u'script'),
- (NUMBERNS,u'transliteration-language'),
- (STYLENS,u'name'),
- (STYLENS,u'display-name'),
- (NUMBERNS,u'language'),
(NUMBERNS,u'title'),
- (NUMBERNS,u'country'),
+ (NUMBERNS,u'transliteration-country'),
(NUMBERNS,u'transliteration-format'),
+ (NUMBERNS,u'transliteration-language'),
(NUMBERNS,u'transliteration-style'),
+ (STYLENS,u'display-name'),
+ (STYLENS,u'name'),
(STYLENS,u'volatile'),
- (NUMBERNS,u'transliteration-country'),
),
(NUMBERNS,u'time-style'):(
+ (NUMBERNS,u'country'),
+ (NUMBERNS,u'format-source'),
+ (NUMBERNS,u'language'),
(NUMBERNS,u'rfc-language-tag'),
(NUMBERNS,u'script'),
- (NUMBERNS,u'transliteration-language'),
- (NUMBERNS,u'transliteration-format'),
- (STYLENS,u'name'),
- (STYLENS,u'display-name'),
- (NUMBERNS,u'language'),
(NUMBERNS,u'title'),
- (NUMBERNS,u'country'),
- (NUMBERNS,u'truncate-on-overflow'),
+ (NUMBERNS,u'transliteration-country'),
+ (NUMBERNS,u'transliteration-format'),
+ (NUMBERNS,u'transliteration-language'),
(NUMBERNS,u'transliteration-style'),
- (NUMBERNS,u'format-source'),
+ (NUMBERNS,u'truncate-on-overflow'),
+ (STYLENS,u'display-name'),
+ (STYLENS,u'name'),
(STYLENS,u'volatile'),
- (NUMBERNS,u'transliteration-country'),
),
(NUMBERNS,u'week-of-year'):(
(NUMBERNS,u'calendar'),
@@ -5423,13 +5423,13 @@ allowed_attributes = {
),
(DRAWNS,u'a'):(
(OFFICENS,u'name'),
- (OFFICENS,u'title'),
- (XLINKNS,u'show'),
+ (OFFICENS,u'server-map'),
(OFFICENS,u'target-frame-name'),
+ (OFFICENS,u'title'),
(XLINKNS,u'actuate'),
(XLINKNS,u'href'),
+ (XLINKNS,u'show'),
(XLINKNS,u'type'),
- (OFFICENS,u'server-map'),
(XMLNS,u'id'),
),
(DRAWNS,u'applet'):(
@@ -5672,49 +5672,49 @@ allowed_attributes = {
),
# allowed_attributes
(DRAWNS,u'enhanced-geometry'):(
- (DRAWNS,u'extrusion-rotation-center'),
- (DRAWNS,u'extrusion-shininess'),
- (DRAWNS,u'extrusion-rotation-angle'),
- (DRAWNS,u'extrusion-allowed'),
- (DRAWNS,u'extrusion-first-light-level'),
- (DRAWNS,u'extrusion-specularity'),
- (DRAWNS,u'extrusion-viewpoint'),
- (DRAWNS,u'extrusion-second-light-level'),
- (DRAWNS,u'extrusion-origin'),
- (DRAWNS,u'extrusion-color'),
- (SVGNS,u'viewBox'),
(DR3DNS,u'projection'),
- (DRAWNS,u'extrusion-metal'),
- (DRAWNS,u'extrusion-number-of-line-segments'),
- (DRAWNS,u'text-path-same-letter-heights'),
- (DRAWNS,u'extrusion-first-light-harsh'),
- (DRAWNS,u'enhanced-path'),
- (DRAWNS,u'text-rotate-angle'),
- (DRAWNS,u'type'),
- (DRAWNS,u'glue-point-leaving-directions'),
+ (DR3DNS,u'shade-mode'),
(DRAWNS,u'concentric-gradient-fill-allowed'),
- (DRAWNS,u'text-path-scale'),
+ (DRAWNS,u'enhanced-path'),
+ (DRAWNS,u'extrusion'),
+ (DRAWNS,u'extrusion-allowed'),
(DRAWNS,u'extrusion-brightness'),
- (DRAWNS,u'extrusion-first-light-direction'),
- (DRAWNS,u'extrusion-light-face'),
- (DRAWNS,u'text-path-allowed'),
- (DRAWNS,u'glue-points'),
- (DRAWNS,u'mirror-vertical'),
+ (DRAWNS,u'extrusion-color'),
(DRAWNS,u'extrusion-depth'),
(DRAWNS,u'extrusion-diffusion'),
+ (DRAWNS,u'extrusion-first-light-direction'),
+ (DRAWNS,u'extrusion-first-light-harsh'),
+ (DRAWNS,u'extrusion-first-light-level'),
+ (DRAWNS,u'extrusion-light-face'),
+ (DRAWNS,u'extrusion-metal'),
+ (DRAWNS,u'extrusion-number-of-line-segments'),
+ (DRAWNS,u'extrusion-origin'),
+ (DRAWNS,u'extrusion-rotation-angle'),
+ (DRAWNS,u'extrusion-rotation-center'),
(DRAWNS,u'extrusion-second-light-direction'),
+ (DRAWNS,u'extrusion-second-light-harsh'),
+ (DRAWNS,u'extrusion-second-light-level'),
+ (DRAWNS,u'extrusion-shininess'),
(DRAWNS,u'extrusion-skew'),
- (DR3DNS,u'shade-mode'),
- (DRAWNS,u'path-stretchpoint-y'),
+ (DRAWNS,u'extrusion-specularity'),
+ (DRAWNS,u'extrusion-viewpoint'),
+ (DRAWNS,u'glue-point-leaving-directions'),
+ (DRAWNS,u'glue-points'),
+ (DRAWNS,u'glue-point-type'),
+ (DRAWNS,u'mirror-horizontal'),
+ (DRAWNS,u'mirror-vertical'),
(DRAWNS,u'modifiers'),
- (DRAWNS,u'extrusion'),
(DRAWNS,u'path-stretchpoint-x'),
+ (DRAWNS,u'path-stretchpoint-y'),
(DRAWNS,u'text-areas'),
- (DRAWNS,u'mirror-horizontal'),
- (DRAWNS,u'text-path-mode'),
- (DRAWNS,u'extrusion-second-light-harsh'),
- (DRAWNS,u'glue-point-type'),
(DRAWNS,u'text-path'),
+ (DRAWNS,u'text-path-allowed'),
+ (DRAWNS,u'text-path-mode'),
+ (DRAWNS,u'text-path-same-letter-heights'),
+ (DRAWNS,u'text-path-scale'),
+ (DRAWNS,u'text-rotate-angle'),
+ (DRAWNS,u'type'),
+ (SVGNS,u'viewBox'),
),
# allowed_attributes
(DRAWNS,u'equation'):(
@@ -5974,29 +5974,29 @@ allowed_attributes = {
),
# allowed_attributes
(DRAWNS,u'path'):(
- (TABLENS,u'table-background'),
- (DRAWNS,u'layer'),
- (TABLENS,u'end-cell-address'),
(DRAWNS,u'caption-id'),
- (SVGNS,u'd'),
- (DRAWNS,u'text-style-name'),
+ (DRAWNS,u'class-names'),
(DRAWNS,u'id'),
+ (DRAWNS,u'layer'),
+ (DRAWNS,u'name'),
+ (DRAWNS,u'style-name'),
+ (DRAWNS,u'text-style-name'),
(DRAWNS,u'transform'),
- (SVGNS,u'height'),
- (SVGNS,u'width'),
(DRAWNS,u'z-index'),
- (DRAWNS,u'class-names'),
- (DRAWNS,u'style-name'),
- (PRESENTATIONNS,u'style-name'),
(PRESENTATIONNS,u'class-names'),
- (TABLENS,u'end-x'),
- (TEXTNS,u'anchor-type'),
- (TEXTNS,u'anchor-page-number'),
- (SVGNS,u'y'),
+ (PRESENTATIONNS,u'style-name'),
+ (SVGNS,u'd'),
+ (SVGNS,u'height'),
+ (SVGNS,u'viewBox'),
+ (SVGNS,u'width'),
(SVGNS,u'x'),
+ (SVGNS,u'y'),
+ (TABLENS,u'end-cell-address'),
+ (TABLENS,u'end-x'),
(TABLENS,u'end-y'),
- (SVGNS,u'viewBox'),
- (DRAWNS,u'name'),
+ (TABLENS,u'table-background'),
+ (TEXTNS,u'anchor-page-number'),
+ (TEXTNS,u'anchor-type'),
(XMLNS,u'id'),
),
# allowed_attributes
@@ -8288,14 +8288,14 @@ allowed_attributes = {
),
# allowed_attributes
(TEXTNS,u'a'):(
- (TEXTNS,u'visited-style-name'),
(OFFICENS,u'name'),
- (OFFICENS,u'title'),
- (XLINKNS,u'show'),
(OFFICENS,u'target-frame-name'),
- (XLINKNS,u'actuate'),
+ (OFFICENS,u'title'),
(TEXTNS,u'style-name'),
+ (TEXTNS,u'visited-style-name'),
+ (XLINKNS,u'actuate'),
(XLINKNS,u'href'),
+ (XLINKNS,u'show'),
(XLINKNS,u'type'),
),
(TEXTNS,u'alphabetical-index'):(
diff --git a/odf/meta.py b/odf/meta.py
index dc03181..68b1d19 100644
--- a/odf/meta.py
+++ b/odf/meta.py
@@ -59,6 +59,7 @@ def PrintedBy(**args):
return Element(qname = (METANS,'printed-by'), **args)
def Template(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (METANS,'template'), **args)
def UserDefined(**args):
diff --git a/odf/opendocument.py b/odf/opendocument.py
index 69ada21..0d87f65 100644
--- a/odf/opendocument.py
+++ b/odf/opendocument.py
@@ -602,12 +602,28 @@ def __loadxmlparts(z, manifest, doc, objectpath):
del doc._parsing
except KeyError, v: pass
+def __detectmimetype(zipfd, odffile):
+ try:
+ mimetype = zipfd.read('mimetype')
+ return mimetype
+ except:
+ pass
+ # Fall-through to next mechanism
+ manifestpart = zipfd.read('META-INF/manifest.xml')
+ manifest = manifestlist(manifestpart)
+ for mentry,mvalue in manifest.items():
+ if mentry == "/":
+ return mvalue['media-type']
+
+ # Fall-through to last mechanism
+ return 'application/vnd.oasis.opendocument.text'
+
def load(odffile):
""" Load an ODF file into memory
Returns a reference to the structure
"""
z = zipfile.ZipFile(odffile)
- mimetype = z.read('mimetype')
+ mimetype = __detectmimetype(z, odffile)
doc = OpenDocument(mimetype, add_generator=False)
# Look in the manifest file to see if which of the four files there are
diff --git a/odf/presentation.py b/odf/presentation.py
index c1f2135..04e2b76 100644
--- a/odf/presentation.py
+++ b/odf/presentation.py
@@ -81,5 +81,6 @@ def ShowText(**args):
return Element(qname = (PRESENTATIONNS,'show-text'), **args)
def Sound(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (PRESENTATIONNS,'sound'), **args)
diff --git a/odf/svg.py b/odf/svg.py
index 346c490..79629b9 100644
--- a/odf/svg.py
+++ b/odf/svg.py
@@ -24,6 +24,7 @@ from draw import DrawElement
# Autogenerated
def DefinitionSrc(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (SVGNS,'definition-src'), **args)
def Desc(**args):
@@ -39,6 +40,7 @@ def FontFaceSrc(**args):
return Element(qname = (SVGNS,'font-face-src'), **args)
def FontFaceUri(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (SVGNS,'font-face-uri'), **args)
def Lineargradient(**args):
diff --git a/odf/table.py b/odf/table.py
index 11662a3..904f2a7 100644
--- a/odf/table.py
+++ b/odf/table.py
@@ -42,6 +42,7 @@ def CellContentDeletion(**args):
return Element(qname = (TABLENS,'cell-content-deletion'), **args)
def CellRangeSource(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (TABLENS,'cell-range-source'), **args)
def ChangeDeletion(**args):
@@ -303,6 +304,7 @@ def TableRows(**args):
return Element(qname = (TABLENS,'table-rows'), **args)
def TableSource(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (TABLENS,'table-source'), **args)
def TableTemplate(**args):
diff --git a/odf/text.py b/odf/text.py
index 3313a86..ffc78ce 100644
--- a/odf/text.py
+++ b/odf/text.py
@@ -24,12 +24,14 @@ from style import StyleElement
# Autogenerated
def A(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (TEXTNS,'a'), **args)
def AlphabeticalIndex(**args):
return Element(qname = (TEXTNS,'alphabetical-index'), **args)
def AlphabeticalIndexAutoMarkFile(**args):
+ args.setdefault('type', 'simple')
return Element(qname = (TEXTNS,'alphabetical-index-auto-mark-file'), **args)
def AlphabeticalIndexEntryTemplate(**args):
diff --git a/odfmeta/odfmeta b/odfmeta/odfmeta
index 0808b2d..6cc42e5 100755
--- a/odfmeta/odfmeta
+++ b/odfmeta/odfmeta
@@ -229,7 +229,11 @@ else:
exitwithusage()
zin = zipfile.ZipFile(args[0], 'r')
-content = zin.read('meta.xml')
+try:
+ content = zin.read('meta.xml')
+except:
+ sys.stderr.write("File has no meta data\n")
+ sys.exit(1)
parser.parse(StringIO(content))
if writemeta:
diff --git a/tests/testpresentations.py b/tests/testpresentations.py
new file mode 100644
index 0000000..e05239b
--- /dev/null
+++ b/tests/testpresentations.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# Copyright (C) 2007-2010 Søren Roug, European Environment Agency
+#
+# This is free software. You may redistribute it under the terms
+# of the Apache license and the GNU General Public License Version
+# 2 or at your option any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+#
+# Contributor(s):
+#
+
+import unittest
+from odf.opendocument import OpenDocumentPresentation, OpenDocumentText
+from odf import draw, style, table, text
+from odf.element import IllegalChild
+from odf.namespaces import TEXTNS
+from elementparser import ElementParser
+
+class TestPresentations(unittest.TestCase):
+
+ def assertContains(self, stack, needle):
+ self.assertNotEqual(-1, stack.find(needle))
+
+ def assertNotContains(self, stack, needle):
+ self.assertEquals(-1, stack.find(needle))
+
+ def testTable(self):
+ """ Create a presentation with a page layout called MyLayout
+ """
+ presdoc = OpenDocumentPresentation()
+ # We must describe the dimensions of the page
+ pagelayout = style.PageLayout(name="MyLayout")
+ presdoc.automaticstyles.addElement(pagelayout)
+ pagelayout.addElement(style.PageLayoutProperties(margin="0cm", pagewidth="28cm", pageheight="21cm", printorientation="landscape"))
+
+ # Every drawing page must have a master page assigned to it.
+ masterpage = style.MasterPage(name="MyMaster", pagelayoutname=pagelayout)
+ presdoc.masterstyles.addElement(masterpage)
+
+ # Style for the title frame of the page
+ # We set a centered 34pt font with yellowish background
+ titlestyle = style.Style(name="MyMaster-title", family="presentation")
+ titlestyle.addElement(style.ParagraphProperties(textalign="center"))
+ titlestyle.addElement(style.TextProperties(fontsize="34pt"))
+ titlestyle.addElement(style.GraphicProperties(fillcolor="#ffff99"))
+ presdoc.styles.addElement(titlestyle)
+
+ # Style for the photo frame
+ mainstyle = style.Style(name="MyMaster-main", family="presentation")
+ presdoc.styles.addElement(mainstyle)
+
+ # Create style for drawing page
+ dpstyle = style.Style(name="dp1", family="drawing-page")
+ presdoc.automaticstyles.addElement(dpstyle)
+
+ page = draw.Page(stylename=dpstyle, masterpagename=masterpage)
+ presdoc.presentation.addElement(page)
+
+ titleframe = draw.Frame(stylename=titlestyle, width="720pt", height="56pt", x="40pt", y="10pt")
+ page.addElement(titleframe)
+ textbox = draw.TextBox()
+ titleframe.addElement(textbox)
+ textbox.addElement(text.P(text="Presentation"))
+
+ mainframe = draw.Frame(stylename=mainstyle, width="720pt", height="500pt", x="0pt", y="56pt")
+ page.addElement(mainframe)
+ mainframe.addElement(table.Table())
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/tests/testtext.py b/tests/testtext.py
index 6a3aee3..0437520 100644
--- a/tests/testtext.py
+++ b/tests/testtext.py
@@ -42,6 +42,28 @@ class TestText(unittest.TestCase):
self.assertEquals(shouldbe, unicode(d.body))
self.assertEquals(shouldbe, str(d.body))
+ def test_link(self):
+ """ Create a link """
+ textdoc = OpenDocumentText()
+ para = text.P()
+ anchor = text.A(href="http://www.com/", text="A link label")
+ para.addElement(anchor)
+ textdoc.text.addElement(para)
+ self.assertEquals(1, 1)
+
+ def test_simple_link(self):
+ """ Create a link """
+ textdoc = OpenDocumentText()
+ para = text.P()
+ anchor = text.A(href="http://www.com/", type="simple", text="A link label")
+ para.addElement(anchor)
+ textdoc.text.addElement(para)
+
+ def test_extended_link(self):
+ """ Create a link """
+ textdoc = OpenDocumentText()
+ para = text.P()
+ self.assertRaises(ValueError, text.A, href="http://www.com/", type="extended", text="A link label")
if __name__ == '__main__':
unittest.main()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-odf.git
More information about the Python-modules-commits
mailing list