Example #1
0
    def add_picture(self, file, left, top, width=None, height=None):
        """
        Add picture shape displaying image in *file*, where *file* can be
        either a path to a file (a string) or a file-like object.
        """
        image, rel = self.__slide._add_image(file)

        id = self.__next_shape_id
        name = 'Picture %d' % (id-1)
        desc = image._desc
        rId = rel._rId
        width, height = image._scale(width, height)

        pic = CT_Picture.new_pic(id, name, desc, rId, left, top, width, height)

        self.__spTree.append(pic)
        picture = _Picture(pic)
        self.__shapes.append(picture)
        return picture
Example #2
0
    def add_picture(self, file, left, top, width=None, height=None):
        """
        Add picture shape displaying image in *file*, where *file* can be
        either a path to a file (a string) or a file-like object.
        """
        image, rel = self.__slide._add_image(file)

        id = self.__next_shape_id
        name = 'Picture %d' % (id - 1)
        desc = image._desc
        rId = rel._rId
        width, height = image._scale(width, height)

        pic = CT_Picture.new_pic(id, name, desc, rId, left, top, width, height)

        self.__spTree.append(pic)
        picture = _Picture(pic)
        self.__shapes.append(picture)
        return picture
Example #3
0
 def test_new_pic_generates_correct_xml(self):
     """CT_Picture.new_pic() returns correct XML"""
     # setup ------------------------
     id_, name, desc, rId = 9, "Picture 8", "test-image.png", "rId7"
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:pic %s>\n  <p:nvPicPr>\n    <p:cNvPr id="%d" name="%s" descr='
         '"%s"/>\n    <p:cNvPicPr>\n      <a:picLocks noChangeAspect="1"/>'
         "\n    </p:cNvPicPr>\n    <p:nvPr/>\n  </p:nvPicPr>\n  <p:blipFil"
         'l>\n    <a:blip r:embed="%s"/>\n    <a:stretch>\n      <a:fillRe'
         "ct/>\n    </a:stretch>\n  </p:blipFill>\n  <p:spPr>\n    <a:xfrm"
         '>\n      <a:off x="%d" y="%d"/>\n      <a:ext cx="%d" cy="%d"/>'
         '\n    </a:xfrm>\n    <a:prstGeom prst="rect">\n      <a:avLst/>'
         "\n    </a:prstGeom>\n  </p:spPr>\n</p:pic>\n"
         % (nsdecls("a", "p", "r"), id_, name, desc, rId, left, top, width, height)
     )
     # exercise ---------------------
     pic = CT_Picture.new_pic(id_, name, desc, rId, left, top, width, height)
     # verify -----------------------
     self.assertEqualLineByLine(xml, pic)
Example #4
0
 def test_new_pic_generates_correct_xml(self):
     """CT_Picture.new_pic() returns correct XML"""
     # setup -----------------------
     id_, name, desc, rId = 9, 'Picture 8', 'test-image.png', 'rId7'
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n<'
         'p:pic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/'
         'main" xmlns:p="http://schemas.openxmlformats.org/presentationml/'
         '2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocu'
         'ment/2006/relationships">\n  <p:nvPicPr>\n    <p:cNvPr id="%d" n'
         'ame="%s" descr="%s"/>\n    <p:cNvPicPr>\n      <a:picLocks noCha'
         'ngeAspect="1"/>\n    </p:cNvPicPr>\n    <p:nvPr/>\n  </p:nvPicPr'
         '>\n  <p:blipFill>\n    <a:blip r:embed="%s"/>\n    <a:stretch>\n'
         '      <a:fillRect/>\n    </a:stretch>\n  </p:blipFill>\n  <p:spP'
         'r>\n    <a:xfrm>\n      <a:off x="%d" y="%d"/>\n      <a:ext cx='
         '"%d" cy="%d"/>\n    </a:xfrm>\n    <a:prstGeom prst="rect">\n   '
         '   <a:avLst/>\n    </a:prstGeom>\n  </p:spPr>\n</p:pic>\n' %
         (id_, name, desc, rId, left, top, width, height))
     # exercise --------------------
     pic = CT_Picture.new_pic(id_, name, desc, rId, left, top,
                              width, height)
     # verify ----------------------
     _assert_equal_line_by_line(self, xml, pic)