Example #1
0
 def test_new_placeholder_sp_generates_correct_xml(self):
     """CT_Shape._new_placeholder_sp() returns correct XML"""
     # setup ------------------------
     expected_xml_tmpl = (
         '<p:sp %s>\n  <p:nvSpPr>\n    <p:cNvPr id="%s" name="%s"/>\n    <'
         'p:cNvSpPr>\n      <a:spLocks noGrp="1"/>\n    </p:cNvSpPr>\n    '
         "<p:nvPr>\n      <p:ph%s/>\n    </p:nvPr>\n  </p:nvSpPr>\n  <p:sp"
         "Pr/>\n%s</p:sp>\n" % (nsdecls("a", "p"), "%d", "%s", "%s", "%s")
     )
     txBody_snippet = "  <p:txBody>\n    <a:bodyPr/>\n    <a:lstStyle/>\n    <a:p/>\n  " "</p:txBody>\n"
     test_cases = (
         (2, "Title 1", PH_TYPE_CTRTITLE, PH_ORIENT_HORZ, PH_SZ_FULL, 0),
         (3, "Date Placeholder 2", PH_TYPE_DT, PH_ORIENT_HORZ, PH_SZ_HALF, 10),
         (4, "Vertical Subtitle 3", PH_TYPE_SUBTITLE, PH_ORIENT_VERT, PH_SZ_FULL, 1),
         (5, "Table Placeholder 4", PH_TYPE_TBL, PH_ORIENT_HORZ, PH_SZ_QUARTER, 14),
         (6, "Slide Number Placeholder 5", PH_TYPE_SLDNUM, PH_ORIENT_HORZ, PH_SZ_QUARTER, 12),
         (7, "Footer Placeholder 6", PH_TYPE_FTR, PH_ORIENT_HORZ, PH_SZ_QUARTER, 11),
         (8, "Content Placeholder 7", PH_TYPE_OBJ, PH_ORIENT_HORZ, PH_SZ_FULL, 15),
     )
     expected_values = (
         (2, "Title 1", ' type="%s"' % PH_TYPE_CTRTITLE, txBody_snippet),
         (3, "Date Placeholder 2", ' type="%s" sz="half" idx="10"' % PH_TYPE_DT, ""),
         (4, "Vertical Subtitle 3", ' type="%s" orient="vert" idx="1"' % PH_TYPE_SUBTITLE, txBody_snippet),
         (5, "Table Placeholder 4", ' type="%s" sz="quarter" idx="14"' % PH_TYPE_TBL, ""),
         (6, "Slide Number Placeholder 5", ' type="%s" sz="quarter" ' 'idx="12"' % PH_TYPE_SLDNUM, ""),
         (7, "Footer Placeholder 6", ' type="%s" sz="quarter" idx="11"' % PH_TYPE_FTR, ""),
         (8, "Content Placeholder 7", ' idx="15"', txBody_snippet),
     )
     # exercise ---------------------
     for case_idx, argv in enumerate(test_cases):
         id_, name, ph_type, orient, sz, idx = argv
         sp = CT_Shape.new_placeholder_sp(id_, name, ph_type, orient, sz, idx)
         # verify ------------------
         expected_xml = expected_xml_tmpl % expected_values[case_idx]
         self.assertEqualLineByLine(expected_xml, sp)
Example #2
0
 def test_new_autoshape_sp_generates_correct_xml(self):
     """CT_Shape._new_autoshape_sp() returns correct XML"""
     # setup ------------------------
     id_ = 9
     name = "Rounded Rectangle 8"
     prst = "roundRect"
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:sp %s>\n  <p:nvSpPr>\n    <p:cNvPr id="%d" name="%s"/>\n    <'
         "p:cNvSpPr/>\n    <p:nvPr/>\n  </p:nvSpPr>\n  <p:spPr>\n    <a:xf"
         'rm>\n      <a:off x="%d" y="%d"/>\n      <a:ext cx="%d" cy="%d"/'
         '>\n    </a:xfrm>\n    <a:prstGeom prst="%s">\n      <a:avLst/>\n'
         '    </a:prstGeom>\n  </p:spPr>\n  <p:style>\n    <a:lnRef idx="1'
         '">\n      <a:schemeClr val="accent1"/>\n    </a:lnRef>\n    <a:f'
         'illRef idx="3">\n      <a:schemeClr val="accent1"/>\n    </a:fil'
         'lRef>\n    <a:effectRef idx="2">\n      <a:schemeClr val="accent'
         '1"/>\n    </a:effectRef>\n    <a:fontRef idx="minor">\n      <a:'
         'schemeClr val="lt1"/>\n    </a:fontRef>\n  </p:style>\n  <p:txBo'
         'dy>\n    <a:bodyPr rtlCol="0" anchor="ctr"/>\n    <a:lstStyle/>'
         '\n    <a:p>\n      <a:pPr algn="ctr"/>\n    </a:p>\n  </p:txBody'
         ">\n</p:sp>\n" % (nsdecls("a", "p"), id_, name, left, top, width, height, prst)
     )
     # exercise ---------------------
     sp = CT_Shape.new_autoshape_sp(id_, name, prst, left, top, width, height)
     # verify -----------------------
     self.assertEqualLineByLine(xml, sp)
