예제 #1
0
    def test_append_sub_item(self):
        spam = odf_create_list([u'spam'])
        ham = odf_create_list([u'ham'])
        eggs = odf_create_list([u'eggs'])

        spam.append_item(ham)
        ham.append_item(eggs)

        expected = ('<text:list>'
                      '<text:list-item>'
                        '<text:p>spam</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:list>'
                          '<text:list-item>'
                            '<text:p>ham</text:p>'
                          '</text:list-item>'
                          '<text:list-item>'
                            '<text:list>'
                              '<text:list-item>'
                                '<text:p>eggs</text:p>'
                              '</text:list-item>'
                            '</text:list>'
                          '</text:list-item>'
                        '</text:list>'
                      '</text:list-item>'
                    '</text:list>')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(spam.serialize(), expected)
예제 #2
0
    def test_insert_sub_item(self):
        spam = odf_create_list([u"spam"])
        ham = odf_create_list([u"ham"])
        eggs = odf_create_list([u"eggs"])

        spam.insert_item(ham, 1)
        ham.insert_item(eggs, 1)

        expected = (
            "<text:list>"
            "<text:list-item>"
            "<text:p>spam</text:p>"
            "</text:list-item>"
            "<text:list-item>"
            "<text:list>"
            "<text:list-item>"
            "<text:p>ham</text:p>"
            "</text:list-item>"
            "<text:list-item>"
            "<text:list>"
            "<text:list-item>"
            "<text:p>eggs</text:p>"
            "</text:list-item>"
            "</text:list>"
            "</text:list-item>"
            "</text:list>"
            "</text:list-item>"
            "</text:list>"
        )
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(spam.serialize(), expected)
예제 #3
0
    def test_append_sub_item(self):
        spam = odf_create_list(['spam'])
        ham = odf_create_list(['ham'])
        eggs = odf_create_list(['eggs'])

        spam.append_item(ham)
        ham.append_item(eggs)

        expected = ('<text:list>'
                    '<text:list-item>'
                    '<text:p>spam</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:list>'
                    '<text:list-item>'
                    '<text:p>ham</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:list>'
                    '<text:list-item>'
                    '<text:p>eggs</text:p>'
                    '</text:list-item>'
                    '</text:list>'
                    '</text:list-item>'
                    '</text:list>'
                    '</text:list-item>'
                    '</text:list>')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(spam.serialize(), expected)
예제 #4
0
    def test_get_formatted_text(self):
        # Create the items
        spam = odf_create_list_item('In this picture, there are 47 people;\n'
                                    'none of them can be seen.')
        ham = odf_create_list_item('In this film, we hope to show you the\n'
                                   'value of not being seen.\n')
        eggs = odf_create_list_item('Here is Mr. Bagthorpe of London, '
                                    'SE14.\n')
        foo = odf_create_list_item('He cannot be seen.')
        bar = odf_create_list_item('Now I am going to ask him to stand up.')
        baz = odf_create_list_item('Mr. Bagthorpe, will you stand up please?')
        # Create the lists
        how_not_to_be_seen1 = odf_create_list()
        how_not_to_be_seen2 = odf_create_list()
        how_not_to_be_seen3 = odf_create_list()
        # Fill the lists
        # First list
        how_not_to_be_seen1.append_item(spam)
        # Second list
        how_not_to_be_seen2.append_item(ham)
        how_not_to_be_seen2.append_item(eggs)
        how_not_to_be_seen2.append_item(foo)
        # Third list
        how_not_to_be_seen3.append_item(bar)
        how_not_to_be_seen3.append_item(baz)
        # Create the final nested list (how_not_to_be_seen1)
        spam.append(how_not_to_be_seen2)
        foo.append(how_not_to_be_seen3)

        # Initialize an empty fake context
        context = {
            'document': None,
            'footnotes': [],
            'endnotes': [],
            'annotations': [],
            'rst_mode': False
        }
        expected = ('- In this picture, there are 47 people;\n'
                    '  none of them can be seen.\n'
                    '  \n'
                    '  - In this film, we hope to show you the\n'
                    '    value of not being seen.\n'
                    '  - Here is Mr. Bagthorpe of London, SE14.\n'
                    '  - He cannot be seen.\n'
                    '    \n'
                    '    - Now I am going to ask him to stand up.\n'
                    '    - Mr. Bagthorpe, will you stand up please?\n')
        self.assertEqual(how_not_to_be_seen1.get_formatted_text(context),
                         expected)
