Пример #1
0
    def set_bookmark(self, name, before=None, after=None, position=0,
                     role=None, content=None, limits=None):
        """Insert a bookmark before or after the characters in the text which
        match the regexp before/after. When the regexp matches more of one part
        of the text, position can be set to choice which part must be used. If
        before and after are None, we use only position that is the number of
        characters. So, by default, this function inserts a bookmark before the
        first character of the content. Role can be None, "start" or "end", we
        insert respectively a position bookmark a bookmark-start or a
        bookmark-end. If content is not None these 2 calls are equivalent::

          paragraph.set_bookmark("bookmark", content="xyz")

        ::

          paragraph.set_bookmark("bookmark", before="xyz", role="start")
          paragraph.set_bookmark("bookmark", after="xyz", role="end")

        If limits is not None these 2 calls are equivalent::

          paragraph.set_bookmark("bookmark", limits=(10, 20))

        ::

          paragraph.set_bookmark("bookmark", position=10, role="start")
          paragraph.set_bookmark("bookmark", position=20, role="end")

        Arguments:

            name -- string

            before -- regexp (unicode)

            after -- regexp (unicode)

            position -- int

            role -- None, "start" or "end"

            content -- regexp (unicode)

            limits -- (int, int)
        """

        # With "content" => automatically insert a "start" and an "end"
        # bookmark
        if (before is None and
            after is None and
            role is None and
            content is not None and
            limits is None):

            # Start
            start = odf_create_bookmark_start(name)
            self._insert(start, before=content, position=position)

            # End
            end = odf_create_bookmark_end(name)
            self._insert(end, after=content, position=position)

            return start, end

        # With "limits" =>  automatically insert a "start" and an "end"
        # bookmark
        if (before is None and
            after is None and
            role is None and
            content is None and
            position == 0 and
            limits is not None):

            # Start
            start = odf_create_bookmark_start(name)
            self._insert(start, position=limits[0])

            # End
            end = odf_create_bookmark_end(name)
            self._insert(end, position=limits[1])

            return start, end

        # Without "content" and "limits"
        if content is not None or limits is not None:
            raise ValueError, "bad arguments"

        # Role
        if role is None:
            bookmark = odf_create_bookmark(name)
        elif role == "start":
            bookmark = odf_create_bookmark_start(name)
        elif role == "end":
            bookmark = odf_create_bookmark_end(name)
        else:
            raise ValueError, "bad arguments"

        # Insert
        self._insert(bookmark, before=before, after=after, position=position)

        return bookmark
Пример #2
0
    def set_bookmark(self,
                     name,
                     before=None,
                     after=None,
                     position=0,
                     role=None,
                     content=None):
        """Insert a bookmark before or after the characters in the text which
        match the regex before/after. When the regex matches more of one part
        of the text, position can be set to choose which part must be used.
        If before and after are None, we use only position that is the number
        of characters. So, by default, this function inserts a bookmark
        before the first character of the content. Role can be None, "start"
        or "end", we insert respectively a position bookmark a bookmark-start
        or a bookmark-end. If content is not None these 2 calls are
        equivalent::

          paragraph.set_bookmark("bookmark", content="xyz")

        and::

          paragraph.set_bookmark("bookmark", before="xyz", role="start")
          paragraph.set_bookmark("bookmark", after="xyz", role="end")

        If position is a 2-tuple, these 2 calls are equivalent::

          paragraph.set_bookmark("bookmark", position=(10, 20))

        and::

          paragraph.set_bookmark("bookmark", position=10, role="start")
          paragraph.set_bookmark("bookmark", position=20, role="end")

        Arguments:

            name -- str

            before -- unicode regex

            after -- unicode regex

            position -- int or (int, int)

            role -- None, "start" or "end"

            content -- unicode regex
        """
        # With "content" => automatically insert a "start" and an "end"
        # bookmark
        if (before is None and after is None and role is None
                and content is not None and type(position) is int):
            # Start
            start = odf_create_bookmark_start(name)
            self._insert(start, before=content, position=position)
            # End
            end = odf_create_bookmark_end(name)
            self._insert(end, after=content, position=position)
            return start, end

        # With "(int, int)" =>  automatically insert a "start" and an "end"
        # bookmark
        if (before is None and after is None and role is None
                and content is None and type(position) is tuple):
            # Start
            start = odf_create_bookmark_start(name)
            self._insert(start, position=position[0])
            # End
            end = odf_create_bookmark_end(name)
            self._insert(end, position=position[1])
            return start, end

        # Without "content" nor "position"
        if content is not None or type(position) is not int:
            raise ValueError, "bad arguments"

        # Role
        if role is None:
            bookmark = odf_create_bookmark(name)
        elif role == "start":
            bookmark = odf_create_bookmark_start(name)
        elif role == "end":
            bookmark = odf_create_bookmark_end(name)
        else:
            raise ValueError, "bad arguments"

        # Insert
        self._insert(bookmark, before=before, after=after, position=position)

        return bookmark
Пример #3
0
    def set_bookmark(self, name, before=None, after=None, position=0,
                     role=None, content=None):
        """Insert a bookmark before or after the characters in the text which
        match the regex before/after. When the regex matches more of one part
        of the text, position can be set to choose which part must be used.
        If before and after are None, we use only position that is the number
        of characters. So, by default, this function inserts a bookmark
        before the first character of the content. Role can be None, "start"
        or "end", we insert respectively a position bookmark a bookmark-start
        or a bookmark-end. If content is not None these 2 calls are
        equivalent::

          paragraph.set_bookmark("bookmark", content="xyz")

        and::

          paragraph.set_bookmark("bookmark", before="xyz", role="start")
          paragraph.set_bookmark("bookmark", after="xyz", role="end")

        If position is a 2-tuple, these 2 calls are equivalent::

          paragraph.set_bookmark("bookmark", position=(10, 20))

        and::

          paragraph.set_bookmark("bookmark", position=10, role="start")
          paragraph.set_bookmark("bookmark", position=20, role="end")

        Arguments:

            name -- str

            before -- unicode regex

            after -- unicode regex

            position -- int or (int, int)

            role -- None, "start" or "end"

            content -- unicode regex
        """
        # With "content" => automatically insert a "start" and an "end"
        # bookmark
        if (before is None and after is None and role is None
                and content is not None and type(position) is int):
            # Start
            start = odf_create_bookmark_start(name)
            self._insert(start, before=content, position=position,
                         main_text=True)
            # End
            end = odf_create_bookmark_end(name)
            self._insert(end, after=content, position=position,
                         main_text=True)
            return start, end

        # With "(int, int)" =>  automatically insert a "start" and an "end"
        # bookmark
        if (before is None and after is None and role is None
                and content is None and type(position) is tuple):
            # Start
            start = odf_create_bookmark_start(name)
            self._insert(start, position=position[0], main_text=True)
            # End
            end = odf_create_bookmark_end(name)
            self._insert(end, position=position[1], main_text=True)
            return start, end

        # Without "content" nor "position"
        if content is not None or type(position) is not int:
            raise ValueError("bad arguments")

        # Role
        if role is None:
            bookmark = odf_create_bookmark(name)
        elif role == "start":
            bookmark = odf_create_bookmark_start(name)
        elif role == "end":
            bookmark = odf_create_bookmark_end(name)
        else:
            raise ValueError("bad arguments")

        # Insert
        self._insert(bookmark, before=before, after=after, position=position,
                     main_text=True)

        return bookmark