Пример #1
0
 def add_freeform_sp(self, x, y, cx, cy):
     """Append a new freeform `p:sp` with specified position and size."""
     shape_id = self._next_shape_id
     name = 'Freeform %d' % (shape_id - 1, )
     sp = CT_Shape.new_freeform_sp(shape_id, name, x, y, cx, cy)
     self.insert_element_before(sp, 'p:extLst')
     return sp
Пример #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)
Пример #3
0
 def add_freeform_sp(self, x, y, cx, cy):
     """Append a new freeform `p:sp` with specified position and size."""
     shape_id = self._next_shape_id
     name = "Freeform %d" % (shape_id - 1,)
     sp = CT_Shape.new_freeform_sp(shape_id, name, x, y, cx, cy)
     self.insert_element_before(sp, "p:extLst")
     return sp
Пример #4
0
 def it_knows_how_to_create_a_new_autoshape_sp(self):
     # 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 -----------------------
     assert sp.xml == xml
 def it_knows_how_to_create_a_new_autoshape_sp(self):
     # 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 -----------------------
     assert sp.xml == xml
Пример #6
0
 def add_placeholder(self, id_, name, ph_type, orient, sz, idx):
     """
     Append a newly-created placeholder ``<p:sp>`` shape having the
     specified placeholder properties.
     """
     sp = CT_Shape.new_placeholder_sp(id_, name, ph_type, orient, sz, idx)
     self.insert_element_before(sp, "p:extLst")
     return sp
Пример #7
0
 def add_autoshape(self, id_, name, prst, x, y, cx, cy):
     """
     Append a new ``<p:sp>`` shape to the group/shapetree having the
     properties specified in call.
     """
     sp = CT_Shape.new_autoshape_sp(id_, name, prst, x, y, cx, cy)
     self.insert_element_before(sp, 'p:extLst')
     return sp
Пример #8
0
 def add_textbox(self, id_, name, x, y, cx, cy):
     """
     Append a newly-created textbox ``<p:sp>`` shape having the specified
     position and size.
     """
     sp = CT_Shape.new_textbox_sp(id_, name, x, y, cx, cy)
     self.insert_element_before(sp, "p:extLst")
     return sp
Пример #9
0
 def add_textbox(self, id_, name, x, y, cx, cy):
     """
     Append a newly-created textbox ``<p:sp>`` shape having the specified
     position and size.
     """
     sp = CT_Shape.new_textbox_sp(id_, name, x, y, cx, cy)
     self.insert_element_before(sp, 'p:extLst')
     return sp
Пример #10
0
 def add_placeholder(self, id_, name, ph_type, orient, sz, idx):
     """
     Append a newly-created placeholder ``<p:sp>`` shape having the
     specified placeholder properties.
     """
     sp = CT_Shape.new_placeholder_sp(id_, name, ph_type, orient, sz, idx)
     self.insert_element_before(sp, 'p:extLst')
     return sp
Пример #11
0
 def add_autoshape(self, id_, name, prst, x, y, cx, cy):
     """
     Append a new ``<p:sp>`` shape to the group/shapetree having the
     properties specified in call.
     """
     sp = CT_Shape.new_autoshape_sp(id_, name, prst, x, y, cx, cy)
     self.insert_element_before(sp, "p:extLst")
     return sp
