Exemplo n.º 1
0
 def prstGeom(self):
     if self.avLst:
         prstGeom = ('<a:prstGeom %s prst="%s">\n%s</a:prstGeom>\n' %
                     (nsdecls('a'), self._prst, self.avLst))
     else:
         prstGeom = ('<a:prstGeom %s prst="%s"/>\n' %
                     (nsdecls('a'), self._prst))
     return prstGeom
Exemplo n.º 2
0
 def coreProperties(self):
     if self.props_xml:
         coreProperties = (
             '<cp:coreProperties %s>\n%s</cp:coreProperties>\n' %
             (nsdecls(*self._ns_prefixes), self.props_xml)
         )
     else:
         coreProperties = (
             '<cp:coreProperties %s/>\n' % nsdecls('cp', 'dc', 'dcterms')
         )
     return coreProperties
Exemplo n.º 3
0
 def test_new_tbl_generates_correct_xml(self):
     """CT_Table._new_tbl() returns correct XML"""
     # setup ------------------------
     rows, cols = 2, 3
     width, height = 334, 445
     xml = (
         '<a:tbl %s>\n  <a:tblPr firstRow="1" bandRow="1">\n    <a:tableSt'
         "yleId>{5C22544A-7EE6-4342-B048-85BDC9FD1C3A}</a:tableStyleId>\n "
         ' </a:tblPr>\n  <a:tblGrid>\n    <a:gridCol w="111"/>\n    <a:gri'
         'dCol w="111"/>\n    <a:gridCol w="112"/>\n  </a:tblGrid>\n  <a:t'
         'r h="222">\n    <a:tc>\n      <a:txBody>\n        <a:bodyPr/>\n '
         "       <a:lstStyle/>\n        <a:p/>\n      </a:txBody>\n      <"
         "a:tcPr/>\n    </a:tc>\n    <a:tc>\n      <a:txBody>\n        <a:"
         "bodyPr/>\n        <a:lstStyle/>\n        <a:p/>\n      </a:txBod"
         "y>\n      <a:tcPr/>\n    </a:tc>\n    <a:tc>\n      <a:txBody>\n"
         "        <a:bodyPr/>\n        <a:lstStyle/>\n        <a:p/>\n    "
         "  </a:txBody>\n      <a:tcPr/>\n    </a:tc>\n  </a:tr>\n  <a:tr "
         'h="223">\n    <a:tc>\n      <a:txBody>\n        <a:bodyPr/>\n   '
         "     <a:lstStyle/>\n        <a:p/>\n      </a:txBody>\n      <a:"
         "tcPr/>\n    </a:tc>\n    <a:tc>\n      <a:txBody>\n        <a:bo"
         "dyPr/>\n        <a:lstStyle/>\n        <a:p/>\n      </a:txBody>"
         "\n      <a:tcPr/>\n    </a:tc>\n    <a:tc>\n      <a:txBody>\n  "
         "      <a:bodyPr/>\n        <a:lstStyle/>\n        <a:p/>\n      "
         "</a:txBody>\n      <a:tcPr/>\n    </a:tc>\n  </a:tr>\n</a:tbl>\n" % nsdecls("a")
     )
     # exercise ---------------------
     tbl = CT_Table.new_tbl(rows, cols, width, height)
     # verify -----------------------
     self.assertEqualLineByLine(xml, tbl)
Exemplo n.º 4
0
 def textbox(self):
     """Generic text box XML"""
     return (
         '<p:sp %s>\n'
         '  <p:nvSpPr>\n'
         '    <p:cNvPr id="9" name="TextBox 8"/>\n'
         '    <p:cNvSpPr txBox="1"/>\n'
         '    <p:nvPr/>\n'
         '  </p:nvSpPr>\n'
         '  <p:spPr>\n'
         '    <a:xfrm>\n'
         '      <a:off x="111" y="222"/>\n'
         '      <a:ext cx="333" cy="444"/>\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>' % nsdecls('a', 'p')
     )