예제 #5
0
    def test_get_item_by_content(self):
        # Create the items
        spam = odf_create_list_item(u"spam")
        ham = odf_create_list_item(u"ham")
        eggs = odf_create_list_item(u"eggs")
        # Create the corresponding lists
        spam_list = odf_create_list()
        ham_list = odf_create_list()
        eggs_list = odf_create_list()
        # Fill the lists
        spam_list.append_item(spam)
        ham_list.append_item(ham)
        eggs_list.append_item(eggs)
        # Create the final nested list (spam_list)
        spam.append_element(ham_list)
        ham.append_element(eggs_list)

        item = spam_list.get_item_by_content(ur"spam")
        expected = (
            "<text:list-item>\n"
            "  <text:p>spam</text:p>\n"
            "  <text:list>\n"
            "    <text:list-item>\n"
            "      <text:p>ham</text:p>\n"
            "      <text:list>\n"
            "        <text:list-item>\n"
            "          <text:p>eggs</text:p>\n"
            "        </text:list-item>\n"
            "      </text:list>\n"
            "    </text:list-item>\n"
            "  </text:list>\n"
            "</text:list-item>\n"
        )
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item_by_content(ur"ham")
        expected = (
            "<text:list-item>\n"
            "  <text:p>ham</text:p>\n"
            "  <text:list>\n"
            "    <text:list-item>\n"
            "      <text:p>eggs</text:p>\n"
            "    </text:list-item>\n"
            "  </text:list>\n"
            "</text:list-item>\n"
        )
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item_by_content(ur"eggs")
        expected = "<text:list-item>\n" "  <text:p>eggs</text:p>\n" "</text:list-item>\n"
        self.assertEqual(item.serialize(pretty=True), expected)
예제 #6
0
def convert_list(node, context, list_type):
    # Predefined styles
    if list_type == "enumerated":
        style_name = "Numbering_20_1"
    else:
        style_name = "List_20_1"

    odf_list = odf_create_list(style=style_name)
    context["top"].append_element(odf_list)

    # Save the current top
    old_top = context["top"]

    for item in node:

        if item.tagname != "list_item":
            warn("node not supported: %s" % item.tagname)
            continue

        # Create a new item
        odf_item = odf_create_list_item()
        odf_list.append_element(odf_item)

        # A new top
        context["top"] = odf_item

        for child in item:
            convert_node(child, context)

    # And restore the top
    context["top"] = old_top
예제 #7
0
 def list(self, body, ordered=True):
     # TODO: reverse-engineer magic to convert outline style to
     # numbering style
     lst = odf_create_list(style=u'L1' if ordered else u'OutlineListStyle')
     for elem in body.get():
         lst.append(elem)
     return ODFPartialTree.from_metrics_provider([lst], self)
예제 #8
0
 def test_create_list(self):
     item = odf_create_list_item()
     a_list = odf_create_list([u"你好 Zoé"])
     expected = (
         "<text:list>" "<text:list-item>" "<text:p>%s</text:p>" "</text:list-item>" "</text:list>"
     ) % convert_unicode(u"你好 Zoé")
     self.assertEqual(a_list.serialize(), expected)
예제 #9
0
파일: odpdown.py 프로젝트: rombert/odpdown
 def list(self, body, ordered=True):
     # TODO: reverse-engineer magic to convert outline style to
     # numbering style
     lst = odf_create_list(style=u'L1' if ordered else u'OutlineListStyle')
     for elem in body.get():
         lst.append(elem)
     return ODFPartialTree.from_metrics_provider([lst], self)