Example #3
0
 def test_new_placeholder_sp_generates_correct_xml(self):
     """CT_Shape._new_placeholder_sp() returns correct XML"""
     # setup -----------------------
     expected_xml_tmpl = (
         '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n<'
         'p:sp xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/m'
         'ain" xmlns:p="http://schemas.openxmlformats.org/presentationml/2'
         '006/main">\n  <p:nvSpPr>\n    <p:cNvPr id="%d" name="%s"/>\n    '
         '<p:cNvSpPr>\n      <a:spLocks noGrp="1"/>\n    </p:cNvSpPr>\n   '
         ' <p:nvPr>\n      <p:ph%s/>\n    </p:nvPr>\n  </p:nvSpPr>\n  <p:s'
         'pPr/>\n%s</p:sp>\n')
     txBody_snippet = (
         '  <p:txBody>\n    <a:bodyPr/>\n    <a:lstStyle/>\n    <a:p/>\n  '
         '</p:txBody>\n')
     test_cases = (
         (2, 'Title 1', PH_TYPE_CTRTITLE, PH_ORIENT_HORZ, PH_SZ_FULL,
          0),
         (3, 'Date Placeholder 2', PH_TYPE_DT, PH_ORIENT_HORZ, PH_SZ_HALF,
          10),
         (4, 'Vertical Subtitle 3', PH_TYPE_SUBTITLE, PH_ORIENT_VERT,
          PH_SZ_FULL, 1),
         (5, 'Table Placeholder 4', PH_TYPE_TBL, PH_ORIENT_HORZ,
          PH_SZ_QUARTER, 14),
         (6, 'Slide Number Placeholder 5', PH_TYPE_SLDNUM, PH_ORIENT_HORZ,
          PH_SZ_QUARTER, 12),
         (7, 'Footer Placeholder 6', PH_TYPE_FTR, PH_ORIENT_HORZ,
          PH_SZ_QUARTER, 11),
         (8, 'Content Placeholder 7', PH_TYPE_OBJ, PH_ORIENT_HORZ,
          PH_SZ_FULL, 15)
     )
     expected_values = (
         (2, 'Title 1', ' type="%s"' % PH_TYPE_CTRTITLE, txBody_snippet),
         (3, 'Date Placeholder 2', ' type="%s" sz="half" idx="10"' %
          PH_TYPE_DT, ''),
         (4, 'Vertical Subtitle 3', ' type="%s" orient="vert" idx="1"' %
          PH_TYPE_SUBTITLE, txBody_snippet),
         (5, 'Table Placeholder 4', ' type="%s" sz="quarter" idx="14"' %
          PH_TYPE_TBL, ''),
         (6, 'Slide Number Placeholder 5', ' type="%s" sz="quarter" '
          'idx="12"' % PH_TYPE_SLDNUM, ''),
         (7, 'Footer Placeholder 6', ' type="%s" sz="quarter" idx="11"' %
          PH_TYPE_FTR, ''),
         (8, 'Content Placeholder 7', ' idx="15"', txBody_snippet)
     )
     # exercise --------------------
     for case_idx, argv in enumerate(test_cases):
         id_, name, ph_type, orient, sz, idx = argv
         sp = CT_Shape.new_placeholder_sp(id_, name, ph_type, orient, sz,
                                          idx)
         # verify ------------------
         expected_xml = expected_xml_tmpl % expected_values[case_idx]
         _assert_equal_line_by_line(self, expected_xml, sp)
Example #4
0
    def add_textbox(self, left, top, width, height):
        """
        Add text box shape of specified size at specified position.
        """
        id_ = self.__next_shape_id
        name = "TextBox %d" % (id_ - 1)

        sp = CT_Shape.new_textbox_sp(id_, name, left, top, width, height)
        shape = _Shape(sp)

        self.__spTree.append(sp)
        self.__shapes.append(shape)
        return shape
Example #5
0
    def add_textbox(self, left, top, width, height):
        """
        Add text box shape of specified size at specified position.
        """
        id_ = self.__next_shape_id
        name = 'TextBox %d' % (id_ - 1)

        sp = CT_Shape.new_textbox_sp(id_, name, left, top, width, height)
        shape = _Shape(sp)

        self.__spTree.append(sp)
        self.__shapes.append(shape)
        return shape