Exemplo n.º 5
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)
Exemplo n.º 6
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)
Exemplo n.º 7
0
 def picture(self):
     """ XML for an pic shape, for unit testing purposes """
     return (
         '<p:pic %s>\n'
         '  <p:nvPicPr>\n'
         '    <p:cNvPr id="9" name="Picture 8" descr="image.png"/>\n'
         '    <p:cNvPicPr>\n'
         '      <a:picLocks noChangeAspect="1"/>\n'
         '    </p:cNvPicPr>\n'
         '    <p:nvPr/>\n'
         '  </p:nvPicPr>\n'
         '  <p:blipFill>\n'
         '    <a:blip r:embed="rId7"/>\n'
         '    <a:stretch>\n'
         '      <a:fillRect/>\n'
         '    </a:stretch>\n'
         '  </p:blipFill>\n'
         '  <p:spPr>\n'
         '    <a:xfrm>\n'
         '      <a:off x="111" y="222"/>\n'
         '      <a:ext cx="333" cy="444"/>\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')
     )
Exemplo n.º 8
0
 def centered_paragraph(self):
     """
     XML for centered paragraph
     """
     return (
         '<a:p %s>\n'
         '  <a:pPr algn="ctr"/>\n'
         '</a:p>\n' % nsdecls('a')
     )
Exemplo n.º 9
0
 def empty_spTree(self):
     return (
         '<p:spTree %s>\n'
         '  <p:nvGrpSpPr>\n'
         '    <p:cNvPr id="1" name=""/>\n'
         '    <p:cNvGrpSpPr/>\n'
         '    <p:nvPr/>\n'
         '  </p:nvGrpSpPr>\n'
         '  <p:grpSpPr/>\n'
         '</p:spTree>\n' % nsdecls('p', 'a')
     )
Exemplo n.º 10
0
 def cell(self):
     """
     XML for empty default table cell
     """
     return (
         '<a:tc %s>\n'
         '  <a:txBody>\n'
         '    <a:bodyPr/>\n'
         '    <a:lstStyle/>\n'
         '    <a:p/>\n'
         '  </a:txBody>\n'
         '</a:tc>\n' % nsdecls('a')
     )
Exemplo n.º 11
0
 def top_aligned_cell(self):
     """
     XML for empty top-aligned table cell
     """
     return (
         '<a:tc %s>\n'
         '  <a:txBody>\n'
         '    <a:bodyPr/>\n'
         '    <a:lstStyle/>\n'
         '    <a:p/>\n'
         '  </a:txBody>\n'
         '  <a:tcPr anchor="t"/>\n'
         '</a:tc>\n' % nsdecls('a')
     )
Exemplo n.º 12
0
 def cell_with_margins(self):
     """
     XML for cell having top, left, right, and bottom margin settings
     """
     return (
         '<a:tc %s>\n'
         '  <a:txBody>\n'
         '    <a:bodyPr/>\n'
         '    <a:lstStyle/>\n'
         '    <a:p/>\n'
         '  </a:txBody>\n'
         '  <a:tcPr marT="12" marR="34" marB="56" marL="78"/>\n'
         '</a:tc>\n' % nsdecls('a')
     )