예제 #10
0
    def test_get_item_by_content(self):
        # Create the items
        spam = odf_create_list_item('spam')
        ham = odf_create_list_item('ham')
        eggs = odf_create_list_item('eggs')
        # Create the corresponding lists
        spam_list = odf_create_list()
        ham_list = odf_create_list()
        eggs_list = odf_create_list()
        # Fill the lists
        spam_list.append_item(spam)
        ham_list.append_item(ham)
        eggs_list.append_item(eggs)
        # Create the final nested list (spam_list)
        spam.append(ham_list)
        ham.append(eggs_list)

        item = spam_list.get_item(content=r'spam')
        expected = ('<text:list-item>\n'
                    '  <text:p>spam</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>ham</text:p>\n'
                    '      <text:list>\n'
                    '        <text:list-item>\n'
                    '          <text:p>eggs</text:p>\n'
                    '        </text:list-item>\n'
                    '      </text:list>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=r'ham')
        expected = ('<text:list-item>\n'
                    '  <text:p>ham</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>eggs</text:p>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=r'eggs')
        expected = ('<text:list-item>\n'
                    '  <text:p>eggs</text:p>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
예제 #11
0
    def test_get_item_by_content(self):
        # Create the items
        spam = odf_create_list_item(u'spam')
        ham = odf_create_list_item(u'ham')
        eggs = odf_create_list_item(u'eggs')
        # Create the corresponding lists
        spam_list = odf_create_list()
        ham_list = odf_create_list()
        eggs_list = odf_create_list()
        # Fill the lists
        spam_list.append_item(spam)
        ham_list.append_item(ham)
        eggs_list.append_item(eggs)
        # Create the final nested list (spam_list)
        spam.append(ham_list)
        ham.append(eggs_list)

        item = spam_list.get_item(content=ur'spam')
        expected = ('<text:list-item>\n'
                    '  <text:p>spam</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>ham</text:p>\n'
                    '      <text:list>\n'
                    '        <text:list-item>\n'
                    '          <text:p>eggs</text:p>\n'
                    '        </text:list-item>\n'
                    '      </text:list>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=ur'ham')
        expected = ('<text:list-item>\n'
                    '  <text:p>ham</text:p>\n'
                    '  <text:list>\n'
                    '    <text:list-item>\n'
                    '      <text:p>eggs</text:p>\n'
                    '    </text:list-item>\n'
                    '  </text:list>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
        item = spam_list.get_item(content=ur'eggs')
        expected = ('<text:list-item>\n'
                    '  <text:p>eggs</text:p>\n'
                    '</text:list-item>\n')
        self.assertEqual(item.serialize(pretty=True), expected)
예제 #12
0
    def test_get_formatted_text(self):
        # Create the items
        spam = odf_create_list_item(u'In this picture, there are 47 people;\n'
                                    u'none of them can be seen.')
        ham = odf_create_list_item(u'In this film, we hope to show you the\n'
                                   u'value of not being seen.\n')
        eggs = odf_create_list_item(u'Here is Mr. Bagthorpe of London, '
                                    u'SE14.\n')
        foo = odf_create_list_item(u'He cannot be seen.')
        bar = odf_create_list_item(u'Now I am going to ask him to stand up.')
        baz = odf_create_list_item(u'Mr. Bagthorpe, will you stand up please?')
        # Create the lists
        how_not_to_be_seen1 = odf_create_list()
        how_not_to_be_seen2 = odf_create_list()
        how_not_to_be_seen3 = odf_create_list()
        # Fill the lists
        # First list
        how_not_to_be_seen1.append_item(spam)
        # Second list
        how_not_to_be_seen2.append_item(ham)
        how_not_to_be_seen2.append_item(eggs)
        how_not_to_be_seen2.append_item(foo)
        # Third list
        how_not_to_be_seen3.append_item(bar)
        how_not_to_be_seen3.append_item(baz)
        # Create the final nested list (how_not_to_be_seen1)
        spam.append(how_not_to_be_seen2)
        foo.append(how_not_to_be_seen3)

        # Initialize an empty fake context
        context = {'document': None,
                   'footnotes': [],
                   'endnotes': [],
                   'annotations': [],
                   'rst_mode': False}
        expected = (u'- In this picture, there are 47 people;\n'
                    u'  none of them can be seen.\n'
                    u'  \n'
                    u'  - In this film, we hope to show you the\n'
                    u'    value of not being seen.\n'
                    u'  - Here is Mr. Bagthorpe of London, SE14.\n'
                    u'  - He cannot be seen.\n'
                    u'    \n'
                    u'    - Now I am going to ask him to stand up.\n'
                    u'    - Mr. Bagthorpe, will you stand up please?\n')
        self.assertEqual(how_not_to_be_seen1.get_formatted_text(context),
                         expected)
예제 #13
0
 def test_create_list(self):
     item = odf_create_list_item()
     a_list = odf_create_list(['你好 Zoé'])
     expected = (('<text:list>'
                  '<text:list-item>'
                  '<text:p>%s</text:p>'
                  '</text:list-item>'
                  '</text:list>') % convert_unicode('你好 Zoé'))
     self.assertEqual(a_list.serialize(), expected)
예제 #14
0
 def test_create_list(self):
     item = odf_create_list_item()
     a_list = odf_create_list([u'你好 Zoé'])
     expected = (('<text:list>'
                    '<text:list-item>'
                      '<text:p>%s</text:p>'
                    '</text:list-item>'
                  '</text:list>') % convert_unicode(u'你好 Zoé'))
     self.assertEqual(a_list.serialize(), expected)
예제 #15
0
    def test_insert_list(self):
        content = self.content
        clone = content.clone()
        item = odf_create_list_item()
        a_list = odf_create_list(style="a_style")
        a_list.append_element(item)
        body = clone.get_body()
        body.append_element(a_list)

        expected = '<text:list text:style-name="a_style">' "<text:list-item/>" "</text:list>"
        self.assertEqual(a_list.serialize(), expected)
예제 #16
0
    def test_insert_list(self):
        content = self.content
        clone = content.clone()
        item = odf_create_list_item()
        a_list = odf_create_list(style='a_style')
        a_list.append(item)
        body = clone.get_body()
        body.append(a_list)

        expected = ('<text:list text:style-name="a_style">'
                    '<text:list-item/>'
                    '</text:list>')
        self.assertEqual(a_list.serialize(), expected)
예제 #17
0
    def test_get_formatted_text(self):
        # Create the items
        spam = odf_create_list_item(u"In this picture, there are 47 people;\n" u"none of them can be seen.")
        ham = odf_create_list_item(u"In this film, we hope to show you the\n" u"value of not being seen.\n")
        eggs = odf_create_list_item(u"Here is Mr. Bagthorpe of London, " u"SE14.\n")
        foo = odf_create_list_item(u"He cannot be seen.")
        bar = odf_create_list_item(u"Now I am going to ask him to stand up.")
        baz = odf_create_list_item(u"Mr. Bagthorpe, will you stand up please?")
        # Create the lists
        how_not_to_be_seen1 = odf_create_list()
        how_not_to_be_seen2 = odf_create_list()
        how_not_to_be_seen3 = odf_create_list()
        # Fill the lists
        # First list
        how_not_to_be_seen1.append_item(spam)
        # Second list
        how_not_to_be_seen2.append_item(ham)
        how_not_to_be_seen2.append_item(eggs)
        how_not_to_be_seen2.append_item(foo)
        # Third list
        how_not_to_be_seen3.append_item(bar)
        how_not_to_be_seen3.append_item(baz)
        # Create the final nested list (how_not_to_be_seen1)
        spam.append_element(how_not_to_be_seen2)
        foo.append_element(how_not_to_be_seen3)

        # Initialize an empty fake context
        context = {"document": None, "footnotes": [], "endnotes": [], "annotations": [], "rst_mode": False}
        expected = (
            u"- In this picture, there are 47 people;\n"
            u"  none of them can be seen.\n"
            u"  - In this film, we hope to show you the\n"
            u"    value of not being seen.\n"
            u"  - Here is Mr. Bagthorpe of London, SE14.\n"
            u"  - He cannot be seen.\n"
            u"    - Now I am going to ask him to stand up.\n"
            u"    - Mr. Bagthorpe, will you stand up please?\n"
        )
        self.assertEqual(how_not_to_be_seen1.get_formatted_text(context), expected)
예제 #18
0
 def test_get_formatted_text(self):
     document = self.document
     body = self.body
     paragraph = body.get_element('//text:p')
     list_with_note = odf_create_list()
     list_with_note.append_item(paragraph)
     body.append(list_with_note)
     expected = (u"- Un paragraphe[1] d'apparence(i) banale[*].\n"
                 u"----\n"
                 u"[1] C'est-à-dire l'élément « text:p ».\n"
                 u"\n"
                 u"----\n"
                 u"[*] Sauf qu'il est commenté !\n"
                 u"\n"
                 u"========\n"
                 u"(i) Les apparences sont trompeuses !\n")
     self.assertEqual(document.get_formatted_text(), expected)
예제 #19
0
 def test_get_formatted_text(self):
     document = self.document
     body = self.body
     paragraph = body.get_element('//text:p')
     list_with_note = odf_create_list()
     list_with_note.append_item(paragraph)
     body.append(list_with_note)
     expected = (u"- Un paragraphe[1] d'apparence(i) banale[*].\n"
                 u"----\n"
                 u"[1] C'est-à-dire l'élément « text:p ».\n"
                 u"\n"
                 u"----\n"
                 u"[*] Sauf qu'il est commenté !\n"
                 u"\n"
                 u"========\n"
                 u"(i) Les apparences sont trompeuses !\n")
     self.assertEqual(document.get_formatted_text(), expected)
예제 #20
0
    def test_insert_item(self):
        breakfast = odf_create_list()
        breakfast.insert_item(u'spam', 1)
        breakfast.insert_item(u'eggs', 2)
        item = odf_create_list_item(u'ham')
        breakfast.insert_item(item, -1)

        expected = ('<text:list>'
                      '<text:list-item>'
                        '<text:p>spam</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:p>ham</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:p>eggs</text:p>'
                      '</text:list-item>'
                    '</text:list>')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
예제 #21
0
    def test_append_item(self):
        breakfast = odf_create_list()
        breakfast.append_item('spam')
        breakfast.append_item('ham')
        item = odf_create_list_item('eggs')
        breakfast.append_item(item)

        expected = ('<text:list>'
                    '<text:list-item>'
                    '<text:p>spam</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>ham</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>eggs</text:p>'
                    '</text:list-item>'
                    '</text:list>')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
예제 #22
0
    def test_insert_after(self):
        breakfast = odf_create_list()
        breakfast.append_item(u'spam')
        ham = odf_create_list_item(u'ham')
        breakfast.append_item(ham)
        eggs = odf_create_list_item(u'eggs')
        breakfast.insert_item(eggs, after=ham)

        expected = ('<text:list>'
                      '<text:list-item>'
                        '<text:p>spam</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:p>ham</text:p>'
                      '</text:list-item>'
                      '<text:list-item>'
                        '<text:p>eggs</text:p>'
                      '</text:list-item>'
                    '</text:list>')
        # TODO use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
예제 #23
0
    def test_insert_before(self):
        breakfast = odf_create_list()
        breakfast.append_item(u'spam')
        eggs = odf_create_list_item(u'eggs')
        breakfast.append_item(eggs)
        ham = odf_create_list_item(u'ham')
        breakfast.insert_item(ham, before=eggs)

        expected = ('<text:list>'
                    '<text:list-item>'
                    '<text:p>spam</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>ham</text:p>'
                    '</text:list-item>'
                    '<text:list-item>'
                    '<text:p>eggs</text:p>'
                    '</text:list-item>'
                    '</text:list>')
        # TODO use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
예제 #24
0
    def test_append_item(self):
        breakfast = odf_create_list()
        breakfast.append_item(u"spam")
        breakfast.append_item(u"ham")
        item = odf_create_list_item(u"eggs")
        breakfast.append_item(item)

        expected = (
            "<text:list>"
            "<text:list-item>"
            "<text:p>spam</text:p>"
            "</text:list-item>"
            "<text:list-item>"
            "<text:p>ham</text:p>"
            "</text:list-item>"
            "<text:list-item>"
            "<text:p>eggs</text:p>"
            "</text:list-item>"
            "</text:list>"
        )
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(), expected)
예제 #25
0
# -*- coding: UTF-8 -*-
from lpod.document import odf_new_document

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

# Lists are a dedicated object
from lpod.list import odf_create_list
my_list = odf_create_list([u'chocolat', u'café'])

# The list factory accepts a Python list of unicode strings and list items.
#
# The list can be written even though we will modify it afterwards:

body.append(my_list)
예제 #26
0
    def test_nested_list(self):
        breakfast = odf_create_list()
        spam = odf_create_list_item(u'spam')
        ham = odf_create_list_item(u'ham')
        eggs = odf_create_list_item(u'eggs')
        # First way: a list in an item, right next to a paragraph
        spam.append(odf_create_list([u'thé', u'café', u'chocolat']))
        breakfast.append_item(spam)
        breakfast.append_item(ham)
        breakfast.append_item(eggs)
        # Second way: a list as an item
        breakfast.append_item(breakfast.clone())

        expected = ('<text:list>\n'
                    '  <text:list-item>\n'
                    '    <text:p>spam</text:p>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>th&#233;</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>caf&#233;</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>chocolat</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>ham</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>eggs</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>spam</text:p>\n'
                    '        <text:list>\n'
                    '          <text:list-item>\n'
                    '            <text:p>th&#233;</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>caf&#233;</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>chocolat</text:p>\n'
                    '          </text:list-item>\n'
                    '        </text:list>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>ham</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>eggs</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '</text:list>\n')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(pretty=True), expected)
예제 #27
0
# Start a new page
page2 = odf_create_draw_page(u"page2")
body.append(page2)

# Embed an image from a file name
local_uri = document.add_file(u'images/zoé.jpg')

# Add image frame
image_frame = odf_create_image_frame(local_uri,
                                     size=('60mm', '45mm'),
                                     position=('4.5cm', '7cm'))
page2.append(image_frame)

# Some text side by side
list = odf_create_list([u"Item 1", u"Item 2", u"Item 3"])
text_frame = odf_create_text_frame(list,
                                   size=('7cm', '2.5cm'),
                                   position=('12.5cm', '7cm'),
                                   style=u"colored")
page2.append(text_frame)

# Add a transition for this frame
page2.set_transition("fade", "fadeOverColor")

#
# Shapes
#

# Last page
page3 = odf_create_draw_page(u"page3")
예제 #28
0
 title_frame = get_title_frame(first_master_page)
 name = unicode(filename.split('/')[-1])
 source = u"filesystem" if not scheme else scheme
 title_frame.set_text_content(u"%s (%s)" % (name, source))
 page.append(title_frame)
 # Get info
 info = []
 input_meta = input_document.get_part(ODF_META)
 info.append(u"Title: %s" % input_meta.get_title())
 stats = input_meta.get_statistic()
 info.append(u"# pages: %s" % stats['meta:page-count'])
 input_body = input_document.get_body()
 info.append(u"# images: %s" % len(input_body.get_images()))
 info.append(u"# tables: %s" % len(input_body.get_tables()))
 # Outline Frame
 info_list = odf_create_list(info)
 outline_frame = get_outline_frame(first_master_page)
 outline_frame.set_text_content(info_list)
 page.append(outline_frame)
 # Graphic Frame
 first_image = input_body.get_image(1)
 if not first_image:
     first_image = input_body.get_image(0)
 sibling = (first_image is not None
         and first_image.get_prev_sibling() or None)
 if sibling is not None and sibling.get_tag() == 'draw:object-ole':
     # TODO in lpOD
     first_image = None
 if first_image is None:
     printwarn('no image found in "%s"' % filename, indent=2)
     continue
# Uncommented parts are explained in : create_a_basic_document_with_a_list.py

# Imports from lpod
from lpod.document import odf_get_document, odf_new_document
# Import the list module
from lpod.list import odf_create_list
# Import the list item factory module
from lpod.list import odf_create_list_item

# Create the document
my_document = odf_new_document('text')
body = my_document.get_body()

# Adding List
my_list = odf_create_list([u'Arthur', u'Ford', u'Trillian'])
item = odf_create_list_item(u'Marvin')
my_list.append_item(item)
body.append(my_list)

# Adding Sublist¶
# A sublist is simply a list as an item of another list:
item.append(odf_create_list([u'Paranoid Android', u'older than the universe']))

# See the result:
print my_document.get_formatted_text()
# - Arthur
# - Ford
# - Trillian
# - Marvin
#   - Paranoid Android
# -*- coding: UTF-8 -*-
from lpod.document import odf_new_document
from lpod.list import odf_create_list

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

my_list = odf_create_list([u'chocolat', u'café'])
body.append(my_list)

from lpod.list import odf_create_list_item

item = odf_create_list_item(u"thé")
my_list.append(item)

#A sublist is simply a list as an item of another list

item.append(odf_create_list([u"thé vert", u"thé rouge"]))

print body.serialize(True)
예제 #31
0
    def test_nested_list(self):
        breakfast = odf_create_list()
        spam = odf_create_list_item('spam')
        ham = odf_create_list_item('ham')
        eggs = odf_create_list_item('eggs')
        # First way: a list in an item, right next to a paragraph
        spam.append(odf_create_list(['thé', 'café', 'chocolat']))
        breakfast.append_item(spam)
        breakfast.append_item(ham)
        breakfast.append_item(eggs)
        # Second way: a list as an item
        breakfast.append_item(breakfast.clone())

        expected = ('<text:list>\n'
                    '  <text:list-item>\n'
                    '    <text:p>spam</text:p>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>th&#233;</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>caf&#233;</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>chocolat</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>ham</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:p>eggs</text:p>\n'
                    '  </text:list-item>\n'
                    '  <text:list-item>\n'
                    '    <text:list>\n'
                    '      <text:list-item>\n'
                    '        <text:p>spam</text:p>\n'
                    '        <text:list>\n'
                    '          <text:list-item>\n'
                    '            <text:p>th&#233;</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>caf&#233;</text:p>\n'
                    '          </text:list-item>\n'
                    '          <text:list-item>\n'
                    '            <text:p>chocolat</text:p>\n'
                    '          </text:list-item>\n'
                    '        </text:list>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>ham</text:p>\n'
                    '      </text:list-item>\n'
                    '      <text:list-item>\n'
                    '        <text:p>eggs</text:p>\n'
                    '      </text:list-item>\n'
                    '    </text:list>\n'
                    '  </text:list-item>\n'
                    '</text:list>\n')
        # TODO Use the true list element in the body of the document instead of
        # the element just created.
        self.assertEqual(breakfast.serialize(pretty=True), expected)
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 €" % (
                                            product.name, product.price))
        product_list.append(item)

    title12 = odf_create_heading(2, u"Your command")
    body.append(title12)

    command = {0 : 1, 1 : 12, 2 : 3, 4 : 5 }

    # A table in the text document :
    table = odf_create_table(u"Table")
    body.append(table)
    row = odf_create_row()
예제 #33
0
#

# Start a new page
page2 = odf_create_draw_page(u"page2")
body.append(page2)

# Embed an image from a file name
local_uri = document.add_file(u'images/zoé.jpg')

# Add image frame
image_frame = odf_create_image_frame(local_uri, size=('60mm', '45mm'),
                                     position=('4.5cm', '7cm'))
page2.append(image_frame)

# Some text side by side
list = odf_create_list([u"Item 1", u"Item 2", u"Item 3"])
text_frame = odf_create_text_frame(list, size=('7cm', '2.5cm'),
                                   position=('12.5cm', '7cm'),
                                   style=u"colored")
page2.append(text_frame)

# Add a transition for this frame
page2.set_transition("fade", "fadeOverColor")

#
# Shapes
#

# Last page
page3 = odf_create_draw_page(u"page3")
body.append(page3)
예제 #34
0
# Add (empty) Table of content
toc = odf_create_toc()
body.append(toc)

# Add Paragraph
paragraph = odf_create_paragraph(u'lpOD generated Document')
body.append(paragraph)

# Add Heading
heading = odf_create_heading(1, text=u'Lists')
body.append(heading)

#
# A list
#
my_list = odf_create_list([u'chocolat', u'café'])

item = odf_create_list_item(u'Du thé')
item.append(odf_create_list([u'thé vert', u'thé rouge']))
my_list.append_item(item)

# insert item by position
my_list.insert_item(u'Chicorée', position=1)

# insert item by relative position
the = my_list.get_item(content=u'thé')
my_list.insert_item(u'Chicorée', before=the)
my_list.insert_item(u'Chicorée', after=the)

body.append(my_list)
예제 #35
0
# Uncommented parts are explained in : create_a_basic_text_document.py

# Imports from lpod
from lpod.document import odf_new_document
# Import the list module
from lpod.list import odf_create_list
# Import the list item factory module
from lpod.list import odf_create_list_item

# Create the document
my_document = odf_new_document('text')
body = my_document.get_body()

# Adding List
my_list = odf_create_list([u'Arthur', u'Ford', u'Trillian'])
# The list factory accepts a Python list of unicode strings and list items.

# The list can be written even though we will modify it afterwards:
body.append(my_list)

# Adding more List Item to the list, using the factory
item = odf_create_list_item(u'Marvin')
my_list.append_item(item)


if not os.path.exists('test_output'):
    os.mkdir('test_output')

output = os.path.join('test_output', 'my_document_with_list.odt')
예제 #36
0
 title_frame = get_title_frame(first_master_page)
 name = unicode(filename.split('/')[-1])
 source = u"filesystem" if not scheme else scheme
 title_frame.set_text_content(u"%s (%s)" % (name, source))
 page.append(title_frame)
 # Get info
 info = []
 input_meta = input_document.get_part(ODF_META)
 info.append(u"Title: %s" % input_meta.get_title())
 stats = input_meta.get_statistic()
 info.append(u"# pages: %s" % stats['meta:page-count'])
 input_body = input_document.get_body()
 info.append(u"# images: %s" % len(input_body.get_images()))
 info.append(u"# tables: %s" % len(input_body.get_tables()))
 # Outline Frame
 info_list = odf_create_list(info)
 outline_frame = get_outline_frame(first_master_page)
 outline_frame.set_text_content(info_list)
 page.append(outline_frame)
 # Graphic Frame
 first_image = input_body.get_image(1)
 if not first_image:
     first_image = input_body.get_image(0)
 sibling = (first_image is not None and first_image.get_prev_sibling()
            or None)
 if sibling is not None and sibling.get_tag() == 'draw:object-ole':
     # TODO in lpOD
     first_image = None
 if first_image is None:
     printwarn('no image found in "%s"' % filename, indent=2)
     continue
# Uncommented parts are explained in : create_a_basic_document_with_a_list.py

# Imports from lpod
from lpod.document import odf_get_document, odf_new_document
# Import the list module
from lpod.list import odf_create_list
# Import the list item factory module
from lpod.list import odf_create_list_item

# Create the document
my_document = odf_new_document('text')
body = my_document.get_body()

# Adding List
my_list = odf_create_list([u'Arthur', u'Ford', u'Trillian'])
item = odf_create_list_item(u'Marvin')
my_list.append_item(item)
body.append(my_list)

# Adding Sublist¶
# A sublist is simply a list as an item of another list:
item.append(odf_create_list([u'Paranoid Android',u'older than the universe']))

# See the result:
print my_document.get_formatted_text()
# - Arthur
# - Ford
# - Trillian
# - Marvin
#   - Paranoid Android