Пример #12
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', ST_PlaceholderType.CTR_TITLE,
                    ST_Direction.HORZ, ST_PlaceholderSize.FULL,
                    0), (3, 'Date Placeholder 2', ST_PlaceholderType.DT,
                         ST_Direction.HORZ, ST_PlaceholderSize.HALF, 10),
                   (4, 'Vertical Subtitle 3', ST_PlaceholderType.SUB_TITLE,
                    ST_Direction.VERT, ST_PlaceholderSize.FULL,
                    1), (5, 'Table Placeholder 4', ST_PlaceholderType.TBL,
                         ST_Direction.HORZ, ST_PlaceholderSize.QUARTER, 14),
                   (6, 'Slide Number Placeholder 5',
                    ST_PlaceholderType.SLD_NUM, ST_Direction.HORZ,
                    ST_PlaceholderSize.QUARTER, 12),
                   (7, 'Footer Placeholder 6', ST_PlaceholderType.FTR,
                    ST_Direction.HORZ, ST_PlaceholderSize.QUARTER, 11),
                   (8, 'Content Placeholder 7', ST_PlaceholderType.OBJ,
                    ST_Direction.HORZ, ST_PlaceholderSize.FULL, 15))
     expected_values = ((2, 'Title 1',
                         ' type="%s"' % ST_PlaceholderType.CTR_TITLE,
                         txBody_snippet), (3, 'Date Placeholder 2',
                                           ' type="%s" sz="half" idx="10"' %
                                           ST_PlaceholderType.DT, ''),
                        (4, 'Vertical Subtitle 3',
                         ' type="%s" orient="vert" idx="1"' %
                         ST_PlaceholderType.SUB_TITLE, txBody_snippet),
                        (5, 'Table Placeholder 4',
                         ' type="%s" sz="quarter" idx="14"' %
                         ST_PlaceholderType.TBL,
                         ''), (6, 'Slide Number Placeholder 5',
                               ' type="%s" sz="quarter" '
                               'idx="12"' % ST_PlaceholderType.SLD_NUM,
                               ''), (7, 'Footer Placeholder 6',
                                     ' type="%s" sz="quarter" idx="11"' %
                                     ST_PlaceholderType.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)
Пример #13
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', ST_PlaceholderType.CTR_TITLE, ST_Direction.HORZ,
          ST_PlaceholderSize.FULL, 0),
         (3, 'Date Placeholder 2', ST_PlaceholderType.DT,
          ST_Direction.HORZ, ST_PlaceholderSize.HALF, 10),
         (4, 'Vertical Subtitle 3', ST_PlaceholderType.SUB_TITLE,
          ST_Direction.VERT, ST_PlaceholderSize.FULL, 1),
         (5, 'Table Placeholder 4', ST_PlaceholderType.TBL,
          ST_Direction.HORZ, ST_PlaceholderSize.QUARTER, 14),
         (6, 'Slide Number Placeholder 5', ST_PlaceholderType.SLD_NUM,
          ST_Direction.HORZ, ST_PlaceholderSize.QUARTER, 12),
         (7, 'Footer Placeholder 6', ST_PlaceholderType.FTR,
          ST_Direction.HORZ, ST_PlaceholderSize.QUARTER, 11),
         (8, 'Content Placeholder 7', ST_PlaceholderType.OBJ,
          ST_Direction.HORZ, ST_PlaceholderSize.FULL, 15)
     )
     expected_values = (
         (2, 'Title 1', ' type="%s"' % ST_PlaceholderType.CTR_TITLE,
          txBody_snippet),
         (3, 'Date Placeholder 2', ' type="%s" sz="half" idx="10"' %
          ST_PlaceholderType.DT, ''),
         (4, 'Vertical Subtitle 3', ' type="%s" orient="vert" idx="1"' %
          ST_PlaceholderType.SUB_TITLE, txBody_snippet),
         (5, 'Table Placeholder 4', ' type="%s" sz="quarter" idx="14"' %
          ST_PlaceholderType.TBL, ''),
         (6, 'Slide Number Placeholder 5', ' type="%s" sz="quarter" '
          'idx="12"' % ST_PlaceholderType.SLD_NUM, ''),
         (7, 'Footer Placeholder 6', ' type="%s" sz="quarter" idx="11"' %
          ST_PlaceholderType.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)
 def it_knows_how_to_create_a_new_textbox_sp(self):
     # 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 -----------------------
     assert sp.xml == xml
Пример #15
0
 def it_knows_how_to_create_a_new_textbox_sp(self):
     # 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 -----------------------
     assert sp.xml == xml
Пример #16
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)
Пример #17
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)
 def it_knows_how_to_create_a_new_placeholder_sp(self, new_ph_sp_fixture):
     id_, name, ph_type, orient, sz, idx, expected_xml = new_ph_sp_fixture
     sp = CT_Shape.new_placeholder_sp(id_, name, ph_type, orient, sz, idx)
     assert sp.xml == expected_xml
Пример #19
0
 def it_knows_how_to_create_a_new_placeholder_sp(self, new_ph_sp_fixture):
     id_, name, ph_type, orient, sz, idx, expected_xml = new_ph_sp_fixture
     sp = CT_Shape.new_placeholder_sp(
         id_, name, ph_type, orient, sz, idx
     )
     assert sp.xml == expected_xml