Exemplo n.º 13
0
 def test_new_table_generates_correct_xml(self):
     """CT_GraphicalObjectFrame.new_table() returns correct XML"""
     # setup ------------------------
     id_, name = 9, "Table 8"
     rows, cols = 2, 3
     left, top, width, height = 111, 222, 334, 445
     xml = (
         "<p:graphicFrame %s>\n  <p:nvGraphicFramePr>\n    <p:cNvP"
         'r id="'
         '%d" name="%s"/>\n    <p:cNvGraphicFramePr>\n      <a:graphicFram'
         'eLocks noGrp="1"/>\n    </p:cNvGraphicFramePr>\n    <p:nvPr/>\n '
         ' </p:nvGraphicFramePr>\n  <p:xfrm>\n    <a:off x="%d" y="%d"/>\n'
         '    <a:ext cx="%d" cy="%d"/>\n  </p:xfrm>\n  <a:graphic>\n    <a'
         ':graphicData uri="http://schemas.openxmlformats.org/drawingml/20'
         '06/table">\n      <a:tbl>\n        <a:tblPr firstRow="1" bandRow'
         '="1">\n          <a:tableStyleId>{5C22544A-7EE6-4342-B048-85BDC9'
         "FD1C3A}</a:tableStyleId>\n        </a:tblPr>\n        <a:tblGrid"
         '>\n          <a:gridCol w="111"/>\n          <a:gridCol w="111"/'
         '>\n          <a:gridCol w="112"/>\n        </a:tblGrid>\n       '
         ' <a:tr h="222">\n          <a:tc>\n            <a:txBody>\n     '
         "         <a:bodyPr/>\n              <a:lstStyle/>\n             "
         " <a:p/>\n            </a:txBody>\n            <a:tcPr/>\n       "
         "   </a:tc>\n          <a:tc>\n            <a:txBody>\n          "
         "    <a:bodyPr/>\n              <a:lstStyle/>\n              <a:p"
         "/>\n            </a:txBody>\n            <a:tcPr/>\n          </"
         "a:tc>\n          <a:tc>\n            <a:txBody>\n              <"
         "a:bodyPr/>\n              <a:lstStyle/>\n              <a:p/>\n "
         "           </a:txBody>\n            <a:tcPr/>\n          </a:tc>"
         '\n        </a:tr>\n        <a:tr h="223">\n          <a:tc>\n   '
         "         <a:txBody>\n              <a:bodyPr/>\n              <a"
         ":lstStyle/>\n              <a:p/>\n            </a:txBody>\n    "
         "        <a:tcPr/>\n          </a:tc>\n          <a:tc>\n        "
         "    <a:txBody>\n              <a:bodyPr/>\n              <a:lstS"
         "tyle/>\n              <a:p/>\n            </a:txBody>\n         "
         "   <a:tcPr/>\n          </a:tc>\n          <a:tc>\n            <"
         "a:txBody>\n              <a:bodyPr/>\n              <a:lstStyle/"
         ">\n              <a:p/>\n            </a:txBody>\n            <a"
         ":tcPr/>\n          </a:tc>\n        </a:tr>\n      </a:tbl>\n   "
         " </a:graphicData>\n  </a:graphic>\n</p:graphicFrame>\n"
         % (nsdecls("a", "p"), id_, name, left, top, width, height)
     )
     # exercise ---------------------
     graphicFrame = CT_GraphicalObjectFrame.new_table(id_, name, rows, cols, left, top, width, height)
     # verify -----------------------
     self.assertEqualLineByLine(xml, graphicFrame)
Exemplo n.º 14
0
 def test_new_graphicFrame_generates_correct_xml(self):
     """CT_GraphicalObjectFrame.new_graphicFrame() returns correct XML"""
     # setup ------------------------
     id_, name = 9, "Table 8"
     left, top, width, height = 111, 222, 333, 444
     xml = (
         '<p:graphicFrame %s>\n  <p:nvGraphicFramePr>\n    <p:cNvPr id="%d'
         '" name="%s"/>\n    <p:cNvGraphicFramePr>\n      <a:graphicFrameL'
         'ocks noGrp="1"/>\n    </p:cNvGraphicFramePr>\n    <p:nvPr/>\n  <'
         '/p:nvGraphicFramePr>\n  <p:xfrm>\n    <a:off x="%d" y="%d"/>\n  '
         '  <a:ext cx="%d" cy="%d"/>\n  </p:xfrm>\n  <a:graphic>\n    <a:g'
         "raphicData/>\n  </a:graphic>\n</p:graphicFrame>\n"
         % (nsdecls("a", "p"), id_, name, left, top, width, height)
     )
     # exercise ---------------------
     graphicFrame = CT_GraphicalObjectFrame.new_graphicFrame(id_, name, left, top, width, height)
     # verify -----------------------
     self.assertEqualLineByLine(xml, graphicFrame)
Exemplo n.º 15
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)
Exemplo n.º 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)
Exemplo n.º 17
0
 def paragraph(self):
     """
     XML for a default, empty paragraph
     """
     return '<a:p %s/>\n' % nsdecls('a')
Exemplo n.º 18
0
 def xml(self):
     """
     Return XML string based on settings accumulated via method calls
     """
     return self._tmpl % (nsdecls('a'), self._tblPr_attrs_str)