Example #6
0
    def add_shape(self, autoshape_type_id, left, top, width, height):
        """
        Add auto shape of type specified by *autoshape_type_id* (like
        ``MSO.SHAPE_RECTANGLE``) and of specified size at specified position.
        """
        autoshape_type = _AutoShapeType(autoshape_type_id)
        id_ = self.__next_shape_id
        name = "%s %d" % (autoshape_type.basename, id_ - 1)

        sp = CT_Shape.new_autoshape_sp(id_, name, autoshape_type.prst, left, top, width, height)
        shape = _Shape(sp)

        self.__spTree.append(sp)
        self.__shapes.append(shape)
        return shape
Example #7
0
    def add_shape(self, autoshape_type_id, left, top, width, height):
        """
        Add auto shape of type specified by *autoshape_type_id* (like
        ``MSO.SHAPE_RECTANGLE``) and of specified size at specified position.
        """
        autoshape_type = _AutoShapeType(autoshape_type_id)
        id_ = self.__next_shape_id
        name = '%s %d' % (autoshape_type.basename, id_ - 1)

        sp = CT_Shape.new_autoshape_sp(id_, name, autoshape_type.prst, left,
                                       top, width, height)
        shape = _Shape(sp)

        self.__spTree.append(sp)
        self.__shapes.append(shape)
        return shape
Example #8
0
    def __clone_layout_placeholder(self, layout_ph):
        """
        Add a new placeholder shape based on the slide layout placeholder
        *layout_ph*.
        """
        id_ = self.__next_shape_id
        ph_type = layout_ph.type
        orient = layout_ph.orient
        shapename = self.__next_ph_name(ph_type, id_, orient)
        sz = layout_ph.sz
        idx = layout_ph.idx

        sp = CT_Shape.new_placeholder_sp(id_, shapename, ph_type, orient, sz, idx)
        shape = _Shape(sp)

        self.__spTree.append(sp)
        self.__shapes.append(shape)
        return shape
Example #9
0
    def __clone_layout_placeholder(self, layout_ph):
        """
        Add a new placeholder shape based on the slide layout placeholder
        *layout_ph*.
        """
        id_ = self.__next_shape_id
        ph_type = layout_ph.type
        orient = layout_ph.orient
        shapename = self.__next_ph_name(ph_type, id_, orient)
        sz = layout_ph.sz
        idx = layout_ph.idx

        sp = CT_Shape.new_placeholder_sp(id_, shapename, ph_type, orient, sz,
                                         idx)
        shape = _Shape(sp)

        self.__spTree.append(sp)
        self.__shapes.append(shape)
        return shape
Example #10
0
 def test_new_textbox_sp_generates_correct_xml(self):
     """CT_Shape.new_textbox_sp() returns correct XML"""
     # setup ------------------------
     id_ = 9
     name = "TextBox 8"
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:sp %s>\n  <p:nvSpPr>\n    <p:cNvPr id="%d" name="%s"/>\n    <'
         'p:cNvSpPr txBox="1"/>\n    <p:nvPr/>\n  </p:nvSpPr>\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    <a:noFill/>\n  </p:spPr>\n  "
         '<p:txBody>\n    <a:bodyPr wrap="none">\n      <a:spAutoFit/>\n  '
         "  </a:bodyPr>\n    <a:lstStyle/>\n    <a:p/>\n  </p:txBody>\n</p"
         ":sp>\n" % (nsdecls("a", "p"), id_, name, left, top, width, height)
     )
     # exercise ---------------------
     sp = CT_Shape.new_textbox_sp(id_, name, left, top, width, height)
     # verify -----------------------
     self.assertEqualLineByLine(xml, sp)
Example #11
0
 def test_new_textbox_sp_generates_correct_xml(self):
     """CT_Shape._new_textbox_sp() returns correct XML"""
     # setup -----------------------
     id = 9
     name = 'TextBox 8'
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n<'
         'p:sp xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/m'
         'ain" xmlns:p="http://schemas.openxmlformats.org/presentationml/2'
         '006/main">\n  <p:nvSpPr>\n    <p:cNvPr id="%d" name="%s"/>\n    '
         '<p:cNvSpPr txBox="1"/>\n    <p:nvPr/>\n  </p:nvSpPr>\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    <a:noFill/>\n  </p:spPr>\n  '
         '<p:txBody>\n    <a:bodyPr wrap="none">\n      <a:spAutoFit/>\n  '
         '  </a:bodyPr>\n    <a:lstStyle/>\n    <a:p/>\n  </p:txBody>\n</p'
         ':sp>\n' % (id, name, left, top, width, height)
     )
     # exercise --------------------
     sp = CT_Shape.new_textbox_sp(id, name, left, top, width, height)
     # verify ----------------------
     _assert_equal_line_by_line(self, xml, sp)